]> git.proxmox.com Git - pve-ha-manager.git/blob - PVE/HA/Env.pm
implement helper to return quorum info
[pve-ha-manager.git] / PVE / HA / Env.pm
1 package PVE::HA::Env;
2
3 use strict;
4 use warnings;
5
6 use PVE::SafeSyslog;
7
8 # abstract out the cluster environment
9
10 sub new {
11 my ($this, $statusdir) = @_;
12
13 my $class = ref($this) || $this;
14
15 my $self = bless {
16 statusdir => $statusdir,
17 }, $class;
18
19 return $self;
20 }
21
22 sub read_local_status {
23 my ($self) = @_;
24
25 return PVE::Tools::file_read_firstline("$self->{statusdir}/status");
26 }
27
28 sub write_local_status {
29 my ($self, $status) = @_;
30
31 PVE::Tools::file_set_contents("$self->{statusdir}/status", $status);
32 }
33
34 # this should return a hash containing info
35 # what nodes are members and online.
36 sub get_node_info {
37 my ($self) = @_;
38
39 die "implement me";
40
41 # return { node1 => { online => 1, join_time => X }, node2 => ... }
42 }
43
44 sub log {
45 my ($self, $level, $msg) = @_;
46
47 syslog($level, $msg);
48 }
49
50 # aquire a cluster wide lock
51 sub get_ha_manager_lock {
52 my ($self) = @_;
53
54 die "implement me";
55 }
56
57 # return true when cluster is quorate
58 sub quorate {
59 my ($self) = @_;
60
61 die "implement me";
62 }
63
64 # return current time
65 # overwrite that if you want to simulate
66 sub get_time {
67 my ($self) = @_;
68
69 return time();
70 }
71
72 sub sleep {
73 my ($self, $delay) = @_;
74
75 sleep($delay);
76 }
77
78 sub loop_start_hook {
79 my ($self) = @_;
80
81 # do nothing
82 }
83
84 sub loop_end_hook {
85 my ($self) = @_;
86
87 # do nothing
88 }
89
90
91 1;