]> git.proxmox.com Git - pve-storage.git/commitdiff
extend storage list API with useful parameters for clone
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 14 May 2013 07:56:11 +0000 (09:56 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 14 May 2013 07:56:11 +0000 (09:56 +0200)
Add ability to list shared storages availavlable on souce and target node.

PVE/API2/Storage/Config.pm
PVE/API2/Storage/Status.pm

index 59e0c825a5a877a09b8a82a4336f015d1864aa66..27b3a550076425214a7bfa92cbcd002f58e2457e 100755 (executable)
@@ -54,7 +54,6 @@ __PACKAGE__->register_method ({
                enum => $storage_type_enum,
                optional => 1,
            },
-
        },
     },
     returns => {
index 09222298131aaf1fc05b346f3dd533fa9795f404..09192df36dfd5c798894853ad5a1079e22e2198b 100644 (file)
@@ -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};
        }