]>
Commit | Line | Data |
---|---|---|
a223f4cc DM |
1 | package PVE::HA::Resources; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
a223f4cc DM |
6 | use PVE::JSONSchema qw(get_standard_option); |
7 | use PVE::SectionConfig; | |
8 | use PVE::HA::Tools; | |
9 | ||
10 | use base qw(PVE::SectionConfig); | |
11 | ||
12 | my $defaultData = { | |
13 | propertyList => { | |
95ea5d67 | 14 | type => { description => "Resource type.", optional => 1 }, |
73bede9b | 15 | sid => get_standard_option('pve-ha-resource-or-vm-id', |
bf119a50 | 16 | { completion => \&PVE::HA::Tools::complete_sid }), |
7a19642e | 17 | state => { |
7a19642e | 18 | type => 'string', |
667670b2 | 19 | enum => ['started', 'stopped', 'enabled', 'disabled', 'ignored'], |
7a19642e | 20 | optional => 1, |
bb07bd2c | 21 | default => 'started', |
6d1e4974 DM |
22 | description => "Requested resource state.", |
23 | verbose_description => <<EODESC, | |
cb6741fb DM |
24 | Requested resource state. The CRM reads this state and acts accordingly. |
25 | Please note that `enabled` is just an alias for `started`. | |
26 | ||
27 | `started`;; | |
28 | ||
29 | The CRM tries to start the resource. Service state is | |
30 | set to `started` after successful start. On node failures, or when start | |
31 | fails, it tries to recover the resource. If everything fails, service | |
32 | state it set to `error`. | |
33 | ||
34 | `stopped`;; | |
35 | ||
36 | The CRM tries to keep the resource in `stopped` state, but it | |
37 | still tries to relocate the resources on node failures. | |
38 | ||
39 | `disabled`;; | |
40 | ||
41 | The CRM tries to put the resource in `stopped` state, but does not try | |
42 | to relocate the resources on node failures. The main purpose of this | |
43 | state is error recovery, because it is the only way to move a resource out | |
44 | of the `error` state. | |
45 | ||
667670b2 TL |
46 | `ignored`;; |
47 | ||
48 | The resource gets removed from the manager status and so the CRM and the LRM do | |
49 | not touch the resource anymore. All {pve} API calls affecting this resource | |
50 | will be executed, directly bypassing the HA stack. CRM commands will be thrown | |
51 | away while there source is in this state. The resource will not get relocated | |
52 | on node failures. | |
53 | ||
cb6741fb | 54 | EODESC |
7a19642e | 55 | }, |
73bede9b TL |
56 | group => get_standard_option('pve-ha-group-id', |
57 | { optional => 1, | |
58 | completion => \&PVE::HA::Tools::complete_group }), | |
ea4443cc TL |
59 | max_restart => { |
60 | description => "Maximal number of tries to restart the service on". | |
61 | " a node after its start failed.", | |
62 | type => 'integer', | |
63 | optional => 1, | |
64 | default => 1, | |
65 | minimum => 0, | |
66 | }, | |
67 | max_relocate => { | |
68 | description => "Maximal number of service relocate tries when a". | |
69 | " service failes to start.", | |
70 | type => 'integer', | |
71 | optional => 1, | |
72 | default => 1, | |
73 | minimum => 0, | |
74 | }, | |
a223f4cc DM |
75 | comment => { |
76 | description => "Description.", | |
77 | type => 'string', | |
78 | optional => 1, | |
79 | maxLength => 4096, | |
80 | }, | |
81 | }, | |
82 | }; | |
83 | ||
84 | sub verify_name { | |
85 | my ($class, $name) = @_; | |
86 | ||
87 | die "implement this in subclass"; | |
88 | } | |
89 | ||
90 | sub private { | |
91 | return $defaultData; | |
92 | } | |
93 | ||
95ea5d67 DM |
94 | sub format_section_header { |
95 | my ($class, $type, $sectionId) = @_; | |
96 | ||
97 | my (undef, $name) = split(':', $sectionId, 2); | |
289e4784 | 98 | |
95ea5d67 DM |
99 | return "$type: $name\n"; |
100 | } | |
101 | ||
a223f4cc DM |
102 | sub parse_section_header { |
103 | my ($class, $line) = @_; | |
104 | ||
105 | if ($line =~ m/^(\S+):\s*(\S+)\s*$/) { | |
106 | my ($type, $name) = (lc($1), $2); | |
107 | my $errmsg = undef; # set if you want to skip whole section | |
108 | eval { | |
109 | if (my $plugin = $defaultData->{plugins}->{$type}) { | |
110 | $plugin->verify_name($name); | |
85d36c36 DM |
111 | } else { |
112 | die "no such resource type '$type'\n"; | |
a223f4cc | 113 | } |
a223f4cc DM |
114 | }; |
115 | $errmsg = $@ if $@; | |
95ea5d67 | 116 | my $config = {}; # to return additional attributes |
a223f4cc DM |
117 | return ($type, "$type:$name", $errmsg, $config); |
118 | } | |
119 | return undef; | |
120 | } | |
121 | ||
3d60e54f | 122 | sub start { |
b865e4cb | 123 | my ($class, $haenv, $id) = @_; |
92bd23c6 | 124 | |
3d60e54f TL |
125 | die "implement in subclass"; |
126 | } | |
127 | ||
128 | sub shutdown { | |
e4ef317d | 129 | my ($class, $haenv, $id, $timeout) = @_; |
92bd23c6 | 130 | |
3d60e54f TL |
131 | die "implement in subclass"; |
132 | } | |
133 | ||
134 | sub migrate { | |
b865e4cb | 135 | my ($class, $haenv, $id, $target, $online) = @_; |
92bd23c6 | 136 | |
3d60e54f TL |
137 | die "implement in subclass"; |
138 | } | |
139 | ||
140 | sub config_file { | |
92bd23c6 TL |
141 | my ($class, $id, $nodename) = @_; |
142 | ||
3d60e54f TL |
143 | die "implement in subclass" |
144 | } | |
145 | ||
f06755de TL |
146 | sub exists { |
147 | my ($class, $id, $noerr) = @_; | |
148 | ||
149 | die "implement in subclass" | |
150 | } | |
151 | ||
3d60e54f | 152 | sub check_running { |
0d5906f3 | 153 | my ($class, $haenv, $id) = @_; |
92bd23c6 | 154 | |
3d60e54f TL |
155 | die "implement in subclass"; |
156 | } | |
157 | ||
5dd3ed86 TL |
158 | sub remove_locks { |
159 | my ($self, $haenv, $id, $locks, $service_node) = @_; | |
160 | ||
161 | die "implement in subclass"; | |
162 | } | |
163 | ||
3d60e54f | 164 | |
85d36c36 | 165 | # package PVE::HA::Resources::IPAddr; |
a223f4cc | 166 | |
85d36c36 DM |
167 | # use strict; |
168 | # use warnings; | |
169 | # use PVE::Tools qw($IPV4RE $IPV6RE); | |
a223f4cc | 170 | |
85d36c36 | 171 | # use base qw(PVE::HA::Resources); |
a223f4cc | 172 | |
85d36c36 DM |
173 | # sub type { |
174 | # return 'ipaddr'; | |
175 | # } | |
a223f4cc | 176 | |
85d36c36 DM |
177 | # sub verify_name { |
178 | # my ($class, $name) = @_; | |
a223f4cc | 179 | |
85d36c36 DM |
180 | # die "invalid IP address\n" if $name !~ m!^$IPV6RE|$IPV4RE$!; |
181 | # } | |
a223f4cc | 182 | |
85d36c36 DM |
183 | # sub options { |
184 | # return { | |
185 | # state => { optional => 1 }, | |
186 | # group => { optional => 1 }, | |
187 | # comment => { optional => 1 }, | |
188 | # }; | |
189 | # } | |
a223f4cc DM |
190 | |
191 | 1; |