]> git.proxmox.com Git - pve-ha-manager.git/blame - src/PVE/HA/Env.pm
Tools/Config: refactor lrm status json reading
[pve-ha-manager.git] / src / PVE / HA / Env.pm
CommitLineData
95ca6580
DM
1package PVE::HA::Env;
2
3use strict;
4use warnings;
5
6use PVE::SafeSyslog;
158bd429 7use PVE::Tools;
95ca6580 8
498246b9 9# abstract out the cluster environment for a single node
95ca6580
DM
10
11sub new {
3c36cbca 12 my ($this, $baseclass, $node, @args) = @_;
95ca6580
DM
13
14 my $class = ref($this) || $this;
15
3c36cbca
DM
16 my $plug = $baseclass->new($node, @args);
17
18 my $self = bless { plug => $plug }, $class;
95ca6580
DM
19
20 return $self;
21}
22
7e0a7262
DM
23sub nodename {
24 my ($self) = @_;
25
3c36cbca 26 return $self->{plug}->nodename();
7e0a7262
DM
27}
28
dd9c0c9d
TL
29sub hardware {
30 my ($self) = @_;
31
32 return $self->{plug}->hardware();
33}
34
158bd429
DM
35# manager status is stored on cluster, protected by ha_manager_lock
36sub read_manager_status {
37 my ($self) = @_;
38
3c36cbca 39 return $self->{plug}->read_manager_status();
158bd429
DM
40}
41
42sub write_manager_status {
43 my ($self, $status_obj) = @_;
44
3c36cbca 45 return $self->{plug}->write_manager_status($status_obj);
158bd429
DM
46}
47
c4a221bc
DM
48# lrm status is written by LRM, protected by ha_agent_lock,
49# but can be read by any node (CRM)
50
51sub read_lrm_status {
52 my ($self, $node) = @_;
53
54 return $self->{plug}->read_lrm_status($node);
55}
56
57sub write_lrm_status {
58 my ($self, $status_obj) = @_;
59
60 return $self->{plug}->write_lrm_status($status_obj);
61}
62
cde77779
DM
63# check if we do node shutdown
64# we used this to decide if services should be stopped or freezed
65sub is_node_shutdown {
d42219a3
TL
66 my ($self) = @_;
67
cde77779 68 return $self->{plug}->is_node_shutdown();
d42219a3
TL
69}
70
3b996922
DM
71# implement a way to send commands to the CRM master
72sub queue_crm_commands {
73 my ($self, $cmd) = @_;
74
75 return $self->{plug}->queue_crm_commands($cmd);
76}
77
78sub read_crm_commands {
79 my ($self) = @_;
80
81 return $self->{plug}->read_crm_commands();
82}
83
f7ccd1b3
DM
84sub read_service_config {
85 my ($self) = @_;
86
3c36cbca 87 return $self->{plug}->read_service_config();
f7ccd1b3
DM
88}
89
c982dfee
TL
90sub read_fence_config {
91 my ($self) = @_;
92
93 return $self->{plug}->read_fence_config();
94}
95
96sub fencing_mode {
97 my ($self) = @_;
98
99 return $self->{plug}->fencing_mode();
100}
101
102sub exec_fence_agent {
103 my ($self, $agent, $node, @param) = @_;
104
105 return $self->{plug}->exec_fence_agent($agent, $node, @param);
106}
107
9da84a0d
TL
108# this is normally only allowed by the master to recover a _fenced_ service
109sub steal_service {
6da27e23 110 my ($self, $sid, $current_node, $new_node) = @_;
8456bde2 111
9da84a0d 112 return $self->{plug}->steal_service($sid, $current_node, $new_node);
8456bde2
DM
113}
114
abc920b4
DM
115sub read_group_config {
116 my ($self) = @_;
117
118 return $self->{plug}->read_group_config();
119}
120
91dab9ce
DM
121# this should return a hash containing info
122# what nodes are members and online.
123sub get_node_info {
124 my ($self) = @_;
125
3c36cbca 126 return $self->{plug}->get_node_info();
91dab9ce
DM
127}
128
95ca6580 129sub log {
f25a336a 130 my ($self, $level, @args) = @_;
95ca6580 131
3c36cbca 132 return $self->{plug}->log($level, @args);
95ca6580
DM
133}
134
1b3969b6
TL
135sub sendmail {
136 my ($self, $subject, $text) = @_;
137
138 return $self->{plug}->sendmail($subject, $text);
139}
140
63f6a08c 141# acquire a cluster wide manager lock
95ca6580
DM
142sub get_ha_manager_lock {
143 my ($self) = @_;
144
3c36cbca
DM
145 return $self->{plug}->get_ha_manager_lock();
146}
147
de002253
TL
148# release the cluster wide manager lock.
149# when released another CRM may step up and get the lock, thus this should only
150# get called when shutting down/deactivating the current master
151sub release_ha_manager_lock {
152 my ($self) = @_;
153
154 return $self->{plug}->release_ha_manager_lock();
155}
156
63f6a08c 157# acquire a cluster wide node agent lock
3c36cbca 158sub get_ha_agent_lock {
3c36cbca
DM
159 my ($self, $node) = @_;
160
f5c29173 161 return $self->{plug}->get_ha_agent_lock($node);
95ca6580
DM
162}
163
ff165cd8
TL
164# release the respective node agent lock.
165# this should only get called if the nodes LRM gracefully shuts down with
166# all services already cleanly stopped!
167sub release_ha_agent_lock {
168 my ($self) = @_;
169
170 return $self->{plug}->release_ha_agent_lock();
171}
172
0d00a7da
DM
173# return true when cluster is quorate
174sub quorate {
175 my ($self) = @_;
176
3c36cbca 177 return $self->{plug}->quorate();
0d00a7da
DM
178}
179
95ca6580
DM
180# return current time
181# overwrite that if you want to simulate
182sub get_time {
183 my ($self) = @_;
184
3c36cbca 185 return $self->{plug}->get_time();
95ca6580
DM
186}
187
188sub sleep {
189 my ($self, $delay) = @_;
190
3c36cbca 191 return $self->{plug}->sleep($delay);
95ca6580
DM
192}
193
f25a336a
DM
194sub sleep_until {
195 my ($self, $end_time) = @_;
196
3c36cbca 197 return $self->{plug}->sleep_until($end_time);
f25a336a
DM
198}
199
95ca6580 200sub loop_start_hook {
3c36cbca 201 my ($self, @args) = @_;
95ca6580 202
3c36cbca 203 return $self->{plug}->loop_start_hook(@args);
95ca6580
DM
204}
205
206sub loop_end_hook {
3c36cbca
DM
207 my ($self, @args) = @_;
208
209 return $self->{plug}->loop_end_hook(@args);
95ca6580
DM
210}
211
3df15380
TL
212sub cluster_state_update {
213 my ($self) = @_;
214
215 return $self->{plug}->cluster_state_update();
216}
217
9329c1e2
DM
218sub watchdog_open {
219 my ($self) = @_;
220
b6044542
DM
221 # Note: when using /dev/watchdog, make sure perl does not close
222 # the handle automatically at exit!!
223
9329c1e2
DM
224 return $self->{plug}->watchdog_open();
225}
226
227sub watchdog_update {
228 my ($self, $wfh) = @_;
229
230 return $self->{plug}->watchdog_update($wfh);
231}
232
233sub watchdog_close {
234 my ($self, $wfh) = @_;
235
236 return $self->{plug}->watchdog_close($wfh);
237}
238
a28fa330 239sub after_fork {
0d1d32fb
DM
240 my ($self) = @_;
241
a28fa330 242 return $self->{plug}->after_fork();
0d1d32fb
DM
243}
244
a28fa330
TL
245# maximal number of workers to fork,
246# return 0 as a hack to support regression tests
247sub get_max_workers {
a2aae08a
TL
248 my ($self) = @_;
249
a28fa330 250 return $self->{plug}->get_max_workers();
a2aae08a
TL
251}
252
95ca6580 2531;