[pve-devel] [PATCH 4/4] refactor and reuse code in vm_is_ha_managed

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Oct 23 14:04:26 CEST 2015


reuse service_is_ha_managed in vm_is_ha_managed to make code easier
and reduce same code.

Only test 'vm' and 'ct' as a service type, as those are the only
VM resources we have for now (and probably/hopefully the the next
years) and they are the only agent which can be uniquely identified
by the VMID.

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

diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm
index d6d974d..bb2fe05 100644
--- a/src/PVE/HA/Config.pm
+++ b/src/PVE/HA/Config.pm
@@ -159,17 +159,12 @@ sub read_crm_commands {
 sub vm_is_ha_managed {
     my ($vmid, $has_state) = @_;
 
-    my $conf = cfs_read_file($ha_resources_config);
-
-    my $types = PVE::HA::Resources->lookup_types();
-    foreach my $type (@$types) {
+    # only CT and VM can be identified uniquely by VMID
+    foreach my $type ('vm', 'ct') {
 	my $sid = "$type:$vmid";
 
-	if (my $vm = $conf->{ids}->{$sid}) {
-	    $vm->{state} = 'enabled' if !defined($vm->{state});
-	    return !defined($has_state) || $vm->{state} eq $has_state;
-	}
-}
+	return 1 if service_is_ha_managed($sid, $has_state, 1);
+    }
 
     return undef;
 }
-- 
2.1.4





More information about the pve-devel mailing list