[pve-devel] [qemu-server cli cleanup 3/6] qm pending: use print_api_result

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


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/CLI/qm.pm | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 8d9e9ec..f894b8a 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -798,7 +798,9 @@ our $cmddef = {
 
     pending => [ "PVE::API2::Qemu", 'vm_pending', ['vmid'],
 		{ node => $nodename }, sub {
-		    my $data = shift;
+		    my ($data, $schema, $options) = @_;
+
+		    my $table = [];
 		    foreach my $item (sort { $a->{key} cmp $b->{key}} @$data) {
 			my $k = $item->{key};
 			next if $k eq 'digest';
@@ -810,18 +812,23 @@ our $cmddef = {
 			}
 			if (defined($v)) {
 			    if ($item->{delete}) {
-				print "del $k: $v\n";
+				push @$table, { status => 'del', key => $k, value => $v };
 			    } elsif (defined($p)) {
-				print "cur $k: $v\n";
-				print "new $k: $p\n";
+				push @$table, { status => 'cur', key => $k, value => $v };
+				push @$table, { status => 'new', key => $k, value => $p };
 			    } else {
-				print "cur $k: $v\n";
+				push @$table, { status => 'cur', key => $k, value => $v };
 			    }
 			} elsif (defined($p)) {
-			    print "new $k: $p\n";
+			    push @$table, { status => 'new', key => $k, value => $p };
 			}
 		    }
-		}],
+
+		    my $proplist = ['status', 'key', 'value'];
+		    my $tableschema = { type => 'array', items => { type => 'object' }};
+		    PVE::CLIFormatter::print_api_result($table, $tableschema, $proplist, $options);
+
+		}, $PVE::RESTHandler::standard_output_options],
 
     showcmd => [ __PACKAGE__, 'showcmd', ['vmid']],
 
-- 
2.11.0




More information about the pve-devel mailing list