]> git.proxmox.com Git - pve-ha-manager.git/blob - PVE/HA/Env.pm
implement read/write manager status
[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 use PVE::Tools;
8
9 # abstract out the cluster environment
10
11 sub new {
12 my ($this, $statusdir, $nodename) = @_;
13
14 my $class = ref($this) || $this;
15
16 my $self = bless {
17 statusdir => $statusdir,
18 nodename => $nodename,
19 }, $class;
20
21 return $self;
22 }
23
24 sub nodename {
25 my ($self) = @_;
26
27 return $self->{nodename};
28 }
29
30 sub read_local_status {
31 my ($self) = @_;
32
33 return PVE::Tools::file_read_firstline("$self->{statusdir}/local_status");
34 }
35
36 sub write_local_status {
37 my ($self, $status) = @_;
38
39 PVE::Tools::file_set_contents("$self->{statusdir}/local_status", $status);
40 }
41
42 # manager status is stored on cluster, protected by ha_manager_lock
43 sub read_manager_status {
44 my ($self) = @_;
45
46 die "implement me";
47
48 return {};
49 }
50
51 sub write_manager_status {
52 my ($self, $status_obj) = @_;
53
54 die "implement me";
55 }
56
57 # we use this to enable/disbale ha
58 sub manager_status_exists {
59 my ($self) = @_;
60
61 die "implement me";
62
63 return {};
64 }
65
66 # this should return a hash containing info
67 # what nodes are members and online.
68 sub get_node_info {
69 my ($self) = @_;
70
71 die "implement me";
72
73 # return { node1 => { online => 1, join_time => X }, node2 => ... }
74 }
75
76 sub log {
77 my ($self, $level, $msg) = @_;
78
79 syslog($level, $msg);
80 }
81
82 # aquire a cluster wide lock
83 sub get_ha_manager_lock {
84 my ($self) = @_;
85
86 die "implement me";
87 }
88
89 # return true when cluster is quorate
90 sub quorate {
91 my ($self) = @_;
92
93 die "implement me";
94 }
95
96 # return current time
97 # overwrite that if you want to simulate
98 sub get_time {
99 my ($self) = @_;
100
101 return time();
102 }
103
104 sub sleep {
105 my ($self, $delay) = @_;
106
107 sleep($delay);
108 }
109
110 sub loop_start_hook {
111 my ($self) = @_;
112
113 # do nothing
114 }
115
116 sub loop_end_hook {
117 my ($self) = @_;
118
119 # do nothing
120 }
121
122
123 1;