[pve-devel] [pve-manager cli cleanup 3/4] pveam available: use print_api_result

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


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/CLI/pveam.pm | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/PVE/CLI/pveam.pm b/PVE/CLI/pveam.pm
index 10511f24..ee103be5 100644
--- a/PVE/CLI/pveam.pm
+++ b/PVE/CLI/pveam.pm
@@ -11,6 +11,8 @@ use PVE::Cluster;
 use PVE::INotify;
 use PVE::RPCEnvironment;
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::CLIFormatter;
+use PVE::RESTHandler;
 use PVE::CLIHandler;
 use PVE::API2::Nodes;
 use PVE::Storage;
@@ -64,21 +66,35 @@ __PACKAGE__->register_method ({
 	    },
 	}
     },
-    returns => { type => 'null'},
+    returns => {
+	type => 'array',
+	items => {
+	    type => 'object',
+	    properties => {
+		section => {
+		    type => 'string',
+		    description => "Template section.",
+		},
+		volid => {
+		    type => 'string',
+		    description => "Template volume identifier.",
+		},
+	    },
+	},
+    },
     code => sub {
 	my ($param) = @_;
 
 	my $list = PVE::APLInfo::load_data();
-
+	my $res = [];
 	foreach my $section (sort keys %$list) {
 	    next if $section eq 'all';
 	    next if $param->{section} && $section ne $param->{section};
 	    foreach my $template (sort keys %{$list->{$section}}) {
-		print sprintf("%-15s %s\n", $section, $template);
+		push @$res, { section => $section, volid => $template };
 	    }
 	}
-	return undef;
-
+	return $res;
     }});
 
 __PACKAGE__->register_method ({
@@ -192,7 +208,10 @@ my $print_list = sub {
 our $cmddef = {
     update => [ __PACKAGE__, 'update', []],
     download => [ 'PVE::API2::Nodes::Nodeinfo', 'apl_download', [ 'storage', 'template'], { node => $nodename } ],
-    available => [  __PACKAGE__, 'available', []],
+    available => [  __PACKAGE__, 'available', [], undef, sub {
+	my ($data, $schema, $options) = @_;
+	PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
+    }, $PVE::RESTHandler::standard_output_options],
     list => [  __PACKAGE__, 'index', [ 'storage' ], { node => $nodename }, $print_list ],
     remove => [  __PACKAGE__, 'remove', [ 'template_path' ], { node => $nodename }]
 };
-- 
2.11.0




More information about the pve-devel mailing list