]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
fix #4522: api: vncproxy: also set environment variable for ticket without websocket
[qemu-server.git] / PVE / API2 / Qemu.pm
index fd718f93322546d19f6bfa8489bef5eb759451a3..9877ce24a9b7e2e581d894881787e29aa51657d2 100644 (file)
@@ -32,6 +32,7 @@ use PVE::QemuServer::Drive;
 use PVE::QemuServer::ImportDisk;
 use PVE::QemuServer::Monitor qw(mon_cmd);
 use PVE::QemuServer::Machine;
+use PVE::QemuServer::Memory qw(get_current_memory);
 use PVE::QemuServer::PCI;
 use PVE::QemuServer::USB;
 use PVE::QemuMigrate;
@@ -562,6 +563,7 @@ my $cloudinitoptions = {
     cipassword => 1,
     citype => 1,
     ciuser => 1,
+    ciupgrade => 1,
     nameserver => 1,
     searchdomain => 1,
     sshkeys => 1,
@@ -1481,7 +1483,7 @@ __PACKAGE__->register_method({
     proxyto => 'node',
     description => "Regenerate and change cloudinit config drive.",
     permissions => {
-       check => ['perm', '/vms/{vmid}', 'VM.Config.Cloudinit'],
+       check => ['perm', '/vms/{vmid}', ['VM.Config.Cloudinit']],
     },
     parameters => {
        additionalProperties => 0,
@@ -1572,8 +1574,6 @@ my $update_vm_api  = sub {
 
     my $storecfg = PVE::Storage::config();
 
-    my $defaults = PVE::QemuServer::load_defaults();
-
     &$resolve_cdrom_alias($param);
 
     # now try to verify all parameters
@@ -1693,7 +1693,9 @@ my $update_vm_api  = sub {
        }
 
        if ($param->{memory} || defined($param->{balloon})) {
-           my $maxmem = $param->{memory} || $conf->{pending}->{memory} || $conf->{memory} || $defaults->{memory};
+
+           my $memory = $param->{memory} || $conf->{pending}->{memory} || $conf->{memory};
+           my $maxmem = get_current_memory($memory);
            my $balloon = defined($param->{balloon}) ? $param->{balloon} : $conf->{pending}->{balloon} || $conf->{balloon};
 
            die "balloon value too large (must be smaller than assigned memory)\n"
@@ -1795,7 +1797,10 @@ my $update_vm_api  = sub {
                } elsif ($opt =~ m/^net\d+$/) {
                    if ($conf->{$opt}) {
                        PVE::QemuServer::check_bridge_access(
-                           $rpcenv, $authuser, { $opt => $conf->{$opt} });
+                           $rpcenv,
+                           $authuser,
+                           { $opt => $conf->{$opt} },
+                       );
                    }
                    PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force);
                    PVE::QemuConfig->write_config($vmid, $conf);
@@ -1870,7 +1875,10 @@ my $update_vm_api  = sub {
                } elsif ($opt =~ m/^net\d+$/) {
                    if ($conf->{$opt}) {
                        PVE::QemuServer::check_bridge_access(
-                           $rpcenv, $authuser, { $opt => $conf->{$opt} });
+                           $rpcenv,
+                           $authuser,
+                           { $opt => $conf->{$opt} },
+                       );
                    }
                    $conf->{pending}->{$opt} = $param->{$opt};
                } else {
@@ -2259,7 +2267,8 @@ __PACKAGE__->register_method({
            websocket => {
                optional => 1,
                type => 'boolean',
-               description => "starts websockify instead of vncproxy",
+               description => "Prepare for websocket upgrade (only required when using "
+                   ."serial terminal, otherwise upgrade is always possible).",
            },
            'generate-password' => {
                optional => 1,
@@ -2357,7 +2366,7 @@ __PACKAGE__->register_method({
 
            } else {
 
-               $ENV{LC_PVE_TICKET} = $password if $websocket; # set ticket with "qm vncproxy"
+               $ENV{LC_PVE_TICKET} = $password; # set ticket with "qm vncproxy"
 
                $cmd = [@$remcmd, "/usr/sbin/qm", 'vncproxy', $vmid];
 
@@ -3073,12 +3082,8 @@ __PACKAGE__->register_method({
 
        my $shutdown = 1;
 
-       # if vm is paused, do not shutdown (but stop if forceStop = 1)
-       # otherwise, we will infer a shutdown command, but run into the timeout,
-       # then when the vm is resumed, it will instantly shutdown
-       #
-       # checking the qmp status here to get feedback to the gui/cli/api
-       # and the status query should not take too long
+       # sending a graceful shutdown command to paused VMs runs into timeouts, and even worse, when
+       # the VM gets resumed later, it still gets the request delivered and powers off
        if (PVE::QemuServer::vm_is_paused($vmid)) {
            if ($param->{forceStop}) {
                warn "VM is paused - stop instead of shutdown\n";
@@ -5647,7 +5652,6 @@ __PACKAGE__->register_method({
                        'disk' => [
                            undef,
                            $storeid,
-                           undef,
                            $drive,
                            0,
                            $format,