]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/Sim/Hardware.pm
add CRM command to switch an online node manually into maintenance without reboot
[pve-ha-manager.git] / src / PVE / HA / Sim / Hardware.pm
index 54b1d4913aa8fb6398c8c680d0592cdac96b4f17..9c63b3f5fefdb29e0d9026a3ab203695f5186cde 100644 (file)
@@ -29,6 +29,7 @@ my $watchdog_timeout = 60;
 # $testdir/hardware_status            Hardware description (number of nodes, ...)
 # $testdir/manager_status             CRM status (start with {})
 # $testdir/service_config             Service configuration
+# $testdir/static_service_stats       Static service usage information (cpu, memory)
 # $testdir/groups                     HA groups configuration
 # $testdir/service_status_<node>      Service status
 # $testdir/datacenter.cfg             Datacenter wide HA configuration
@@ -38,6 +39,7 @@ my $watchdog_timeout = 60;
 #
 # $testdir/status/cluster_locks        Cluster locks
 # $testdir/status/hardware_status      Hardware status (power/network on/off)
+# $testdir/status/static_service_stats Static service usage information (cpu, memory)
 # $testdir/status/watchdog_status      Watchdog status
 #
 # runtime status
@@ -330,6 +332,16 @@ sub write_service_status {
     return $res;
 }
 
+sub read_static_service_stats {
+    my ($self) = @_;
+
+    my $filename = "$self->{statusdir}/static_service_stats";
+    my $stats = eval { PVE::HA::Tools::read_json_from_file($filename) };
+    $self->log('error', "loading static service stats failed - $@") if $@;
+
+    return $stats;
+}
+
 my $default_group_config = <<__EOD;
 group: prefer_node1
     nodes node1
@@ -404,6 +416,10 @@ sub new {
        copy("$testdir/datacenter.cfg", "$statusdir/datacenter.cfg");
     }
 
+    if (-f "$testdir/static_service_stats") {
+       copy("$testdir/static_service_stats", "$statusdir/static_service_stats");
+    }
+
     my $cstatus = $self->read_hardware_status_nolock();
 
     foreach my $node (sort keys %$cstatus) {
@@ -538,6 +554,7 @@ sub get_cfs_state {
 #   power <node> <on|off>
 #   network <node> <on|off>
 #   delay <seconds>
+#   skip-round <crm|lrm> [<rounds=1>]
 #   cfs <node> <rw|update> <work|fail>
 #   reboot <node>
 #   shutdown <node>
@@ -555,7 +572,8 @@ sub sim_hardware_cmd {
 
        my $cstatus = $self->read_hardware_status_nolock();
 
-       my ($cmd, $objid, $action, $param) = split(/\s+/, $cmdstr);
+       my ($cmd, $objid, $action, @params) = split(/\s+/, $cmdstr);
+       my $param = $params[0]; # for convenience/legacy
 
        die "sim_hardware_cmd: no node or service for command specified"
            if !$objid;
@@ -645,6 +663,8 @@ sub sim_hardware_cmd {
                }
            } elsif ($action eq 'start') {
                $d->{crm} = $self->crm_control('start', $d, $lock_fh) if !defined($d->{crm});
+           } elsif ($action eq 'enable-node-maintenance' || $action eq 'disable-node-maintenance') {
+               $self->queue_crm_commands_nolock("$action $node");
            } else {
                die "sim_hardware_cmd: unknown action '$action'";
            }
@@ -671,7 +691,7 @@ sub sim_hardware_cmd {
 
            } elsif ($action eq 'add') {
 
-               $self->add_service($sid, {state => 'started', node => $param});
+               $self->add_service($sid, {state => $params[1] || 'started', node => $param});
 
            } elsif ($action eq 'delete') {
 
@@ -856,4 +876,17 @@ sub watchdog_update {
     return &$modify_watchog($self, $code);
 }
 
+sub get_static_node_stats {
+    my ($self) = @_;
+
+    my $cstatus = $self->read_hardware_status_nolock();
+
+    my $stats = {};
+    for my $node (keys $cstatus->%*) {
+       $stats->{$node} = { $cstatus->{$node}->%{qw(cpus memory)} };
+    }
+
+    return $stats;
+}
+
 1;