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