]> git.proxmox.com Git - pve-storage.git/commitdiff
volume_list: moved code from PVE::API2::Storage::Content
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 04:50:19 +0000 (06:50 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 04:50:19 +0000 (06:50 +0200)
For better code reuse.

PVE/API2/Storage/Content.pm
PVE/Storage.pm

index 63dc0a44cd21369af6de7e83fec4365688334ced..68cb713110aa89d79c89637ba8f79409ad2d6d05 100644 (file)
@@ -15,8 +15,6 @@ use PVE::JSONSchema qw(get_standard_option);
 
 use base qw(PVE::RESTHandler);
 
-my @ctypes = qw(images vztmpl iso backup);
-
 __PACKAGE__->register_method ({
     name => 'index', 
     path => '',
@@ -63,42 +61,17 @@ __PACKAGE__->register_method ({
 
        my $authuser = $rpcenv->get_user();
 
-       my $cts = $param->{content} ? [ $param->{content} ] : [ @ctypes ];
-
        my $storeid = $param->{storage};
 
-       my $vmid = $param->{vmid};
-
        my $cfg = cfs_read_file("storage.cfg");
 
-       my $scfg = PVE::Storage::storage_config($cfg, $storeid);
+       my $vollist = PVE::Storage::volume_list($cfg, $storeid, $param->{vmid}, $param->{content});
 
        my $res = [];
-       foreach my $ct (@$cts) {
-           my $data;
-           if ($ct eq 'images') {
-               $data = PVE::Storage::vdisk_list ($cfg, $storeid, $param->{vmid});
-           } elsif ($ct eq 'iso' && !defined($param->{vmid})) {
-               $data = PVE::Storage::template_list ($cfg, $storeid, 'iso');
-           } elsif ($ct eq 'vztmpl'&& !defined($param->{vmid})) {
-               $data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl');
-           } elsif ($ct eq 'backup') {
-               $data = PVE::Storage::template_list ($cfg, $storeid, 'backup');
-               foreach my $item (@{$data->{$storeid}}) {
-                   if (defined($vmid)) {
-                       @{$data->{$storeid}} = grep { $_->{volid} =~ m/\S+-$vmid-\S+/ } @{$data->{$storeid}};
-                   }
-               }
-           }
-
-           next if !$data || !$data->{$storeid};
-
-           foreach my $item (@{$data->{$storeid}}) {
-               eval { $rpcenv->check_volume_access($authuser, $cfg, undef, $item->{volid}); };
-               next if $@;
-               $item->{content} = $ct;
-               push @$res, $item;
-           }
+       foreach my $item (@$vollist) {
+           eval { $rpcenv->check_volume_access($authuser, $cfg, undef, $item->{volid}); };
+           next if $@;
+           push @$res, $item;
        }
 
        return $res;    
index 3d08caf6269af284f353add8688e39d7e8a8508f..3f46eb337754381d5574ae9852577f6e676c744e 100755 (executable)
@@ -759,6 +759,44 @@ sub vdisk_list {
     return $res;
 }
 
+sub volume_list {
+    my ($cfg, $storeid, $vmid, $content) = @_;
+
+    my @ctypes = qw(images vztmpl iso backup);
+
+    my $cts = $content ? [ $content ] : [ @ctypes ];
+
+    my $scfg = PVE::Storage::storage_config($cfg, $storeid);
+
+    my $res = [];
+    foreach my $ct (@$cts) {
+       my $data;
+       if ($ct eq 'images') {
+           $data = vdisk_list($cfg, $storeid, $vmid);
+       } elsif ($ct eq 'iso' && !defined($vmid)) {
+           $data = template_list($cfg, $storeid, 'iso');
+       } elsif ($ct eq 'vztmpl'&& !defined($vmid)) {
+           $data = template_list ($cfg, $storeid, 'vztmpl');
+       } elsif ($ct eq 'backup') {
+           $data = template_list ($cfg, $storeid, 'backup');
+           foreach my $item (@{$data->{$storeid}}) {
+               if (defined($vmid)) {
+                   @{$data->{$storeid}} = grep { $_->{volid} =~ m/\S+-$vmid-\S+/ } @{$data->{$storeid}};
+               }
+           }
+       }
+
+       next if !$data || !$data->{$storeid};
+
+       foreach my $item (@{$data->{$storeid}}) {
+           $item->{content} = $ct;
+           push @$res, $item;
+       }
+    }
+
+    return $res;
+}
+
 sub uevent_seqnum {
 
     my $filename = "/sys/kernel/uevent_seqnum";