]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Resources.pm
1 package PVE
::HA
::Resources
;
7 use PVE
::JSONSchema
qw(get_standard_option);
8 use PVE
::SectionConfig
;
11 use base
qw(PVE::SectionConfig);
15 type
=> { description
=> "Resource type.", optional
=> 1 },
16 sid
=> get_standard_option
('pve-ha-resource-or-vm-id',
17 { completion
=> \
&PVE
::HA
::Tools
::complete_sid
}),
19 description
=> "Resource state.",
21 enum
=> ['enabled', 'disabled'],
25 group
=> get_standard_option
('pve-ha-group-id',
27 completion
=> \
&PVE
::HA
::Tools
::complete_group
}),
29 description
=> "Maximal number of tries to restart the service on".
30 " a node after its start failed.",
37 description
=> "Maximal number of service relocate tries when a".
38 " service failes to start.",
45 description
=> "Description.",
54 my ($class, $name) = @_;
56 die "implement this in subclass";
63 sub format_section_header
{
64 my ($class, $type, $sectionId) = @_;
66 my (undef, $name) = split(':', $sectionId, 2);
68 return "$type: $name\n";
71 sub parse_section_header
{
72 my ($class, $line) = @_;
74 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
75 my ($type, $name) = (lc($1), $2);
76 my $errmsg = undef; # set if you want to skip whole section
78 if (my $plugin = $defaultData->{plugins
}->{$type}) {
79 $plugin->verify_name($name);
81 die "no such resource type '$type'\n";
85 my $config = {}; # to return additional attributes
86 return ($type, "$type:$name", $errmsg, $config);
92 my ($class, $haenv, $id) = @_;
94 die "implement in subclass";
98 my ($class, $haenv, $id) = @_;
100 die "implement in subclass";
104 my ($class, $haenv, $id, $target, $online) = @_;
106 die "implement in subclass";
110 my ($class, $id, $nodename) = @_;
112 die "implement in subclass"
116 my ($class, $id, $noerr) = @_;
118 die "implement in subclass"
122 my ($class, $id) = @_;
124 die "implement in subclass";
128 # virtual machine resource class
129 package PVE
::HA
::Resources
::PVEVM
;
137 use base
qw(PVE::HA::Resources);
144 my ($class, $name) = @_;
146 die "invalid VMID\n" if $name !~ m/^[1-9][0-9]+$/;
151 state => { optional
=> 1 },
152 group
=> { optional
=> 1 },
153 comment
=> { optional
=> 1 },
154 max_restart
=> { optional
=> 1 },
155 max_relocate
=> { optional
=> 1 },
160 my ($class, $vmid, $nodename) = @_;
162 return PVE
::QemuServer
::config_file
($vmid, $nodename);
166 my ($class, $vmid, $noerr) = @_;
168 my $vmlist = PVE
::Cluster
::get_vmlist
();
170 if(!defined($vmlist->{ids
}->{$vmid})) {
171 die "resource 'vm:$vmid' does not exists in cluster\n" if !$noerr;
179 my ($class, $haenv, $id) = @_;
181 my $nodename = $haenv->nodename();
188 my $upid = PVE
::API2
::Qemu-
>vm_start($params);
189 $haenv->upid_wait($upid);
193 my ($class, $haenv, $id) = @_;
195 my $nodename = $haenv->nodename();
196 my $shutdown_timeout = 60; # fixme: make this configurable
201 timeout
=> $shutdown_timeout,
205 my $upid = PVE
::API2
::Qemu-
>vm_shutdown($params);
206 $haenv->upid_wait($upid);
211 my ($class, $haenv, $id, $target, $online) = @_;
213 my $nodename = $haenv->nodename();
222 # explicitly shutdown if $online isn't true (relocate)
223 if (!$online && $class->check_running($id)) {
224 $class->shutdown($haenv, $id);
227 my $upid = PVE
::API2
::Qemu-
>migrate_vm($params);
228 $haenv->upid_wait($upid);
232 my ($class, $vmid) = @_;
234 return PVE
::QemuServer
::check_running
($vmid, 1);
238 # container resource class
239 package PVE
::HA
::Resources
::PVECT
;
246 use PVE
::API2
::LXC
::Status
;
248 use base
qw(PVE::HA::Resources);
255 my ($class, $name) = @_;
257 die "invalid VMID\n" if $name !~ m/^[1-9][0-9]+$/;
262 state => { optional
=> 1 },
263 group
=> { optional
=> 1 },
264 comment
=> { optional
=> 1 },
265 max_restart
=> { optional
=> 1 },
266 max_relocate
=> { optional
=> 1 },
271 my ($class, $vmid, $nodename) = @_;
273 return PVE
::LXC
::config_file
($vmid, $nodename);
277 my ($class, $vmid, $noerr) = @_;
279 my $vmlist = PVE
::Cluster
::get_vmlist
();
281 if(!defined($vmlist->{ids
}->{$vmid})) {
282 die "resource 'ct:$vmid' does not exists in cluster\n" if !$noerr;
290 my ($class, $haenv, $id) = @_;
292 my $nodename = $haenv->nodename();
299 my $upid = PVE
::API2
::LXC
::Status-
>vm_start($params);
300 $haenv->upid_wait($upid);
304 my ($class, $haenv, $id) = @_;
306 my $nodename = $haenv->nodename();
307 my $shutdown_timeout = 60; # fixme: make this configurable
312 timeout
=> $shutdown_timeout,
316 my $upid = PVE
::API2
::LXC
::Status-
>vm_shutdown($params);
317 $haenv->upid_wait($upid);
321 my ($class, $haenv, $id, $target, $online) = @_;
323 my $nodename = $haenv->nodename();
329 online
=> 0, # we cannot migrate CT (yet) online, only relocate
332 # always relocate container for now
333 if ($class->check_running($id)) {
334 $class->shutdown($haenv, $id);
337 my $upid = PVE
::API2
::LXC-
>migrate_vm($params);
338 $haenv->upid_wait($upid);
342 my ($class, $vmid) = @_;
344 return PVE
::LXC
::check_running
($vmid);
348 # package PVE::HA::Resources::IPAddr;
352 # use PVE::Tools qw($IPV4RE $IPV6RE);
354 # use base qw(PVE::HA::Resources);
361 # my ($class, $name) = @_;
363 # die "invalid IP address\n" if $name !~ m!^$IPV6RE|$IPV4RE$!;
368 # state => { optional => 1 },
369 # group => { optional => 1 },
370 # comment => { optional => 1 },