From 283608f3309dc42132c19d54284b7e7d472d1d82 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 14 May 2013 09:56:11 +0200 Subject: [PATCH] extend storage list API with useful parameters for clone Add ability to list shared storages availavlable on souce and target node. --- PVE/API2/Storage/Config.pm | 1 - PVE/API2/Storage/Status.pm | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm index 59e0c82..27b3a55 100755 --- a/PVE/API2/Storage/Config.pm +++ b/PVE/API2/Storage/Config.pm @@ -54,7 +54,6 @@ __PACKAGE__->register_method ({ enum => $storage_type_enum, optional => 1, }, - }, }, returns => { diff --git a/PVE/API2/Storage/Status.pm b/PVE/API2/Storage/Status.pm index 0922229..09192df 100644 --- a/PVE/API2/Storage/Status.pm +++ b/PVE/API2/Storage/Status.pm @@ -50,6 +50,16 @@ __PACKAGE__->register_method ({ type => 'string', format => 'pve-storage-content', optional => 1, }, + enabled => { + description => "Only list stores which are enabled (not disabled in config).", + type => 'boolean', + optional => 0, + }, + target => get_standard_option('pve-node', { + description => "If target is different to 'node', we only lists shared storages which " . + "content is accessible on this 'node' and the specified 'target' node.", + optional => 1, + }), }, }, returns => { @@ -66,6 +76,12 @@ __PACKAGE__->register_method ({ my $rpcenv = PVE::RPCEnvironment::get(); my $authuser = $rpcenv->get_user(); + my $localnode = PVE::INotify::nodename(); + + my $target = $param->{target}; + + undef $target if $target && ($target eq $localnode || $target eq 'localhost'); + my $cfg = cfs_read_file("storage.cfg"); my $info = PVE::Storage::storage_info($cfg, $param->{content}); @@ -80,6 +96,20 @@ __PACKAGE__->register_method ({ my $privs = [ 'Datastore.Audit', 'Datastore.AllocateSpace' ]; next if !$rpcenv->check_any($authuser, "/storage/$storeid", $privs, 1); next if $param->{storage} && $param->{storage} ne $storeid; + + my $scfg = PVE::Storage::storage_config($cfg, $storeid); + + next if $param->{enabled} && $scfg->{disable}; + + if ($target) { + # check if storage content is accessible on local node and specified target node + # we use this on the Clone GUI + + next if !$scfg->{shared}; + next if !PVE::Storage::storage_check_node($cfg, $storeid, undef, 1); + next if !PVE::Storage::storage_check_node($cfg, $storeid, $target, 1); + } + $res->{$storeid} = $info->{$storeid}; } -- 2.39.2