]> git.proxmox.com Git - pve-ha-manager.git/blobdiff - src/PVE/HA/Sim/Hardware.pm
sim/hardware: sort and split use statements
[pve-ha-manager.git] / src / PVE / HA / Sim / Hardware.pm
index 8bd5cbdcc09d46eda5965df4ea7379e8708dcb5f..af7cade8ab97145f3b5125c6d6cade50cd3d63c0 100644 (file)
@@ -8,18 +8,19 @@ package PVE::HA::Sim::Hardware;
 
 use strict;
 use warnings;
-use POSIX qw(strftime EINTR);
-use JSON;
-use IO::File;
+
 use Fcntl qw(:DEFAULT :flock);
 use File::Copy;
 use File::Path qw(make_path remove_tree);
+use IO::File;
+use JSON;
+use POSIX qw(strftime EINTR);
+
 use PVE::HA::FenceConfig;
 use PVE::HA::Groups;
 
 my $watchdog_timeout = 60;
 
-
 # Status directory layout
 #
 # configuration
@@ -109,6 +110,20 @@ sub read_service_config {
     return $conf;
 }
 
+sub update_service_config {
+    my ($self, $sid, $param) = @_;
+
+    my $conf = $self->read_service_config();
+
+    my $sconf = $conf->{$sid} || die "no such resource '$sid'\n";
+
+    foreach my $k (%$param) {
+       $sconf->{$k} = $param->{$k};
+    }
+
+    $self->write_service_config($conf);
+}
+
 sub write_service_config {
     my ($self, $conf) = @_;
 
@@ -518,17 +533,19 @@ sub get_cfs_state {
     return !defined($res) || $res;
 }
 
-# simulate hardware commands
-# power <node> <on|off>
-# network <node> <on|off>
-# cfs <node> <rw|update> <work|fail>
-# reboot <node>
-# shutdown <node>
-# restart-lrm <node>
-# service <sid> <started|disabled|stopped|ignored>
-# service <sid> <migrate|relocate> <target>
-# service <sid> lock/unlock [lockname]
-
+# simulate hardware commands, the following commands are available:
+#   power <node> <on|off>
+#   network <node> <on|off>
+#   delay <seconds>
+#   cfs <node> <rw|update> <work|fail>
+#   reboot <node>
+#   shutdown <node>
+#   restart-lrm <node>
+#   service <sid> <started|disabled|stopped|ignored>
+#   service <sid> <migrate|relocate> <target>
+#   service <sid> stop <timeout>
+#   service <sid> lock/unlock [lockname]
+#   service <sid> <add|delete>
 sub sim_hardware_cmd {
     my ($self, $cmdstr, $logid) = @_;
 
@@ -537,7 +554,7 @@ sub sim_hardware_cmd {
 
        my $cstatus = $self->read_hardware_status_nolock();
 
-       my ($cmd, $objid, $action, $target) = split(/\s+/, $cmdstr);
+       my ($cmd, $objid, $action, $param) = split(/\s+/, $cmdstr);
 
        die "sim_hardware_cmd: no node or service for command specified"
            if !$objid;
@@ -601,10 +618,10 @@ sub sim_hardware_cmd {
        } elsif ($cmd eq 'cfs') {
            die "sim_hardware_cmd: unknown cfs action '$action' for node '$node'"
                if $action !~ m/^(rw|update)$/;
-           die "sim_hardware_cmd: unknown cfs command '$target' for '$action' on node '$node'"
-               if $target !~ m/^(work|fail)$/;
+           die "sim_hardware_cmd: unknown cfs command '$param' for '$action' on node '$node'"
+               if $param !~ m/^(work|fail)$/;
 
-           $cstatus->{$node}->{cfs}->{$action} = $target eq 'work';
+           $cstatus->{$node}->{cfs}->{$action} = $param eq 'work';
            $self->write_hardware_status_nolock($cstatus);
 
        } elsif ($cmd eq 'reboot' || $cmd eq 'shutdown') {
@@ -640,13 +657,20 @@ sub sim_hardware_cmd {
            } elsif ($action eq 'migrate' || $action eq 'relocate') {
 
                die "sim_hardware_cmd: missing target node for '$action' command"
-                   if !$target;
+                   if !$param;
+
+               $self->queue_crm_commands_nolock("$action $sid $param");
+
+           } elsif ($action eq 'stop') {
+
+               die "sim_hardware_cmd: missing timeout for '$action' command"
+                   if !defined($param);
 
-               $self->queue_crm_commands_nolock("$action $sid $target");
+               $self->queue_crm_commands_nolock("$action $sid $param");
 
            } elsif ($action eq 'add') {
 
-               $self->add_service($sid, {state => 'started', node => $target});
+               $self->add_service($sid, {state => 'started', node => $param});
 
            } elsif ($action eq 'delete') {
 
@@ -654,11 +678,11 @@ sub sim_hardware_cmd {
 
            } elsif ($action eq 'lock') {
 
-               $self->lock_service($sid, $target);
+               $self->lock_service($sid, $param);
 
            } elsif ($action eq 'unlock') {
 
-               $self->unlock_service($sid, $target);
+               $self->unlock_service($sid, $param);
 
            } else {
                die "sim_hardware_cmd: unknown service action '$action' " .