[PATCH pve-storage v2 9/9] api: add /nodes//storage//identity route

Lukas Wagner
2026-04-24T08:31:06Z

This API allows us to retrieve the instance ID of PBS storages. This is
useful to establish a mapping between PBS storage and PBS remotes in
PDM.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
Changes since v2:
- Change the return value as proposed by Thomas (include a type
discrimininant and rename pbs-instance-id to id)
- retrieve the identifier through the PBS plugin

Changes since RFC v1:
- Change endpoint path from 'instance-id' to 'identity', as this is
more generic and could make more sense for other storages, if they
ever need such a thing
- Remove unused RpcEnv code
- Adapt PBSClient call to 'get_server_identity'

src/PVE/API2/Storage/Status.pm | 57 +++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm
index 8225c3a..fb921cb 100644
--- a/src/PVE/API2/Storage/Status.pm
+++ b/src/PVE/API2/Storage/Status.pm
@@ -14,7 +14,7 @@ use PVE::JSONSchema qw(get_standard_option);
use PVE::RESTHandler;
use PVE::RPCEnvironment;
use PVE::RRD;
-use PVE::Tools qw(run_command);
+use PVE::Tools qw(run_command extract_param);

use PVE::API2::Storage::Content;
use PVE::API2::Storage::FileRestore;
@@ -23,6 +23,8 @@ use PVE::Storage;

use base qw(PVE::RESTHandler);

+my $storage_type_enum = PVE::Storage::Plugin->lookup_types();
+
__PACKAGE__->register_method({
subclass => "PVE::API2::Storage::PruneBackups",
path => '{storage}/prunebackups',
@@ -308,6 +310,7 @@ __PACKAGE__->register_method({
{ subdir => 'download-url' },
{ subdir => 'file-restore' },
{ subdir => 'import-metadata' },
+ { subdir => 'identity' },
{ subdir => 'oci-registry-pull' },
{ subdir => 'prunebackups' },
{ subdir => 'rrd' },
@@ -1118,4 +1121,56 @@ __PACKAGE__->register_method({
},
});

+__PACKAGE__->register_method({
+ name => 'identity',
+ path => '{storage}/identity',
+ method => 'GET',
+ description => "Return identity information for this storage instance.",
+ permissions => {
+ check => ['perm', '/storage/{storage}', ['Datastore.Audit']],
+ },
+ protected => 1,
+ proxyto => 'node',
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ storage => get_standard_option('pve-storage-id'),
+ },
+ },
+ returns => {
+ type => "object",
+ properties => {
+ 'type' => {
+ type => 'string',
+ description => 'The type of the storage.',
+ enum => $storage_type_enum,
+ },
+ 'id' => {
+ type => 'string',
+ description => 'Unique identifier for this storage instance."
+ . " The exact format and semantics depend on the storage plugin type.',
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $storeid = extract_param($param, 'storage');
+
+ my $cfg = PVE::Storage::config();
+ my $scfg = PVE::Storage::storage_config($cfg, $storeid);
+
+ my $type = $scfg->{type};
+ my $plugin = PVE::Storage::Plugin->lookup($type);
+
+ my $id = $plugin->get_identity($scfg, $storeid);
+
+ return {
+ type => $type,
+ id => $id,
+ };
+ },
+});
+
1;
--
2.47.3