X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qm;h=25f84ea026d5ad6147c141dd73e175a96d43c09b;hb=refs%2Fheads%2Fstable2.0-fixes;hp=94950038f652dfa6b34256a3342833573478299b;hpb=30f6cd84a20e5c48b5e85812a35f43396e0c1b98;p=qemu-server.git diff --git a/qm b/qm index 9495003..25f84ea 100755 --- a/qm +++ b/qm @@ -222,85 +222,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 $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}); - - 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', @@ -373,7 +294,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 $@; } @@ -382,6 +303,89 @@ __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) = @_; + + my $cfg = PVE::Cluster::cfs_read_file("storage.cfg"); + + my $info = PVE::Storage::vdisk_list($cfg, undef, $param->{vmid}); + + my $volid_hash = {}; + foreach my $storeid (keys %$info) { + foreach my $item (@{$info->{$storeid}}) { + next if !($item->{volid} && $item->{size}); + $volid_hash->{$item->{volid}} = $item; + } + } + + my $updatefn = sub { + my ($vmid) = @_; + + my $conf = PVE::QemuServer::load_config($vmid); + + PVE::QemuServer::check_lock($conf); + + my $changes; + + my $used = {}; + + # update size info + foreach my $opt (keys %$conf) { + if (PVE::QemuServer::valid_drivename($opt)) { + my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); + my $volid = $drive->{file}; + next if !$volid; + + $used->{$volid} = 1; + + next if PVE::QemuServer::drive_is_cdrom($drive); + next if !$volid_hash->{$volid}; + + $drive->{size} = $volid_hash->{$volid}->{size}; + $changes = 1; + $conf->{$opt} = PVE::QemuServer::print_drive($vmid, $drive); + } + } + + # add unused volumes + foreach my $storeid (keys %$info) { + foreach my $item (@{$info->{$storeid}}) { + next if !($item->{volid} && $item->{vmid}); + next if $item->{vmid} ne $vmid; + next if $item->{volid} =~ m/vm-$vmid-state-/; + next if $used->{$item->{volid}}; + $changes = 1; + PVE::QemuServer::add_unused_volume($conf, $item->{volid}); + } + } + + PVE::QemuServer::update_config_nolock($vmid, $conf, 1) if $changes; + }; + + if (defined($param->{vmid})) { + PVE::QemuServer::lock_config($param->{vmid}, $updatefn, $param->{vmid}); + } else { + my $vmlist = PVE::QemuServer::config_list(); + foreach my $vmid (keys %$vmlist) { + PVE::QemuServer::lock_config($vmid, $updatefn, $vmid); + } + } + + return undef; + }}); + my $cmddef = { list => [ "PVE::API2::Qemu", 'vmlist', [], { node => $nodename }, sub { @@ -411,6 +415,8 @@ my $cmddef = { 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 } ], config => [ "PVE::API2::Qemu", 'vm_config', ['vmid'], @@ -430,6 +436,12 @@ 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 ], + start => [ "PVE::API2::Qemu", 'vm_start', ['vmid'], { node => $nodename } , $upid_exit ], stop => [ "PVE::API2::Qemu", 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit ], @@ -450,17 +462,18 @@ 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', []], }; 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;