]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Env.pm
Move exec_resource_agent from environment classes to LRM
[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 service_config_exists {
85 my ($self) = @_;
86
87 return $self->{plug}->service_config_exists();
88 }
89
90 sub read_service_config {
91 my ($self) = @_;
92
93 return $self->{plug}->read_service_config();
94 }
95
96 sub change_service_location {
97 my ($self, $sid, $current_node, $new_node) = @_;
98
99 return $self->{plug}->change_service_location($sid, $current_node, $new_node);
100 }
101
102 sub read_group_config {
103 my ($self) = @_;
104
105 return $self->{plug}->read_group_config();
106 }
107
108 # this should return a hash containing info
109 # what nodes are members and online.
110 sub get_node_info {
111 my ($self) = @_;
112
113 return $self->{plug}->get_node_info();
114 }
115
116 sub log {
117 my ($self, $level, @args) = @_;
118
119 return $self->{plug}->log($level, @args);
120 }
121
122 # acquire a cluster wide manager lock
123 sub get_ha_manager_lock {
124 my ($self) = @_;
125
126 return $self->{plug}->get_ha_manager_lock();
127 }
128
129 # release the cluster wide manager lock.
130 # when released another CRM may step up and get the lock, thus this should only
131 # get called when shutting down/deactivating the current master
132 sub release_ha_manager_lock {
133 my ($self) = @_;
134
135 return $self->{plug}->release_ha_manager_lock();
136 }
137
138 # acquire a cluster wide node agent lock
139 sub get_ha_agent_lock {
140 my ($self, $node) = @_;
141
142 return $self->{plug}->get_ha_agent_lock($node);
143 }
144
145 # release the respective node agent lock.
146 # this should only get called if the nodes LRM gracefully shuts down with
147 # all services already cleanly stopped!
148 sub release_ha_agent_lock {
149 my ($self) = @_;
150
151 return $self->{plug}->release_ha_agent_lock();
152 }
153
154 # return true when cluster is quorate
155 sub quorate {
156 my ($self) = @_;
157
158 return $self->{plug}->quorate();
159 }
160
161 # return current time
162 # overwrite that if you want to simulate
163 sub get_time {
164 my ($self) = @_;
165
166 return $self->{plug}->get_time();
167 }
168
169 sub sleep {
170 my ($self, $delay) = @_;
171
172 return $self->{plug}->sleep($delay);
173 }
174
175 sub sleep_until {
176 my ($self, $end_time) = @_;
177
178 return $self->{plug}->sleep_until($end_time);
179 }
180
181 sub loop_start_hook {
182 my ($self, @args) = @_;
183
184 return $self->{plug}->loop_start_hook(@args);
185 }
186
187 sub loop_end_hook {
188 my ($self, @args) = @_;
189
190 return $self->{plug}->loop_end_hook(@args);
191 }
192
193 sub watchdog_open {
194 my ($self) = @_;
195
196 # Note: when using /dev/watchdog, make sure perl does not close
197 # the handle automatically at exit!!
198
199 return $self->{plug}->watchdog_open();
200 }
201
202 sub watchdog_update {
203 my ($self, $wfh) = @_;
204
205 return $self->{plug}->watchdog_update($wfh);
206 }
207
208 sub watchdog_close {
209 my ($self, $wfh) = @_;
210
211 return $self->{plug}->watchdog_close($wfh);
212 }
213
214 # hack to support regression tests
215 sub can_fork {
216 my ($self) = @_;
217
218 return $self->{plug}->can_fork();
219 }
220
221 1;