]> git.proxmox.com Git - qemu-server.git/commitdiff
qm agent: add output formatter
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Dec 2016 06:42:37 +0000 (07:42 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Dec 2016 06:44:23 +0000 (07:44 +0100)
PVE/CLI/qm.pm

index 0599260c4ea0de2b098faaefd9a32614acadda28..6abf6dbc3db12de840729f2aa26348ede168a939 100755 (executable)
@@ -18,6 +18,7 @@ use PVE::INotify;
 use PVE::RPCEnvironment;
 use PVE::QemuServer;
 use PVE::API2::Qemu;
+use JSON;
 use PVE::JSONSchema qw(get_standard_option);
 use Term::ReadLine;
 
@@ -405,6 +406,29 @@ __PACKAGE__->register_method ({
        return undef;
     }});
 
+
+my $print_agent_result = sub {
+    my ($data) = @_;
+
+    my $result = $data->{result};
+    return if !defined($result);
+
+    my $class = ref($result);
+
+    if (!$class) {
+       chomp $result;
+       return if $result =~ m/^\s*$/;
+       print "$result\n";
+       return;
+    }
+
+    if (($class eq 'HASH') && !scalar(keys %$result)) { # empty hash
+       return;
+    }
+
+    print to_json($result, { pretty => 1, canonical => 1});
+};
+
 our $cmddef = {
     list => [ "PVE::API2::Qemu", 'vmlist', [],
             { node => $nodename }, sub {
@@ -529,7 +553,8 @@ our $cmddef = {
 
     monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
 
-    agent  => [ "PVE::API2::Qemu", 'agent', ['vmid'], { node => $nodename }],
+    agent  => [ "PVE::API2::Qemu", 'agent', ['vmid'],
+               { node => $nodename }, $print_agent_result ],
 
     mtunnel => [ __PACKAGE__, 'mtunnel', []],