]> git.proxmox.com Git - pve-ha-manager.git/blob - PVE/HA/Env.pm
cleanup CRM state machine
[pve-ha-manager.git] / 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 # we use this to enable/disbale ha
43 sub manager_status_exists {
44 my ($self) = @_;
45
46 return $self->{plug}->manager_status_exists();
47 }
48
49 sub read_service_config {
50 my ($self) = @_;
51
52 return $self->{plug}->read_service_config();
53 }
54
55 # this should return a hash containing info
56 # what nodes are members and online.
57 sub get_node_info {
58 my ($self) = @_;
59
60 return $self->{plug}->get_node_info();
61 }
62
63 sub log {
64 my ($self, $level, @args) = @_;
65
66 return $self->{plug}->log($level, @args);
67 }
68
69 # aquire a cluster wide manager lock
70 sub get_ha_manager_lock {
71 my ($self) = @_;
72
73 return $self->{plug}->get_ha_manager_lock();
74 }
75
76 # aquire a cluster wide node agent lock
77 sub get_ha_agent_lock {
78 my ($self) = @_;
79
80 return $self->{plug}->get_ha_agent_lock();
81 }
82
83 sub test_ha_agent_lock {
84 my ($self, $node) = @_;
85
86 return $self->{plug}->test_ha_agent_lock($node);
87 }
88
89 # return true when cluster is quorate
90 sub quorate {
91 my ($self) = @_;
92
93 return $self->{plug}->quorate();
94 }
95
96 # return current time
97 # overwrite that if you want to simulate
98 sub get_time {
99 my ($self) = @_;
100
101 return $self->{plug}->get_time();
102 }
103
104 sub sleep {
105 my ($self, $delay) = @_;
106
107 return $self->{plug}->sleep($delay);
108 }
109
110 sub sleep_until {
111 my ($self, $end_time) = @_;
112
113 return $self->{plug}->sleep_until($end_time);
114 }
115
116 sub loop_start_hook {
117 my ($self, @args) = @_;
118
119 return $self->{plug}->loop_start_hook(@args);
120 }
121
122 sub loop_end_hook {
123 my ($self, @args) = @_;
124
125 return $self->{plug}->loop_end_hook(@args);
126 }
127
128 sub watchdog_open {
129 my ($self) = @_;
130
131 # Note: when using /dev/watchdog, make sure perl does not close
132 # the handle automatically at exit!!
133
134 return $self->{plug}->watchdog_open();
135 }
136
137 sub watchdog_update {
138 my ($self, $wfh) = @_;
139
140 return $self->{plug}->watchdog_update($wfh);
141 }
142
143 sub watchdog_close {
144 my ($self, $wfh) = @_;
145
146 return $self->{plug}->watchdog_close($wfh);
147 }
148
149 1;