]>
Commit | Line | Data |
---|---|---|
95ca6580 DM |
1 | package PVE::HA::Env; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::SafeSyslog; | |
158bd429 | 7 | use PVE::Tools; |
95ca6580 | 8 | |
498246b9 | 9 | # abstract out the cluster environment for a single node |
95ca6580 DM |
10 | |
11 | sub 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 |
23 | sub nodename { |
24 | my ($self) = @_; | |
25 | ||
3c36cbca | 26 | return $self->{plug}->nodename(); |
7e0a7262 DM |
27 | } |
28 | ||
158bd429 DM |
29 | # manager status is stored on cluster, protected by ha_manager_lock |
30 | sub read_manager_status { | |
31 | my ($self) = @_; | |
32 | ||
3c36cbca | 33 | return $self->{plug}->read_manager_status(); |
158bd429 DM |
34 | } |
35 | ||
36 | sub write_manager_status { | |
37 | my ($self, $status_obj) = @_; | |
38 | ||
3c36cbca | 39 | return $self->{plug}->write_manager_status($status_obj); |
158bd429 DM |
40 | } |
41 | ||
c4a221bc DM |
42 | # lrm status is written by LRM, protected by ha_agent_lock, |
43 | # but can be read by any node (CRM) | |
44 | ||
45 | sub read_lrm_status { | |
46 | my ($self, $node) = @_; | |
47 | ||
48 | return $self->{plug}->read_lrm_status($node); | |
49 | } | |
50 | ||
51 | sub write_lrm_status { | |
52 | my ($self, $status_obj) = @_; | |
53 | ||
54 | return $self->{plug}->write_lrm_status($status_obj); | |
55 | } | |
56 | ||
3b996922 DM |
57 | # implement a way to send commands to the CRM master |
58 | sub queue_crm_commands { | |
59 | my ($self, $cmd) = @_; | |
60 | ||
61 | return $self->{plug}->queue_crm_commands($cmd); | |
62 | } | |
63 | ||
64 | sub read_crm_commands { | |
65 | my ($self) = @_; | |
66 | ||
67 | return $self->{plug}->read_crm_commands(); | |
68 | } | |
69 | ||
ec046210 DM |
70 | # we use this to enable/disbale ha |
71 | sub service_config_exists { | |
72 | my ($self) = @_; | |
73 | ||
74 | return $self->{plug}->service_config_exists(); | |
75 | } | |
76 | ||
f7ccd1b3 DM |
77 | sub read_service_config { |
78 | my ($self) = @_; | |
79 | ||
3c36cbca | 80 | return $self->{plug}->read_service_config(); |
f7ccd1b3 DM |
81 | } |
82 | ||
8456bde2 | 83 | sub change_service_location { |
6da27e23 | 84 | my ($self, $sid, $current_node, $new_node) = @_; |
8456bde2 | 85 | |
6da27e23 | 86 | return $self->{plug}->change_service_location($sid, $current_node, $new_node); |
8456bde2 DM |
87 | } |
88 | ||
abc920b4 DM |
89 | sub read_group_config { |
90 | my ($self) = @_; | |
91 | ||
92 | return $self->{plug}->read_group_config(); | |
93 | } | |
94 | ||
91dab9ce DM |
95 | # this should return a hash containing info |
96 | # what nodes are members and online. | |
97 | sub get_node_info { | |
98 | my ($self) = @_; | |
99 | ||
3c36cbca | 100 | return $self->{plug}->get_node_info(); |
91dab9ce DM |
101 | } |
102 | ||
95ca6580 | 103 | sub log { |
f25a336a | 104 | my ($self, $level, @args) = @_; |
95ca6580 | 105 | |
3c36cbca | 106 | return $self->{plug}->log($level, @args); |
95ca6580 DM |
107 | } |
108 | ||
3c36cbca | 109 | # aquire a cluster wide manager lock |
95ca6580 DM |
110 | sub get_ha_manager_lock { |
111 | my ($self) = @_; | |
112 | ||
3c36cbca DM |
113 | return $self->{plug}->get_ha_manager_lock(); |
114 | } | |
115 | ||
116 | # aquire a cluster wide node agent lock | |
117 | sub get_ha_agent_lock { | |
3c36cbca DM |
118 | my ($self, $node) = @_; |
119 | ||
f5c29173 | 120 | return $self->{plug}->get_ha_agent_lock($node); |
95ca6580 DM |
121 | } |
122 | ||
0d00a7da DM |
123 | # return true when cluster is quorate |
124 | sub quorate { | |
125 | my ($self) = @_; | |
126 | ||
3c36cbca | 127 | return $self->{plug}->quorate(); |
0d00a7da DM |
128 | } |
129 | ||
95ca6580 DM |
130 | # return current time |
131 | # overwrite that if you want to simulate | |
132 | sub get_time { | |
133 | my ($self) = @_; | |
134 | ||
3c36cbca | 135 | return $self->{plug}->get_time(); |
95ca6580 DM |
136 | } |
137 | ||
138 | sub sleep { | |
139 | my ($self, $delay) = @_; | |
140 | ||
3c36cbca | 141 | return $self->{plug}->sleep($delay); |
95ca6580 DM |
142 | } |
143 | ||
f25a336a DM |
144 | sub sleep_until { |
145 | my ($self, $end_time) = @_; | |
146 | ||
3c36cbca | 147 | return $self->{plug}->sleep_until($end_time); |
f25a336a DM |
148 | } |
149 | ||
95ca6580 | 150 | sub loop_start_hook { |
3c36cbca | 151 | my ($self, @args) = @_; |
95ca6580 | 152 | |
3c36cbca | 153 | return $self->{plug}->loop_start_hook(@args); |
95ca6580 DM |
154 | } |
155 | ||
156 | sub loop_end_hook { | |
3c36cbca DM |
157 | my ($self, @args) = @_; |
158 | ||
159 | return $self->{plug}->loop_end_hook(@args); | |
95ca6580 DM |
160 | } |
161 | ||
9329c1e2 DM |
162 | sub watchdog_open { |
163 | my ($self) = @_; | |
164 | ||
b6044542 DM |
165 | # Note: when using /dev/watchdog, make sure perl does not close |
166 | # the handle automatically at exit!! | |
167 | ||
9329c1e2 DM |
168 | return $self->{plug}->watchdog_open(); |
169 | } | |
170 | ||
171 | sub watchdog_update { | |
172 | my ($self, $wfh) = @_; | |
173 | ||
174 | return $self->{plug}->watchdog_update($wfh); | |
175 | } | |
176 | ||
177 | sub watchdog_close { | |
178 | my ($self, $wfh) = @_; | |
179 | ||
180 | return $self->{plug}->watchdog_close($wfh); | |
181 | } | |
182 | ||
c4a221bc | 183 | sub exec_resource_agent { |
6dbf93a0 | 184 | my ($self, $sid, $service_config, $cmd, @params) = @_; |
c4a221bc | 185 | |
6dbf93a0 | 186 | return $self->{plug}->exec_resource_agent($sid, $service_config, $cmd, @params) |
c4a221bc DM |
187 | } |
188 | ||
0d1d32fb DM |
189 | # hack to support regression tests |
190 | sub can_fork { | |
191 | my ($self) = @_; | |
192 | ||
193 | return $self->{plug}->can_fork(); | |
194 | } | |
195 | ||
95ca6580 | 196 | 1; |