]> git.proxmox.com Git - qemu-server.git/commitdiff
Add qm agent.
authorWolfgang Link <w.link@proxmox.com>
Thu, 3 Nov 2016 14:26:50 +0000 (15:26 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 30 Nov 2016 11:30:31 +0000 (12:30 +0100)
This command makes it possible to run commnads on the Qemu-Guest-Agent if it is installed and running.

PVE/API2/Qemu.pm
PVE/CLI/qm.pm

index 902f028f3746f30371b8875abbc93ef536840cad..500e2df8fc04354786b7288eba289f14a8ff5231 100644 (file)
@@ -614,6 +614,7 @@ __PACKAGE__->register_method({
            { subdir => 'rrd' },
            { subdir => 'rrddata' },
            { subdir => 'monitor' },
+           { subdir => 'agent' },
            { subdir => 'snapshot' },
            { subdir => 'spiceproxy' },
            { subdir => 'sendkey' },
@@ -2839,6 +2840,51 @@ __PACKAGE__->register_method({
        return $res;
     }});
 
+__PACKAGE__->register_method({
+    name => 'agent',
+    path => '{vmid}/agent',
+    method => 'POST',
+    protected => 1,
+    proxyto => 'node',
+    description => "Execute Qemu Guest Agent commands.",
+    permissions => {
+       check => ['perm', '/vms/{vmid}', [ 'VM.Monitor' ]],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           vmid => get_standard_option('pve-vmid'),
+           command => {
+               type => 'string',
+               description => "The QGA command.",
+           }
+       },
+    },
+    returns => { type => 'object' },
+    code => sub {
+       my ($param) = @_;
+
+       my $vmid = $param->{vmid};
+
+       my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
+
+       die "Only qga commands are allowed\n" if $param->{command} !~ m/^guest-.*$/; 
+       die "No Qemu Guest Agent\n" if !defined($conf->{agent});
+       die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
+
+       my $res = '';
+       eval {
+           $res = PVE::QemuServer::vm_mon_cmd($vmid, $param->{command});
+       };
+
+       if (my $err = $@) {
+               return {'ERROR:', $err};
+       } else {
+               return {'OK:', $res};
+       }
+    }});
+
 __PACKAGE__->register_method({
     name => 'resize_vm',
     path => '{vmid}/resize',
index a0e0ba564d5bf0bc3bfb6e841687096d0541ac64..0599260c4ea0de2b098faaefd9a32614acadda28 100755 (executable)
@@ -529,6 +529,8 @@ our $cmddef = {
 
     monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
 
+    agent  => [ "PVE::API2::Qemu", 'agent', ['vmid'], { node => $nodename }],
+
     mtunnel => [ __PACKAGE__, 'mtunnel', []],
 
     terminal => [ __PACKAGE__, 'terminal', ['vmid']],