[pve-devel] [RFC ha-manager 2/8] introduce 'is_on_node' method to service plugins

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jan 22 17:06:36 CET 2016


Can be used to check if a service has really moved when migrating.
Replaces the static check if the old config file still exists.
This check is only suitable for services with configs bound to the
pmxcfs, and thus still suitable for QEMU VMs and LXC CTs but for
the planned virtual (test) resources it's not.

Also a real agent like an IP probably needs also another check than
a test if a config file still exists.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Env/PVE2.pm        | 6 ++----
 src/PVE/HA/Resources.pm       | 6 ++++++
 src/PVE/HA/Resources/PVECT.pm | 9 +++++++++
 src/PVE/HA/Resources/PVEVM.pm | 9 +++++++++
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 8a36a0b..c8bf3e6 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -483,12 +483,10 @@ sub exec_resource_agent {
 
 	my $online = ($cmd eq 'migrate') ? 1 : 0;
 
-	my $oldconfig = $plugin->config_file($vmid, $nodename);
-
 	$plugin->migrate($self, $vmid, $target, $online);
 
-	# something went wrong if old config file is still there
-	if (-f $oldconfig) {
+	# something went wrong if service is still on this node
+	if ($plugin->is_on_node($self, $nodename, $vmid)) {
 	    $self->log("err", "service $sid not moved (migration error)");
 	    return ERROR;
 	}
diff --git a/src/PVE/HA/Resources.pm b/src/PVE/HA/Resources.pm
index fce7d54..615e904 100644
--- a/src/PVE/HA/Resources.pm
+++ b/src/PVE/HA/Resources.pm
@@ -112,6 +112,12 @@ sub config_file {
     die "implement in subclass"
 }
 
+sub is_on_node {
+    my ($class, $haenv, $node, $id) = @_;
+
+    die "implement in subclass"
+}
+
 sub exists {
     my ($class, $id, $noerr) = @_;
 
diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index e70c358..ce08004 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -35,6 +35,15 @@ sub config_file {
     return PVE::LXC::config_file($vmid, $nodename);
 }
 
+sub is_on_node {
+    my ($class, $haenv, $node, $id) = @_;
+
+    # simply check if the config file is there
+    my $path = $class->config_file($id, $node);
+
+    return (-f $path);
+}
+
 sub exists {
     my ($class, $vmid, $noerr) = @_;
 
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index 03b894b..19d7e91 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -34,6 +34,15 @@ sub config_file {
     return PVE::QemuServer::config_file($vmid, $nodename);
 }
 
+sub is_on_node {
+    my ($class, $haenv, $node, $id) = @_;
+
+    # simply check if the config file is there
+    my $path = $class->config_file($id, $node);
+
+    return (-f $path);
+}
+
 sub exists {
     my ($class, $vmid, $noerr) = @_;
 
-- 
2.1.4





More information about the pve-devel mailing list