]> git.proxmox.com Git - pve-manager.git/commitdiff
api: node stopall: expose setting force-stop behavior
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 14 Jan 2023 15:56:39 +0000 (16:56 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 14 Jan 2023 16:41:04 +0000 (17:41 +0100)
So that one can really decide if this is a shutdown or an actual
stop.

partially related to #4194

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Nodes.pm

index 7435fe13dc8160ba91c3d7b8c9f40bdb036ea3f1..e90d2f66950fb5f66fd808f7fb35f785d716c210 100644 (file)
@@ -1866,19 +1866,19 @@ __PACKAGE__->register_method ({
     }});
 
 my $create_stop_worker = sub {
-    my ($nodename, $type, $vmid, $timeout) = @_;
+    my ($nodename, $type, $vmid, $timeout, $force_stop) = @_;
 
     if ($type eq 'lxc') {
        return if !PVE::LXC::check_running($vmid);
        print STDERR "Stopping CT $vmid (timeout = $timeout seconds)\n";
        return PVE::API2::LXC::Status->vm_shutdown(
-           { node => $nodename, vmid => $vmid, timeout => $timeout, forceStop => 1 }
+           { node => $nodename, vmid => $vmid, timeout => $timeout, forceStop => $force_stop }
        );
     } elsif ($type eq 'qemu') {
        return if !PVE::QemuServer::check_running($vmid, 1);
        print STDERR "Stopping VM $vmid (timeout = $timeout seconds)\n";
        return PVE::API2::Qemu->vm_shutdown(
-           { node => $nodename, vmid => $vmid, timeout => $timeout, forceStop => 1 }
+           { node => $nodename, vmid => $vmid, timeout => $timeout, forceStop => $force_stop }
        );
     } else {
        die "unknown VM type '$type'\n";
@@ -1904,6 +1904,12 @@ __PACKAGE__->register_method ({
                type => 'string',  format => 'pve-vmid-list',
                optional => 1,
            },
+           'force-stop' => {
+               description => 'Force a hard-stop after the timeout.',
+               type => 'boolean',
+               default => 1,
+               optional => 1,
+           },
            'timeout' => {
                description => 'Timeout for each guest shutdown task.',
                type => 'integer',
@@ -1951,7 +1957,10 @@ __PACKAGE__->register_method ({
                for my $vmid (sort {$b <=> $a} keys %$vmlist) {
                    my $d = $vmlist->{$vmid};
                    my $timeout = int($d->{down} // $param->{timeout} // 180);
-                   my $upid = eval { $create_stop_worker->($nodename, $d->{type}, $vmid, $timeout) };
+                   my $upid = eval {
+                       $create_stop_worker->(
+                           $nodename, $d->{type}, $vmid, $timeout, $param->{'force-stop'} // 1)
+                   };
                    warn $@ if $@;
                    next if !$upid;