]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Resources/PVEVM.pm
1 package PVE
::HA
::Resources
::PVEVM
;
9 if (!$ENV{PVE_GENERATING_DOCS
}) {
10 require PVE
::QemuConfig
;
11 import PVE
::QemuConfig
;
12 require PVE
::QemuServer
;
13 import PVE
::QemuServer
;
14 require PVE
::API2
::Qemu
;
15 import PVE
::API2
::Qemu
;
19 use base
qw(PVE::HA::Resources);
26 my ($class, $name) = @_;
28 die "invalid VMID\n" if $name !~ m/^[1-9][0-9]+$/;
33 state => { optional
=> 1 },
34 group
=> { optional
=> 1 },
35 comment
=> { optional
=> 1 },
36 max_restart
=> { optional
=> 1 },
37 max_relocate
=> { optional
=> 1 },
42 my ($class, $vmid, $nodename) = @_;
44 return PVE
::QemuConfig-
>config_file($vmid, $nodename);
48 my ($class, $vmid, $noerr) = @_;
50 my $vmlist = PVE
::Cluster
::get_vmlist
();
52 if(!defined($vmlist->{ids
}->{$vmid})) {
53 die "resource 'vm:$vmid' does not exists in cluster\n" if !$noerr;
61 my ($class, $haenv, $id) = @_;
63 my $nodename = $haenv->nodename();
70 my $upid = PVE
::API2
::Qemu-
>vm_start($params);
71 PVE
::HA
::Tools
::upid_wait
($upid, $haenv);
75 my ($class, $haenv, $id) = @_;
77 my $nodename = $haenv->nodename();
78 my $shutdown_timeout = 60; # fixme: make this configurable
83 timeout
=> $shutdown_timeout,
87 my $upid = PVE
::API2
::Qemu-
>vm_shutdown($params);
88 PVE
::HA
::Tools
::upid_wait
($upid, $haenv);
92 my ($class, $haenv, $id, $target, $online) = @_;
94 my $nodename = $haenv->nodename();
99 # bug #2241 forces is for local resource only, people can ensure that
100 # different host have the same hardware, so this can be fine, and qemu
101 # knows when not, so can only win here
107 # explicitly shutdown if $online isn't true (relocate)
108 if (!$online && $class->check_running($haenv, $id)) {
109 $class->shutdown($haenv, $id);
112 my $oldconfig = $class->config_file($id, $nodename);
114 my $upid = PVE
::API2
::Qemu-
>migrate_vm($params);
115 PVE
::HA
::Tools
::upid_wait
($upid, $haenv);
117 # check if vm really moved
118 return !(-f
$oldconfig);
122 my ($class, $haenv, $vmid) = @_;
124 my $nodename = $haenv->nodename();
126 if (PVE
::QemuServer
::check_running
($vmid, 1, $nodename)) {
127 # do not count VMs which are suspended for a backup job as running
128 my $conf = PVE
::QemuConfig-
>load_config($vmid, $nodename);
129 if (defined($conf->{lock}) && $conf->{lock} eq 'backup') {
130 my $qmpstatus = eval {
131 PVE
::QemuServer
::vm_qmp_command
($vmid, { execute
=> 'query-status' })
135 return 0 if defined($qmpstatus) && $qmpstatus->{status
} eq 'prelaunch';
145 my ($self, $haenv, $id, $locks, $service_node) = @_;
147 $service_node = $service_node || $haenv->nodename();
149 my $conf = PVE
::QemuConfig-
>load_config($id, $service_node);
151 return undef if !defined($conf->{lock});
153 foreach my $lock (@$locks) {
154 if ($conf->{lock} eq $lock) {
155 delete $conf->{lock};
157 my $cfspath = PVE
::QemuConfig-
>cfs_config_path($id, $service_node);
158 PVE
::Cluster
::cfs_write_file
($cfspath, $conf);