[pve-devel] [PATCH v2 ha-manager 05/12] Add timeout parameter for shutdown

Fabian Ebner f.ebner at proxmox.com
Mon Sep 30 09:22:30 CEST 2019


Introduces a timeout parameter for shutting a resource down.
If the parameter is 0, we perform a hard stop instead of a shutdown.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/HA/Resources.pm       |  2 +-
 src/PVE/HA/Resources/PVECT.pm | 14 ++++++++++----
 src/PVE/HA/Resources/PVEVM.pm | 16 +++++++++++-----
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index 7c373bc..835c314 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -126,7 +126,7 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     die "implement in subclass";
 }
diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index a0f05f4..282f4ef 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -74,18 +74,24 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     my $nodename = $haenv->nodename();
-    my $shutdown_timeout = 60; # fixme: make this configurable
+    my $shutdown_timeout = $timeout // 60;
 
+    my $upid;
     my $params = {
 	node => $nodename,
 	vmid => $id,
-	timeout => $shutdown_timeout,
     };
 
-    my $upid = PVE::API2::LXC::Status->vm_shutdown($params);
+    if ($shutdown_timeout) {
+	$params->{timeout} = $shutdown_timeout;
+	$upid = PVE::API2::LXC::Status->vm_shutdown($params);
+    } else {
+	$upid = PVE::API2::LXC::Status->vm_stop($params);
+    }
+
     PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index 9dcf558..45d87e8 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -72,19 +72,25 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     my $nodename = $haenv->nodename();
-    my $shutdown_timeout = 60; # fixme: make this configurable
+    my $shutdown_timeout = $timeout // 60;
 
+    my $upid;
     my $params = {
 	node => $nodename,
 	vmid => $id,
-	timeout => $shutdown_timeout,
-	forceStop => 1,
     };
 
-    my $upid = PVE::API2::Qemu->vm_shutdown($params);
+    if ($shutdown_timeout) {
+	$params->{timeout} = $shutdown_timeout;
+	$params->{forceStop} = 1;
+	$upid = PVE::API2::Qemu->vm_shutdown($params);
+    } else {
+	$upid = PVE::API2::Qemu->vm_stop($params);
+    }
+
     PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
-- 
2.20.1





More information about the pve-devel mailing list