X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qm;h=b6617230a6d767cc95cc424d8ffd75d096400aa7;hb=fc79e813536966e9a08ed8daf64a680d1d670936;hp=b45dc319f25f6dca24d7876fdbbf52c778d55a05;hpb=3a2232b3dbb48a42f06f974198177c23d57b5714;p=qemu-server.git diff --git a/qm b/qm index b45dc319..b6617230 100755 --- 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,10 @@ my $upid_exit = sub { my $nodename = PVE::INotify::nodename(); sub run_vnc_proxy { - my ($vmid) = @_; + my ($path) = @_; - 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); @@ -161,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; }}); @@ -187,6 +198,7 @@ __PACKAGE__->register_method ({ PVE::QemuServer::lock_config ($vmid, sub { my $conf = PVE::QemuServer::load_config($vmid); delete $conf->{lock}; + delete $conf->{pending}->{lock} if $conf->{pending}; # just to be sure PVE::QemuServer::update_config_nolock($vmid, $conf, 1); }); @@ -222,90 +234,6 @@ __PACKAGE__->register_method ({ return undef; }}); -__PACKAGE__->register_method ({ - name => 'startall', - path => 'startall', - method => 'POST', - description => "Start all virtual machines (when onboot=1).", - parameters => { - additionalProperties => 0, - properties => {}, - }, - returns => { type => 'null'}, - code => sub { - my ($param) = @_; - - # wait up to 10 seconds for quorum - for (my $i = 10; $i >= 0; $i--) { - last if PVE::Cluster::check_cfs_quorum($i != 0 ? 1 : 0); - sleep(1); - } - - my $vzlist = PVE::QemuServer::vzlist(); - my $storecfg = PVE::Storage::config(); - - my $cc = PVE::Cluster::cfs_read_file('cluster.conf'); - - my $count = 0; - foreach my $vmid (keys %$vzlist) { - next if $vzlist->{$vmid}->{pid}; # already running - - my $conf; - eval { $conf = PVE::QemuServer::load_config($vmid); }; - if (my $err = $@) { - warn $err; - next; - } - - next if !($conf && $conf->{onboot}); - - # skip ha managed VMs (started by rgmanager) - next if PVE::Cluster::cluster_conf_lookup_pvevm($cc, 0, $vmid, 1); - - sleep(2) if $count != 0; # reduce load - $count++; - - PVE::Cluster::check_cfs_quorum(); # abort when we loose quorum - - eval { - print STDERR "Starting Qemu VM $vmid\n"; - PVE::QemuServer::vm_start($storecfg, $vmid); - }; - warn $@ if $@; - } - - return undef; - }}); - -__PACKAGE__->register_method ({ - name => 'stopall', - path => 'stopall', - method => 'POST', - description => "Stop all virtual machines.", - parameters => { - additionalProperties => 0, - properties => { - timeout => { - description => "Timeout in seconds. Default is to wait 3 minutes.", - type => 'integer', - minimum => 1, - optional => 1, - } - }, - }, - returns => { type => 'null'}, - code => sub { - my ($param) = @_; - - my $timeout = $param->{timeout}; - - my $storecfg = PVE::Storage::config(); - - PVE::QemuServer::vm_stopall($storecfg, $timeout); - - return undef; - }}); - __PACKAGE__->register_method ({ name => 'wait', path => 'wait', @@ -378,7 +306,7 @@ __PACKAGE__->register_method ({ last if $input =~ m/^\s*q(uit)?\s*$/; eval { - print PVE::QemuServer::vm_monitor_command ($vmid, $input); + print PVE::QemuServer::vm_human_monitor_command ($vmid, $input); }; print "ERROR: $@" if $@; } @@ -387,6 +315,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 { @@ -412,11 +413,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 } ], - unlink => [ "PVE::API2::Qemu", 'unlink', ['vmid', 'idlist'], { node => $nodename } ], + resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { 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 { @@ -431,10 +438,45 @@ my $cmddef = { } }], + pending => [ "PVE::API2::Qemu", 'vm_pending', ['vmid'], + { node => $nodename }, sub { + my $data = shift; + foreach my $item (sort { $a->{key} cmp $b->{key}} @$data) { + my $k = $item->{key}; + next if $k eq 'digest'; + my $v = $item->{value}; + my $p = $item->{pending}; + if ($k eq 'description') { + $v = PVE::Tools::encode_text($v) if defined($v); + $p = PVE::Tools::encode_text($p) if defined($p); + } + if (defined($v)) { + if ($item->{delete}) { + print "del $k: $v\n"; + } elsif (defined($p)) { + print "cur $k: $v\n"; + print "new $k: $p\n"; + } else { + print "cur $k: $v\n"; + } + } elsif (defined($p)) { + print "new $k: $p\n"; + } + } + }], + showcmd => [ __PACKAGE__, 'showcmd', ['vmid']], 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 ], @@ -455,17 +497,20 @@ my $cmddef = { unlock => [ __PACKAGE__, 'unlock', ['vmid']], - monitor => [ __PACKAGE__, 'monitor', ['vmid']], - - startall => [ __PACKAGE__, 'startall', []], + rescan => [ __PACKAGE__, 'rescan', []], - stopall => [ __PACKAGE__, 'stopall', []], + monitor => [ __PACKAGE__, 'monitor', ['vmid']], mtunnel => [ __PACKAGE__, 'mtunnel', []], + + terminal => [ __PACKAGE__, 'terminal', ['vmid']], }; my $cmd = shift; +# Note: disable '+' prefix for Getopt::Long (for resize command) +use Getopt::Long qw(:config no_getopt_compat); + PVE::CLIHandler::handle_cmd($cmddef, "qm", $cmd, \@ARGV, undef, $0); exit 0;