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