[pve-devel] [RFC container] ha: use correct service id if CT is a template

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Nov 2 16:50:42 CET 2016


while CT templates are experimental still prepare them for HA

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/API2/LXC.pm        |  5 ++++-
 src/PVE/API2/LXC/Status.pm | 14 ++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 15ebb87..a39532e 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -879,7 +879,7 @@ __PACKAGE__->register_method({
 	my $vmid = extract_param($param, 'vmid');
 
 	# test if VM exists
-	PVE::LXC::Config->load_config($vmid);
+	my $conf = PVE::LXC::Config->load_config($vmid);
 
 	# try to detect errors early
 	if (PVE::LXC::check_running($vmid)) {
@@ -894,6 +894,9 @@ __PACKAGE__->register_method({
 
 		my $service = "ct:$vmid";
 
+		$service = "template:$vmid"
+		  if (PVE::LXC::Config->is_template($conf));
+
 		my $cmd = ['ha-manager', 'migrate', $service, $target];
 
 		print "Executing HA migrate for CT $vmid to node $target\n";
diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index 83a23f5..02f62e7 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -137,6 +137,8 @@ __PACKAGE__->register_method({
 
 	PVE::Cluster::check_cfs_quorum();
 
+	my $conf = PVE::LXC::Config->load_config($vmid);
+
 	if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
 
 	    my $hacmd = sub {
@@ -144,6 +146,9 @@ __PACKAGE__->register_method({
 
 		my $service = "ct:$vmid";
 
+		$service = "template:$vmid"
+		  if (PVE::LXC::Config->is_template($conf));
+
 		my $cmd = ['ha-manager', 'enable', $service];
 
 		print "Executing HA start for CT $vmid\n";
@@ -163,8 +168,6 @@ __PACKAGE__->register_method({
 
 		    syslog('info', "starting CT $vmid: $upid\n");
 
-		    my $conf = PVE::LXC::Config->load_config($vmid);
-
 		    die "you can't start a CT if it's a template\n"
 			if PVE::LXC::Config->is_template($conf);
 
@@ -230,6 +233,8 @@ __PACKAGE__->register_method({
 
 	die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
 
+	my $conf = PVE::LXC::Config->load_config($vmid);
+
 	if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
 
 	    my $hacmd = sub {
@@ -237,6 +242,9 @@ __PACKAGE__->register_method({
 
 		my $service = "ct:$vmid";
 
+		$service = "template:$vmid"
+		  if (PVE::LXC::Config->is_template($conf));
+
 		my $cmd = ['ha-manager', 'disable', $service];
 
 		print "Executing HA stop for CT $vmid\n";
@@ -256,8 +264,6 @@ __PACKAGE__->register_method({
 
 		    syslog('info', "stopping CT $vmid: $upid\n");
 
-		    my $conf = PVE::LXC::Config->load_config($vmid);
-
 		    if (!$skiplock && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
 			PVE::LXC::Config->check_lock($conf);
 		    }
-- 
2.1.4





More information about the pve-devel mailing list