[pve-devel] [PATCH v2 pve-ha-manager 1/5] Add 'service is ha managed' check

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Oct 12 15:04:38 CEST 2015


add a check for a given $sid if it's managed by the ha stack

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/HA/Config.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index 0a6dfa5..d6d974d 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -174,4 +174,20 @@ sub vm_is_ha_managed {
     return undef;
 }
 
+sub service_is_ha_managed {
+    my ($sid, $has_state, $noerr) = @_;
+
+    my $conf = cfs_read_file($ha_resources_config);
+
+    if (my $vm = $conf->{ids}->{$sid}) {
+	return 1 if !defined($has_state);
+
+	$vm->{state} = 'enabled' if !defined($vm->{state});
+	return 1 if $vm->{state} eq $has_state;
+    }
+
+    die "resource '$sid' is not HA managed\n" if !$noerr;
+
+    return undef;
+}
 1;
-- 
2.1.4




More information about the pve-devel mailing list