[pve-devel] [PATCH ha-manager 07/13] Add stop command to the API

Fabian Ebner f.ebner at proxmox.com
Thu Sep 26 13:38:53 CEST 2019


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/API2/HA/Resources.pm | 37 ++++++++++++++++++++++++++++++++++++
 src/PVE/CLI/ha_manager.pm    |  2 ++
 2 files changed, 39 insertions(+)

diff --git a/src/PVE/API2/HA/Resources.pm b/src/PVE/API2/HA/Resources.pm
index 0682b57..4e7205f 100644
--- a/src/PVE/API2/HA/Resources.pm
+++ b/src/PVE/API2/HA/Resources.pm
@@ -356,4 +356,41 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'stop',
+    protected => 1,
+    path => '{sid}/stop',
+    method => 'POST',
+    description => "Request the service to be stopped.",
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Console' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    sid => get_standard_option('pve-ha-resource-or-vm-id',
+				      { completion => \&PVE::HA::Tools::complete_sid }),
+	    timeout => {
+		description => "Timeout in seconds. If set to 0 a hard stop will be performed.",
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my ($sid, $type, $name) = PVE::HA::Config::parse_sid(extract_param($param, 'sid'));
+
+	PVE::HA::Config::service_is_ha_managed($sid);
+
+	check_service_state($sid);
+
+	PVE::HA::Config::queue_crm_commands("stop $sid $param->{timeout}");
+
+	return undef;
+    }});
+
 1;
diff --git a/src/PVE/CLI/ha_manager.pm b/src/PVE/CLI/ha_manager.pm
index 5ce4c30..c9d4e7f 100644
--- a/src/PVE/CLI/ha_manager.pm
+++ b/src/PVE/CLI/ha_manager.pm
@@ -114,6 +114,8 @@ our $cmddef = {
     migrate => [ "PVE::API2::HA::Resources", 'migrate', ['sid', 'node'] ],
     relocate => [ "PVE::API2::HA::Resources", 'relocate', ['sid', 'node'] ],
 
+    stop => [ "PVE::API2::HA::Resources", 'stop', ['sid', 'timeout'] ],
+
 };
 
 1;
-- 
2.20.1





More information about the pve-devel mailing list