]> git.proxmox.com Git - qemu-server.git/blobdiff - qm
drive-mirror : wait that busy eq false before block-job-complete
[qemu-server.git] / qm
diff --git a/qm b/qm
index 57e0b4fe33ac1934fbc327c6c02f91f540453d0c..cea223e29994a5325214d238c69b49ee6dc2ecdb 100755 (executable)
--- a/qm
+++ b/qm
@@ -1,6 +1,7 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
 
 use strict;
+use warnings;
 use Getopt::Long;
 use Fcntl ':flock';
 use File::Path;
@@ -44,9 +45,7 @@ my $upid_exit = sub {
 my $nodename = PVE::INotify::nodename();
 
 sub run_vnc_proxy {
-    my ($vmid) = @_;
-
-    my $path = PVE::QemuServer::vnc_socket($vmid);
+    my ($path) = @_;
 
     my $c;
     while ( ++$c < 10 && !-e $path ) { sleep(1); }
@@ -164,8 +163,17 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        my $vmid = $param->{vmid};
+       my $vnc_socket = PVE::QemuServer::vnc_socket($vmid);
 
-       run_vnc_proxy ($vmid);
+       if (my $ticket = $ENV{LC_PVE_TICKET}) {  # NOTE: ssh on debian only pass LC_* variables
+           PVE::QemuServer::vm_mon_cmd($vmid, "change", device => 'vnc', target => "unix:$vnc_socket,password");
+           PVE::QemuServer::vm_mon_cmd($vmid, "set_password", protocol => 'vnc', password => $ticket);
+           PVE::QemuServer::vm_mon_cmd($vmid, "expire_password", protocol => 'vnc', time => "+30");
+       } else {
+           PVE::QemuServer::vm_mon_cmd($vmid, "change", device => 'vnc', target => "unix:$vnc_socket,x509,password");
+       }
+
+       run_vnc_proxy($vnc_socket);
 
        return undef;
     }});
@@ -326,6 +334,59 @@ __PACKAGE__->register_method ({
        return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'terminal', 
+    path => 'terminal', 
+    method => 'POST',
+    description => "Open a terminal using a serial device (The VM need to have a serial device configured, for example 'serial0: socket')",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           vmid => get_standard_option('pve-vmid'),
+           iface => {
+               description => "Select the serial device. By default we simply use the first suitable device.",
+               type => 'string',
+               optional => 1,
+               enum => [qw(serial0 serial1 serial2 serial3)], 
+           }
+       },
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       my $vmid = $param->{vmid};
+
+       my $conf = PVE::QemuServer::load_config ($vmid); # check if VM exists
+
+       my $iface = $param->{iface};
+
+       if ($iface) { 
+           die "serial interface '$iface' is not configured\n" if !$conf->{$iface};
+           die "wrong serial type on interface '$iface'\n" if $conf->{$iface} ne 'socket';
+       } else {
+           foreach my $opt (qw(serial0 serial1 serial2 serial3)) {
+               if ($conf->{$opt} && ($conf->{$opt} eq 'socket')) {
+                   $iface = $opt;
+                   last;
+               }
+           }
+           die "unable to find a serial interface\n" if !$iface;
+       }
+
+       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+
+       my $socket = "/var/run/qemu-server/${vmid}.$iface";
+
+       my $cmd = "socat UNIX-CONNECT:$socket STDIO,raw,echo=0,escape=0x0f";
+
+       print "starting serial terminal on interface $iface (press control-O to exit)\n";
+
+       system($cmd);
+
+       return undef;
+    }});
+
 my $cmddef = {
     list => [ "PVE::API2::Qemu", 'vmlist', [],
             { node => $nodename }, sub {
@@ -359,7 +420,9 @@ my $cmddef = {
 
     resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
 
-    unlink => [ "PVE::API2::Qemu", 'unlink', ['vmid', 'idlist'], { node => $nodename } ],
+    move_disk => [ "PVE::API2::Qemu", 'move_vm_disk', ['vmid', 'disk', 'storage'], { node => $nodename }, $upid_exit ],
+
+    unlink => [ "PVE::API2::Qemu", 'unlink', ['vmid'], { node => $nodename } ],
 
     config => [ "PVE::API2::Qemu", 'vm_config', ['vmid'], 
                { node => $nodename }, sub {
@@ -411,6 +474,8 @@ my $cmddef = {
     monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
 
     mtunnel => [ __PACKAGE__, 'mtunnel', []],  
+
+    terminal => [ __PACKAGE__, 'terminal', ['vmid']],
 };
 
 my $cmd = shift;