]> git.proxmox.com Git - pve-manager.git/commitdiff
api: node stopall: expose setting the task timeout as endpoint parameter
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 14 Jan 2023 15:52:27 +0000 (16:52 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 14 Jan 2023 16:41:04 +0000 (17:41 +0100)
Note that this changes the lower timeout of 60s for CTs also to 180s
like VM always used; besides that there's not much gained making that
distinction there was never a really good argument for this.

partially related to #4194

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

index 0183badc06da3d24a57612dadfac45e645f60ed1..7435fe13dc8160ba91c3d7b8c9f40bdb036ea3f1 100644 (file)
@@ -1866,18 +1866,16 @@ __PACKAGE__->register_method ({
     }});
 
 my $create_stop_worker = sub {
-    my ($nodename, $type, $vmid, $down_timeout) = @_;
+    my ($nodename, $type, $vmid, $timeout) = @_;
 
     if ($type eq 'lxc') {
        return if !PVE::LXC::check_running($vmid);
-       my $timeout =  int($down_timeout // 60);
        print STDERR "Stopping CT $vmid (timeout = $timeout seconds)\n";
        return PVE::API2::LXC::Status->vm_shutdown(
            { node => $nodename, vmid => $vmid, timeout => $timeout, forceStop => 1 }
        );
     } elsif ($type eq 'qemu') {
        return if !PVE::QemuServer::check_running($vmid, 1);
-       my $timeout =  int($down_timeout // 3 * 60);
        print STDERR "Stopping VM $vmid (timeout = $timeout seconds)\n";
        return PVE::API2::Qemu->vm_shutdown(
            { node => $nodename, vmid => $vmid, timeout => $timeout, forceStop => 1 }
@@ -1906,6 +1904,14 @@ __PACKAGE__->register_method ({
                type => 'string',  format => 'pve-vmid-list',
                optional => 1,
            },
+           'timeout' => {
+               description => 'Timeout for each guest shutdown task.',
+               type => 'integer',
+               optional => 1,
+               default => 180,
+               min => 0,
+               max => 2 * 3600, # mostly arbitrary, but we do not want to high timeouts
+           },
        },
     },
     returns => {
@@ -1944,7 +1950,8 @@ __PACKAGE__->register_method ({
 
                for my $vmid (sort {$b <=> $a} keys %$vmlist) {
                    my $d = $vmlist->{$vmid};
-                   my $upid = eval { $create_stop_worker->($nodename, $d->{type}, $vmid, $d->{down}) };
+                   my $timeout = int($d->{down} // $param->{timeout} // 180);
+                   my $upid = eval { $create_stop_worker->($nodename, $d->{type}, $vmid, $timeout) };
                    warn $@ if $@;
                    next if !$upid;