]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
simplify manager code
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 1 Dec 2014 10:31:36 +0000 (11:31 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 1 Dec 2014 10:35:52 +0000 (11:35 +0100)
PVE/HA/Manager.pm

index 5137c86f538cb9032698cd0ba518c48af92a143f..ee2a76b7f4437eaa6263af1ac589bd984d730603 100644 (file)
@@ -8,12 +8,20 @@ use Data::Dumper;
 use PVE::HA::NodeStatus;
 
 sub new {
-    my ($this, $env) = @_;
+    my ($this, $haenv) = @_;
 
     my $class = ref($this) || $this;
 
+    my $ms = $haenv->read_manager_status();
+
+    $ms->{master_node} = $haenv->nodename();
+
+    my $ns = PVE::HA::NodeStatus->new($haenv, $ms->{node_status} || {});
+
     my $self = bless {
-       env => $env,
+       haenv => $haenv,
+       ms => $ms, # master status
+       ns => $ns, # PVE::HA::NodeStatus
     }, $class;
 
     return $self;
@@ -25,27 +33,27 @@ sub cleanup {
     # todo: ?
 }
 
-sub manage {
+sub flush_master_status {
     my ($self) = @_;
 
-    my $haenv = $self->{env};
-
-    my $ms = $haenv->read_manager_status();
+    my $haenv = $self->{haenv};
+    my $ms = $self->{ms};
+    my $ns = $self->{ns};
 
-    $ms->{node_status} = {} if !$ms->{node_status};
+    $ms->{node_status} = $ns->{status};
+    $haenv->write_manager_status($ms);
+} 
 
-    my $node_status = PVE::HA::NodeStatus->new($haenv, $ms->{node_status});
+sub manage {
+    my ($self) = @_;
 
-    $ms->{master_node} = $haenv->nodename();
+    my $haenv = $self->{haenv};
+    my $ms = $self->{ms};
+    my $ns = $self->{ns};
 
-    my $node_info = $haenv->get_node_info();
+    $ns->update($haenv->get_node_info());
     
-    $node_status->update($node_info);
-    
-
-    $ms->{node_status} = $node_status->{status};
-    $haenv->write_manager_status($ms);
-
+    $self->flush_master_status();
 }