]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
implement monitor API
[qemu-server.git] / PVE / API2 / Qemu.pm
index 3d6304e115298d4bdd18d805ea7ea577e27a513d..8dfd1a53d6a45928730d491f81a13d24bbb8dd60 100644 (file)
@@ -2,6 +2,7 @@ package PVE::API2::Qemu;
 
 use strict;
 use warnings;
+use Cwd 'abs_path';
 
 use PVE::Cluster;
 use PVE::SafeSyslog;
@@ -143,10 +144,23 @@ __PACKAGE__->register_method({
            PVE::QemuServer::add_random_macs($param);
        } else {
            my $keystr = join(' ', keys %$param);
-           raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr; 
-       }
+           raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr;
+
+           if ($archive eq '-') {
+               die "pipe requires cli environment\n" 
+                   && $rpcenv->{type} ne 'cli';
+           } else {
+               if (PVE::Storage::parse_volume_id($archive, 1)) {
+                   $archive = PVE::Storage::path($storecfg, $archive);
+               } else {
+                   raise_param_exc({ archive => "Only root can pass arbitrary paths." }) 
+                       if $user ne 'root@pam';
 
-       # fixme: archive eq '-' (read from stdin)
+                   $archive = abs_path($archive);
+               }
+               die "can't find file '$archive'\n" if ! -f $archive;
+           } 
+       }
 
        my $restorefn = sub {
 
@@ -250,6 +264,7 @@ __PACKAGE__->register_method({
            { subdir => 'migrate' },
            { subdir => 'rrd' },
            { subdir => 'rrddata' },
+           { subdir => 'monitor' },
            ];
        
        return $res;
@@ -692,7 +707,7 @@ __PACKAGE__->register_method({
 
        my $remip;
        
-       if ($node ne PVE::INotify::nodename()) {
+       if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
            $remip = PVE::Cluster::remote_node_ip($node);
        }
 
@@ -1231,4 +1246,39 @@ __PACKAGE__->register_method({
        return $upid;
     }});
 
+__PACKAGE__->register_method({
+    name => 'monitor', 
+    path => '{vmid}/monitor', 
+    method => 'POST',
+    protected => 1,
+    proxyto => 'node',
+    description => "Execute Qemu monitor commands.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           vmid => get_standard_option('pve-vmid'),
+           command => {
+               type => 'string',
+               description => "The monitor command.",
+           }
+       },
+    },
+    returns => { type => 'string'},
+    code => sub {
+       my ($param) = @_;
+
+       my $vmid = $param->{vmid};
+
+       my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
+
+       my $res = '';
+       eval {
+           $res = PVE::QemuServer::vm_monitor_command($vmid, $param->{command});
+       };
+       $res = "ERROR: $@" if $@;
+
+       return $res;
+    }});
+
 1;