]>
git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Resources/PVEVM.pm
2e1698fce4c0005955f3bfcc517cf8048c1de068
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
::QemuServer
::Monitor
;
15 import PVE
::QemuServer
::Monitor
;
16 require PVE
::API2
::Qemu
;
17 import PVE
::API2
::Qemu
;
21 use base
qw(PVE::HA::Resources);
28 my ($class, $name) = @_;
30 die "invalid VMID\n" if $name !~ m/^[1-9][0-9]+$/;
35 state => { optional
=> 1 },
36 group
=> { optional
=> 1 },
37 comment
=> { optional
=> 1 },
38 max_restart
=> { optional
=> 1 },
39 max_relocate
=> { optional
=> 1 },
44 my ($class, $vmid, $nodename) = @_;
46 return PVE
::QemuConfig-
>config_file($vmid, $nodename);
50 my ($class, $vmid, $noerr) = @_;
52 my $vmlist = PVE
::Cluster
::get_vmlist
();
54 if(!defined($vmlist->{ids
}->{$vmid})) {
55 die "resource 'vm:$vmid' does not exist in cluster\n" if !$noerr;
63 my ($class, $haenv, $id) = @_;
65 my $nodename = $haenv->nodename();
72 my $upid = PVE
::API2
::Qemu-
>vm_start($params);
73 PVE
::HA
::Tools
::upid_wait
($upid, $haenv);
77 my ($class, $haenv, $id, $timeout) = @_;
79 my $nodename = $haenv->nodename();
80 my $shutdown_timeout = $timeout // 60;
88 if ($shutdown_timeout) {
89 $params->{timeout
} = $shutdown_timeout;
90 $params->{forceStop
} = 1;
91 $upid = PVE
::API2
::Qemu-
>vm_shutdown($params);
93 $upid = PVE
::API2
::Qemu-
>vm_stop($params);
96 PVE
::HA
::Tools
::upid_wait
($upid, $haenv);
100 my ($class, $haenv, $id, $target, $online) = @_;
102 my $nodename = $haenv->nodename();
107 # bug #2241 forces is for local resource only, people can ensure that
108 # different host have the same hardware, so this can be fine, and qemu
109 # knows when not, so can only win here
115 # explicitly shutdown if $online isn't true (relocate)
116 if (!$online && $class->check_running($haenv, $id)) {
117 $class->shutdown($haenv, $id);
120 my $oldconfig = $class->config_file($id, $nodename);
122 my $upid = PVE
::API2
::Qemu-
>migrate_vm($params);
123 PVE
::HA
::Tools
::upid_wait
($upid, $haenv);
125 # check if vm really moved
126 return !(-f
$oldconfig);
130 my ($class, $haenv, $vmid) = @_;
132 my $nodename = $haenv->nodename();
134 if (PVE
::QemuServer
::check_running
($vmid, 1, $nodename)) {
135 # do not count VMs which are suspended for a backup job as running
136 my $conf = PVE
::QemuConfig-
>load_config($vmid, $nodename);
137 if (defined($conf->{lock}) && $conf->{lock} eq 'backup') {
138 my $qmpstatus = eval {
139 PVE
::QemuServer
::Monitor
::mon_cmd
($vmid, 'query-status')
143 return 0 if defined($qmpstatus) && $qmpstatus->{status
} eq 'prelaunch';
153 my ($self, $haenv, $id, $locks, $service_node) = @_;
155 $service_node = $service_node || $haenv->nodename();
157 my $conf = PVE
::QemuConfig-
>load_config($id, $service_node);
159 return undef if !defined($conf->{lock});
161 foreach my $lock (@$locks) {
162 if ($conf->{lock} eq $lock) {
163 delete $conf->{lock};
165 my $cfspath = PVE
::QemuConfig-
>cfs_config_path($id, $service_node);
166 PVE
::Cluster
::cfs_write_file
($cfspath, $conf);