]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/Tools.pm
Tools/Config: refactor lrm status json reading
[pve-ha-manager.git] / src / PVE / HA / Tools.pm
index a4289f5c2f0e3715e8889c1720979ee27cda8950..2bdd6eaff65e05dabaef2561b052b1f880bb793e 100644 (file)
@@ -73,7 +73,8 @@ sub pve_verify_ha_group_node {
 }
 
 PVE::JSONSchema::register_standard_option('pve-ha-group-node-list', {
-    description => "List of cluster node names with optional priority. We use priority '0' as default. The CRM tries to run services on the node with highest priority (also see option 'nofailback').",
+    description => "List of cluster node names with optional priority.",
+    verbose_description => "List of cluster node members, where a priority can be given to each node. A resource bound to a group will run on the available nodes with the highest priority. If there are more nodes in the highest priority class, the services will get distributed to those nodes. The priorities have a relative meaning only.",
     type => 'string', format => 'pve-ha-group-node-list',
     typetext => '<node>[:<pri>]{,<node>[:<pri>]}*',
 });
@@ -123,16 +124,7 @@ sub read_json_from_file {
     if (defined($default) && (! -f $filename)) {
        $data = $default;
     } else {
-       my $raw;
-       # workaround for bug #775
-       if ($filename =~ m|^/etc/pve/|) {
-           $filename =~ s|^/etc/pve/+||;
-           $raw = PVE::Cluster::get_config($filename);
-           die "unable to read file '/etc/pve/$filename'\n" 
-               if !defined($raw);
-       } else {
-           $raw = PVE::Tools::file_get_contents($filename);
-       }
+       my $raw = PVE::Tools::file_get_contents($filename);
        $data = decode_json($raw);
     }
 
@@ -147,21 +139,6 @@ sub write_json_to_file {
     PVE::Tools::file_set_contents($filename, $raw);
 }
 
-sub has_services {
-    my ($haenv, $node) = @_;
-
-    my $conf = $haenv->read_service_config();
-
-    # if no node defined any service count is fine
-    return scalar(%{$conf}) if !defined($node);
-
-    foreach my $d (values %$conf) {
-       return 1 if $d->{node} eq $node;
-    }
-
-    return undef;
-}
-
 sub count_fenced_services {
     my ($ss, $node) = @_;
 
@@ -182,6 +159,40 @@ sub count_fenced_services {
     return $count;
 }
 
+sub get_verbose_service_state {
+    my ($service_state, $service_conf) = @_;
+
+    my $req = $service_conf->{state} // 'ignored';
+    return 'ignored' if $req eq 'ignored';
+
+    # service not yet processed by manager
+    return 'queued' if !defined($service_state);
+    my $cur = $service_state->{state};
+
+    # give fast feedback to the user
+    my $state = $cur;
+    if (!defined($cur)) {
+       $state = 'queued';
+    } elsif ($cur eq 'stopped') {
+       if ($req eq 'started') {
+           $state = 'starting';
+       } elsif ($req eq 'disabled') {
+           $state = 'disabled';
+       }
+    } elsif ($cur eq 'started') {
+       if ($req eq 'stopped' || $req eq 'disabled') {
+           $state = 'stopping';
+       }
+       $state = 'starting' if !$service_state->{running};
+    } elsif ($cur eq 'error') {
+       if ($req eq 'disabled') {
+           $state = 'clearing error flag';
+       }
+    }
+
+    return $state;
+}
+
 sub upid_wait {
     my ($upid, $haenv) = @_;