5
0
mirror of git://git.proxmox.com/git/pve-ha-manager.git synced 2025-01-07 21:18:00 +03:00

implement get_node_info

This commit is contained in:
Dietmar Maurer 2014-11-29 15:40:56 +01:00
parent 53a449bf4b
commit 91dab9cefe
2 changed files with 52 additions and 0 deletions

View File

@ -17,6 +17,16 @@ sub new {
return $self;
}
# this should return a hash containing info
# what nodes are members and online.
sub get_node_info {
my ($self) = @_;
die "implement me";
# return { node1 => { online => 1, join_time => X }, node2 => ... }
}
sub log {
my ($self, $level, $msg) = @_;

View File

@ -3,6 +3,7 @@ package PVE::HA::SimEnv;
use strict;
use warnings;
use POSIX qw(strftime);
use Data::Dumper;
use PVE::HA::Env;
@ -17,6 +18,31 @@ my $quorum_setup = [
[ 500 , [ 'node2', 'node3' ]],
];
my $compute_node_info = sub {
my $last_node_info = {};
foreach my $entry (@$quorum_setup) {
my ($time, $members) = @$entry;
my $node_info = {};
foreach my $node (@$members) {
$node_info->{$node}->{online} = 1;
if (!$last_node_info->{$node}) {
$node_info->{$node}->{join_time} = $time;
} else {
$node_info->{$node}->{join_time} =
$last_node_info->{$node}->{join_time};
}
}
push @$entry, $node_info;
$last_node_info = $node_info;
}
};
sub new {
my ($this, $nodename) = @_;
@ -26,6 +52,8 @@ sub new {
$self->{nodename} = $nodename;
&$compute_node_info();
return $self;
}
@ -68,6 +96,20 @@ sub get_ha_manager_lock {
return 0;
}
sub get_node_info {
my ($self) = @_;
foreach my $entry (reverse @$quorum_setup) {
my ($time, $members, $node_info) = @$entry;
if ($cur_time >= $time) {
return $node_info;
}
}
die "unbale to get node info";
}
sub loop_start_hook {
my ($self) = @_;