[pve-devel] [PATCH manager v3 1/2] add hastate to /cluster/resources api call

Dominik Csapak d.csapak at proxmox.com
Tue Oct 25 14:12:22 CEST 2016


this adds a hastate field to all vms/ct which have ha enabled

we will use this for showing the error state in the tree (in the webgui)
and for the cluster dashboard (to count the error state guests)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes to v2:
 * fixed syntax error
 PVE/API2/Cluster.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index 331e2f7..8a7e538 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -168,6 +168,15 @@ __PACKAGE__->register_method({
 	my $vmlist = PVE::Cluster::get_vmlist() || {};
 	my $idlist = $vmlist->{ids} || {};
 
+
+	my $nodename = PVE::INotify::nodename();
+	my $haenv = PVE::HA::Env::PVE2->new($nodename);
+	my $hastatus = $haenv->read_manager_status();
+	my $hatypemap = {
+	    'qemu' => 'vm',
+	    'lxc' => 'ct'
+	};
+
 	my $pooldata = {};
 	if (!$param->{type} || $param->{type} eq 'pool') {
 	    foreach my $pool (keys %{$usercfg->{pools}}) {
@@ -217,6 +226,12 @@ __PACKAGE__->register_method({
 		
 		next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Audit' ], 1);
 
+		# get ha status
+		my $hatype = $hatypemap->{$entry->{type}};
+		if (defined($hastatus->{service_status}->{"$hatype:$vmid"})) {
+		    $entry->{hastate} = $hastatus->{service_status}->{"$hatype:$vmid"}->{state};
+		}
+
 		push @$res, $entry;
 	    }
 	}
-- 
2.1.4





More information about the pve-devel mailing list