[pve-devel] r6355 - in pve-storage/pve2: . PVE/API2/Storage

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jul 22 11:09:13 CEST 2011


Author: dietmar
Date: 2011-07-22 11:09:12 +0200 (Fri, 22 Jul 2011)
New Revision: 6355

Modified:
   pve-storage/pve2/ChangeLog
   pve-storage/pve2/PVE/API2/Storage/Scan.pm
   pve-storage/pve2/pvesm
Log:
	* PVE/API2/Storage/Scan.pm: split scan into three different
	methods with divverent return values



Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog	2011-07-22 08:02:13 UTC (rev 6354)
+++ pve-storage/pve2/ChangeLog	2011-07-22 09:09:12 UTC (rev 6355)
@@ -1,3 +1,8 @@
+2011-07-22  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/API2/Storage/Scan.pm: split scan into three different
+	methods with divverent return values
+
 2011-07-21  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/Storage.pm (storage_info): do not list disabled storages

Modified: pve-storage/pve2/PVE/API2/Storage/Scan.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Scan.pm	2011-07-22 08:02:13 UTC (rev 6354)
+++ pve-storage/pve2/PVE/API2/Storage/Scan.pm	2011-07-22 09:09:12 UTC (rev 6355)
@@ -43,42 +43,108 @@
 	return $res;
     }});
 
-# fixme: return value ?
 __PACKAGE__->register_method ({
-    name => 'scan', 
-    path => '{method:(lvm|iscsi|nfs)}', 
+    name => 'nfsscan', 
+    path => 'nfs', 
     method => 'GET',
-    description => "Scan remote storage server.",
+    description => "Scan remote NFS server.",
     protected => 1,
     proxyto => "node",
     parameters => {
     	additionalProperties => 0,
 	properties => {
 	    node => get_standard_option('pve-node'),
-	    method => { 
-		type => 'string',
-		enum => [ 'lvm', 'nfs', 'iscsi' ],
+	    server => { type => 'string', format => 'pve-storage-server' },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => { 
+		path => { type => 'string'},
+		options => { type => 'string'},
 	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $server = $param->{server};
+	my $res = PVE::Storage::scan_nfs($server);
+
+	my $data = [];
+	foreach my $k (keys %$res) {
+	    push @$data, { path => $k, options => $res->{$k} };
+	}
+	return $data;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'iscsiscan', 
+    path => 'iscsi', 
+    method => 'GET',
+    description => "Scan remote iSCSI server.",
+    protected => 1,
+    proxyto => "node",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
 	    server => { type => 'string', format => 'pve-storage-server' },
 	},
     },
-    returns => {},
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => { 
+		target => { type => 'string'},
+		portal => { type => 'string'},
+	    },
+	},
+    },
     code => sub {
 	my ($param) = @_;
 
 	my $server = $param->{server};
-	my $method = $param->{method};
+	my $res = PVE::Storage::scan_iscsi ($server);
 
-	my $res;
-	if ($method eq 'nfs') {
-	    $res = PVE::Storage::scan_nfs ($server);
-	} elsif ($method eq 'iscsi') {
-	    $res = PVE::Storage::scan_iscsi ($server);
-	} else {
-	    die "can't execute scan for storage type '$method'\n";
+	my $data = [];
+	foreach my $k (keys %$res) {
+	    push @$data, { target => $k, portal => $res->{$k} };
 	}
 
-	return $res;
+	return $data;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'lvmscan', 
+    path => 'lvm', 
+    method => 'GET',
+    description => "List local LVM volume groups.",
+    protected => 1,
+    proxyto => "node",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => { 
+		vg => { type => 'string'},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $res = PVE::Storage::lvm_vgs();
+	return PVE::RESTHandler::hash_to_array($res, 'vg');
+    }});
+
 1;

Modified: pve-storage/pve2/pvesm
===================================================================
--- pve-storage/pve2/pvesm	2011-07-22 08:02:13 UTC (rev 6354)
+++ pve-storage/pve2/pvesm	2011-07-22 09:09:12 UTC (rev 6355)
@@ -211,19 +211,39 @@
 	       }],
     free => [ "PVE::API2::Storage::Content", 'delete', ['volume'],
 	      { node => $nodename } ],
-    scan => [ "PVE::API2::Storage::Scan", 'scan', ['method', 'server'],
-	      { node => $nodename }, sub  {
-		  my $res = shift;
+    nfsscan => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'],
+		 { node => $nodename }, sub  {
+		     my $res = shift;
 
-		  my $maxlen = 0;
-		  foreach my $k (keys %$res) {
-		      my $len = length ($k);
-		      $maxlen = $len if $len > $maxlen;
-		  }
-		  foreach my $k (keys %$res) {
-		      printf "%-${maxlen}s $res->{$k}\n", $k;
-		  }
-	      }],
+		     my $maxlen = 0;
+		     foreach my $rec (@$res) {
+			 my $len = length ($rec->{path});
+			 $maxlen = $len if $len > $maxlen;
+		     }
+		     foreach my $rec (@$res) {
+			 printf "%-${maxlen}s %s\n", $rec->{path}, $rec->{options};
+		     }
+		 }],
+    iscsiscan => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['server'],
+		   { node => $nodename }, sub  {
+		       my $res = shift;
+
+		       my $maxlen = 0;
+		       foreach my $rec (@$res) {
+			   my $len = length ($rec->{target});
+			   $maxlen = $len if $len > $maxlen;
+		       }
+		       foreach my $rec (@$res) {
+			   printf "%-${maxlen}s %s\n", $rec->{target}, $rec->{portal};
+		       }
+		   }],
+    lvmscan => [ "PVE::API2::Storage::Scan", 'lvmscan', [],
+		 { node => $nodename }, sub  {
+		     my $res = shift;
+		     foreach my $rec (@$res) {
+			 printf "$rec->{vg}\n";
+		     }
+		 }],
     path => [ __PACKAGE__, 'path', ['volume']],
     lock => [ __PACKAGE__, 'lock', ['storage']],
 };




More information about the pve-devel mailing list