[pve-devel] [qemu-server cli cleanup 1/6] qm list: use print_api_result

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


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

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index f2b39ff..8f45138 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -28,6 +28,7 @@ use JSON;
 use PVE::JSONSchema qw(get_standard_option);
 use Term::ReadLine;
 
+use PVE::RESTHandler;
 use PVE::CLIHandler;
 
 use base qw(PVE::CLIHandler);
@@ -763,23 +764,10 @@ sub param_mapping {
 our $cmddef = {
     list => [ "PVE::API2::Qemu", 'vmlist', [],
 	     { node => $nodename }, sub {
-		 my $vmlist = shift;
-
-		 exit 0 if (!scalar(@$vmlist));
-
-		 printf "%10s %-20s %-10s %-10s %12s %-10s\n",
-		 qw(VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID);
-
-		 foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) {
-		     printf "%10s %-20s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name},
-		     $rec->{qmpstatus} || $rec->{status},
-		     ($rec->{maxmem} || 0)/(1024*1024),
-		     ($rec->{maxdisk} || 0)/(1024*1024*1024),
-		     $rec->{pid}||0;
-		 }
-
-
-	      } ],
+		 my ($data, $schema, $options) = @_;
+		 my $proplist = ['vmid', 'name', 'status', 'qmpstatus', 'cpus', 'maxmem', 'maxdisk', 'pid', 'uptime'];
+		 PVE::CLIFormatter::print_api_result($data, $schema, $proplist, $options);
+	      }, $PVE::RESTHandler::standard_output_options],
 
     create => [ "PVE::API2::Qemu", 'create_vm', ['vmid'], { node => $nodename }, $upid_exit ],
 
-- 
2.11.0




More information about the pve-devel mailing list