From: Dominik Rusovac <[email protected]>

This decouples the stats input for the set-static-stats command. Using
the old version one had to pass both, the maxcpu and maxmem stat, even
if they wanted to set only one of the stats. To me, it appears to be
more convenient to set one stat at a time instead of having to pass the
value of the stat that is not changing alongside the value that should
be changed.

Signed-off-by: Dominik Rusovac <[email protected]>
Signed-off-by: Daniel Kral <[email protected]>
---
 src/PVE/HA/Sim/Hardware.pm   | 23 ++++++++++++++++-------
 src/PVE/HA/Sim/RTHardware.pm |  3 ++-
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 4d82e18c..ec135e09 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -743,7 +743,7 @@ sub get_cfs_state {
 #   service <sid> stop <timeout>
 #   service <sid> lock/unlock [lockname]
 #   service <sid> add <node> [<request-state=started>] [<running=0>]
-#   service <sid> set-static-stats <maxcpu> <maxmem>
+#   service <sid> set-static-stats  <maxcpu|maxmem> <cpu cores|MiB>
 #   service <sid> delete
 sub sim_hardware_cmd {
     my ($self, $cmdstr, $logid) = @_;
@@ -894,14 +894,23 @@ sub sim_hardware_cmd {
                 );
 
             } elsif ($action eq 'set-static-stats') {
-                die "sim_hardware_cmd: missing maxcpu for '$action' command" 
if !$params[0];
-                die "sim_hardware_cmd: missing maxmem for '$action' command" 
if !$params[1];
+                my ($target, $val) = ($params[0], $params[1]);
 
-                $self->set_static_service_stats(
-                    $sid,
-                    { maxcpu => 0.0 + $params[0], maxmem => int($params[1]) },
-                );
+                if (!$target) {
+                    die "sim_hardware_cmd: missing target stat for '$action' 
command";
+                } elsif ($target eq "maxcpu") {
+                    die "sim_hardware_cmd: missing value for '$action $target' 
command"
+                        if !$val;
 
+                    $self->set_static_service_stats($sid, { $target => 0.0 + 
$val });
+                } elsif ($target eq "maxmem") {
+                    die "sim_hardware_cmd: missing value for '$action $target' 
command"
+                        if !$val;
+
+                    $self->set_static_service_stats($sid, { $target => $val * 
1024**2 });
+                } else {
+                    die "sim_hardware_cmd: unknown target stat '$target' for 
'$action' command";
+                }
             } elsif ($action eq 'delete') {
 
                 $self->delete_service($sid);
diff --git a/src/PVE/HA/Sim/RTHardware.pm b/src/PVE/HA/Sim/RTHardware.pm
index 9a83d098..3fc52240 100644
--- a/src/PVE/HA/Sim/RTHardware.pm
+++ b/src/PVE/HA/Sim/RTHardware.pm
@@ -532,7 +532,8 @@ sub show_service_add_dialog {
 
         my $maxcpu = $cpu_count_spin->get_value();
         my $maxmem = $memory_spin->get_value();
-        $self->sim_hardware_cmd("service $sid set-static-stats $maxcpu 
$maxmem", 'command');
+        $self->sim_hardware_cmd("service $sid set-static-stats maxcpu 
$maxcpu", 'command');
+        $self->sim_hardware_cmd("service $sid set-static-stats maxmem 
$maxmem", 'command');
 
         $self->add_service_to_gui($sid);
     }
-- 
2.47.3




Reply via email to