]> git.proxmox.com Git - qemu-server.git/blobdiff - qm
add changelog entry for last commit
[qemu-server.git] / qm
diff --git a/qm b/qm
index bcf434d85b1d3e8f24a7ff4649a87a5d5508268b..297617df486e77cd34aead8f6cd7bdea9b1597bd 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;
@@ -48,6 +49,9 @@ sub run_vnc_proxy {
 
     my $path = PVE::QemuServer::vnc_socket($vmid);
 
+    my $c;
+    while ( ++$c < 10 && !-e $path ) { sleep(1); }
+
     my $s = IO::Socket::UNIX->new(Peer => $path, Timeout => 120);
 
     die "unable to connect to socket '$path' - $!" if !$s;
@@ -303,6 +307,79 @@ __PACKAGE__->register_method ({
 
     }});
 
+__PACKAGE__->register_method ({
+    name => 'rescan', 
+    path => 'rescan', 
+    method => 'POST',
+    description => "Rescan all storages and update disk sizes and unused disk images.",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           vmid => get_standard_option('pve-vmid', {optional => 1}),
+       },
+    },
+    returns => { type => 'null'},
+    code => sub {
+       my ($param) = @_;
+
+       PVE::QemuServer::rescan($param->{vmid});
+
+       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 {
@@ -328,13 +405,17 @@ my $cmddef = {
 
     destroy => [ "PVE::API2::Qemu", 'destroy_vm', ['vmid'], { node => $nodename }, $upid_exit ],
 
+    clone => [ "PVE::API2::Qemu", 'clone_vm', ['vmid', 'newid'], { node => $nodename }, $upid_exit ],
+
     migrate => [ "PVE::API2::Qemu", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit ],
 
     set => [ "PVE::API2::Qemu", 'update_vm', ['vmid'], { node => $nodename } ],
 
     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 {
@@ -353,6 +434,14 @@ my $cmddef = {
 
     status => [ __PACKAGE__, 'status', ['vmid']],
 
+    snapshot => [ "PVE::API2::Qemu", 'snapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
+
+    delsnapshot => [ "PVE::API2::Qemu", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
+
+    rollback => [ "PVE::API2::Qemu", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
+
+    template => [ "PVE::API2::Qemu", 'template', ['vmid'], { node => $nodename }],
+
     start => [ "PVE::API2::Qemu", 'vm_start', ['vmid'], { node => $nodename } , $upid_exit ],
 
     stop => [ "PVE::API2::Qemu", 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit ],
@@ -373,9 +462,13 @@ my $cmddef = {
 
     unlock => [ __PACKAGE__, 'unlock', ['vmid']],
 
+    rescan  => [ __PACKAGE__, 'rescan', []],
+
     monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
 
     mtunnel => [ __PACKAGE__, 'mtunnel', []],  
+
+    terminal => [ __PACKAGE__, 'terminal', ['vmid']],
 };
 
 my $cmd = shift;