[pve-devel] [PATCH ha-manager v2 3/6] sim: allow new service request states over gui

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jan 19 13:32:47 CET 2017


Change the old enabled/disabled GTK "Switch" element to a ComboBox
one and add all possible service states, so we can simulate the real
world behaviour with its new states better.

As we do not need to map a the boolean swicth value to our states
anymore, we may drop the set_setvice_state method from the RTHardware
class and use the one from the Hardware base class instead.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

changes since v1:
* delete set_service_state method now and use the base class one
  we overwrote it because we needed to map the boolean value from our GUI
  switch element to 'started' or 'disabled', as changed the boolean switch
  to a combobox with the actual states as choices we can use those directly
  and need no mapping

 src/PVE/HA/Sim/RTHardware.pm | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/src/PVE/HA/Sim/RTHardware.pm b/src/PVE/HA/Sim/RTHardware.pm
index 33debaa..ed0a65e 100644
--- a/src/PVE/HA/Sim/RTHardware.pm
+++ b/src/PVE/HA/Sim/RTHardware.pm
@@ -291,16 +291,6 @@ sub set_network_state {
     $self->sim_hardware_cmd("network $node $action"); 
 }
 
-sub set_service_state {
-    my ($self, $sid) = @_;
-
-    my $d = $self->{service_gui}->{$sid} || die "no such service '$sid'";
-    my $state = $d->{enable_btn}->get_active() ? 'started' : 'disabled';
-
-    $self->{service_config} = $self->SUPER::set_service_state($sid, $state);
-
-}
-
 sub create_node_control {
     my ($self) = @_;
 
@@ -420,9 +410,9 @@ sub create_service_control {
     $sgrid->set_column_spacing(5);
     $sgrid->set('margin', 5);
 
-    my $w = Gtk3::Label->new('Service');
+    my $w = Gtk3::Label->new('Service ID');
     $sgrid->attach($w, 0, 0, 1, 1);
-    $w = Gtk3::Label->new('Enable');
+    $w = Gtk3::Label->new('Request State');
     $sgrid->attach($w, 1, 0, 1, 1);
     $w = Gtk3::Label->new('Node');
     $sgrid->attach($w, 3, 0, 1, 1);
@@ -440,13 +430,19 @@ sub create_service_control {
 	$w = Gtk3::Label->new($sid);
 	$sgrid->attach($w, 0, $row, 1, 1);
 
-	$w = Gtk3::Switch->new();
+	$w = Gtk3::ComboBoxText->new();
 	$sgrid->attach($w, 1, $row, 1, 1);
-	$w->set_active(1) if $d->{state} eq 'started';
-	$self->{service_gui}->{$sid}->{enable_btn} = $w;
-	$w->signal_connect('notify::active' => sub {
-	    $self->set_service_state($sid);
-	}),
+	my $count = 0;
+	foreach my $state (qw(started stopped disabled)) {
+	    $w->append_text($state);
+	    $w->set_active($count) if $d->{state} eq $state;
+	    $count++;
+	}
+	$w->signal_connect(changed => sub {
+	    my $w = shift;
+	    my $state = $w->get_active_text();
+	    $self->set_service_state($sid, $state);
+	});
 
 
 	$w = Gtk3::Button->new('Migrate');
-- 
2.1.4




More information about the pve-devel mailing list