[pve-devel] [pve-storage cli cleanup 3/5] pvesm *scan: use print_api_result

Dietmar Maurer dietmar at proxmox.com
Thu Aug 9 11:43:46 CEST 2018


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/CLI/pvesm.pm | 98 +++++++++++++++++---------------------------------------
 1 file changed, 29 insertions(+), 69 deletions(-)

diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
index 9413aa9..aaf3da8 100755
--- a/PVE/CLI/pvesm.pm
+++ b/PVE/CLI/pvesm.pm
@@ -344,75 +344,35 @@ our $cmddef = {
 	       }],
     free => [ "PVE::API2::Storage::Content", 'delete', ['volume'],
 	      { node => $nodename } ],
-    nfsscan => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'],
-		 { node => $nodename }, sub  {
-		     my $res = shift;
-
-		     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};
-		     }
-		 }],
-    cifsscan => [ "PVE::API2::Storage::Scan", 'cifsscan', ['server'],
-		 { node => $nodename }, sub  {
-		     my $res = shift;
-
-		     my $maxlen = 0;
-		     foreach my $rec (@$res) {
-			 my $len = length ($rec->{share});
-			 $maxlen = $len if $len > $maxlen;
-		     }
-		     foreach my $rec (@$res) {
-			 printf "%-${maxlen}s %s\n", $rec->{share}, $rec->{description};
-		     }
-		 }],
-    glusterfsscan => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'],
-		 { node => $nodename }, sub  {
-		     my $res = shift;
-
-		     foreach my $rec (@$res) {
-			 printf "%s\n", $rec->{volname};
-		     }
-		 }],
-    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";
-		     }
-		 }],
-    lvmthinscan => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'],
-		 { node => $nodename }, sub  {
-		     my $res = shift;
-		     foreach my $rec (@$res) {
-			 printf "$rec->{lv}\n";
-		     }
-		 }],
-    zfsscan => [ "PVE::API2::Storage::Scan", 'zfsscan', [],
-		 { node => $nodename }, sub  {
-		     my $res = shift;
-
-		     foreach my $rec (@$res) {
-			 printf "$rec->{pool}\n";
-		     }
-		 }],
+    nfsscan => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'], { node => $nodename }, sub {
+	my ($data, $schema, $options) = @_;
+	PVE::CLIFormatter::print_api_result($data, $schema, ['path', 'options'], $options);
+     }, $PVE::RESTHandler::standard_output_options],
+     cifsscan => [ "PVE::API2::Storage::Scan", 'cifsscan', ['server'], { node => $nodename }, sub {
+	 my ($data, $schema, $options) = @_;
+	 PVE::CLIFormatter::print_api_result($data, $schema, ['share', 'description'], $options);
+    }, $PVE::RESTHandler::standard_output_options],
+    glusterfsscan => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'], { node => $nodename }, sub {
+	 my ($data, $schema, $options) = @_;
+	 PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
+    }, $PVE::RESTHandler::standard_output_options],
+    iscsiscan => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['server'], { node => $nodename }, sub {
+	my ($data, $schema, $options) = @_;
+	my $props = ['target', 'portal'];
+	PVE::CLIFormatter::print_api_result($data, $schema, $props, $options);
+    }, $PVE::RESTHandler::standard_output_options],
+    lvmscan => [ "PVE::API2::Storage::Scan", 'lvmscan', [], { node => $nodename }, sub {
+	my ($data, $schema, $options) = @_;
+	PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
+    }, $PVE::RESTHandler::standard_output_options],
+    lvmthinscan => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'], { node => $nodename }, sub  {
+	my ($data, $schema, $options) = @_;
+	PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
+    }, $PVE::RESTHandler::standard_output_options],
+    zfsscan => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, sub  {
+	my ($data, $schema, $options) = @_;
+	PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
+    }, $PVE::RESTHandler::standard_output_options],
     path => [ __PACKAGE__, 'path', ['volume']],
     extractconfig => [__PACKAGE__, 'extractconfig', ['volume']],
     export => [ __PACKAGE__, 'export', ['volume', 'format', 'filename']],
-- 
2.11.0




More information about the pve-devel mailing list