]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Env.pm
implement change_service_location
[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 # manager status is stored on cluster, protected by ha_manager_lock
30 sub read_manager_status {
31 my ($self) = @_;
32
33 return $self->{plug}->read_manager_status();
34 }
35
36 sub write_manager_status {
37 my ($self, $status_obj) = @_;
38
39 return $self->{plug}->write_manager_status($status_obj);
40 }
41
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
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
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
77 sub read_service_config {
78 my ($self) = @_;
79
80 return $self->{plug}->read_service_config();
81 }
82
83 sub change_service_location {
84 my ($self, $sid, $current_node, $new_node) = @_;
85
86 return $self->{plug}->change_service_location($sid, $current_node, $new_node);
87 }
88
89 sub read_group_config {
90 my ($self) = @_;
91
92 return $self->{plug}->read_group_config();
93 }
94
95 # this should return a hash containing info
96 # what nodes are members and online.
97 sub get_node_info {
98 my ($self) = @_;
99
100 return $self->{plug}->get_node_info();
101 }
102
103 sub log {
104 my ($self, $level, @args) = @_;
105
106 return $self->{plug}->log($level, @args);
107 }
108
109 # aquire a cluster wide manager lock
110 sub get_ha_manager_lock {
111 my ($self) = @_;
112
113 return $self->{plug}->get_ha_manager_lock();
114 }
115
116 # aquire a cluster wide node agent lock
117 sub get_ha_agent_lock {
118 my ($self, $node) = @_;
119
120 return $self->{plug}->get_ha_agent_lock($node);
121 }
122
123 # return true when cluster is quorate
124 sub quorate {
125 my ($self) = @_;
126
127 return $self->{plug}->quorate();
128 }
129
130 # return current time
131 # overwrite that if you want to simulate
132 sub get_time {
133 my ($self) = @_;
134
135 return $self->{plug}->get_time();
136 }
137
138 sub sleep {
139 my ($self, $delay) = @_;
140
141 return $self->{plug}->sleep($delay);
142 }
143
144 sub sleep_until {
145 my ($self, $end_time) = @_;
146
147 return $self->{plug}->sleep_until($end_time);
148 }
149
150 sub loop_start_hook {
151 my ($self, @args) = @_;
152
153 return $self->{plug}->loop_start_hook(@args);
154 }
155
156 sub loop_end_hook {
157 my ($self, @args) = @_;
158
159 return $self->{plug}->loop_end_hook(@args);
160 }
161
162 sub watchdog_open {
163 my ($self) = @_;
164
165 # Note: when using /dev/watchdog, make sure perl does not close
166 # the handle automatically at exit!!
167
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
183 sub exec_resource_agent {
184 my ($self, $sid, $service_config, $cmd, @params) = @_;
185
186 return $self->{plug}->exec_resource_agent($sid, $service_config, $cmd, @params)
187 }
188
189 # hack to support regression tests
190 sub can_fork {
191 my ($self) = @_;
192
193 return $self->{plug}->can_fork();
194 }
195
196 1;