[pve-devel] [PATCH manager] fix #1578: api/resource hastate: fallback to resource cfg state

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Nov 27 12:43:31 CET 2017


With ignored or still queued services we have no hastate for a
service in the manager status available.

As we use hastate in the web UI to determine if a service is
configured for HA this could lead to confusion there.
For example, the VM/CT 'Manage HA' window thinks tries to add the
service again if its in the 'ignored' state, and then the backend
errors out because it is already configured.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/API2/Cluster.pm | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index 0e94e9ff..7f38e61c 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -14,6 +14,7 @@ use PVE::Storage;
 use PVE::API2Tools;
 use PVE::API2::Backup;
 use PVE::API2::HAConfig;
+use PVE::HA::Env::PVE2;
 use PVE::HA::Config;
 use PVE::API2::ClusterConfig;
 use JSON;
@@ -188,6 +189,7 @@ __PACKAGE__->register_method({
 	my $idlist = $vmlist->{ids} || {};
 
 	my $hastatus = PVE::HA::Config::read_manager_status();
+	my $haresources = PVE::HA::Config::read_resources_config();
 	my $hatypemap = {
 	    'qemu' => 'vm',
 	    'lxc' => 'ct'
@@ -245,8 +247,11 @@ __PACKAGE__->register_method({
 		# get ha status
 		if (my $hatype = $hatypemap->{$entry->{type}}) {
 		    my $sid = "$hatype:$vmid";
-		    if (defined($hastatus->{service_status}->{$sid})) {
-			$entry->{hastate} = $hastatus->{service_status}->{$sid}->{state};
+		    my $service;
+		    if ($service = $hastatus->{service_status}->{$sid}) {
+			$entry->{hastate} = $service->{state};
+		    } elsif ($service = $haresources->{ids}->{$sid}) {
+			$entry->{hastate} = $service->{state};
 		    }
 		}
 
-- 
2.11.0





More information about the pve-devel mailing list