]> git.proxmox.com Git - qemu-server.git/commitdiff
vm_shutdown: request 'stopped' state for HA enabled VMs
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 23 Nov 2016 07:03:08 +0000 (08:03 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 23 Nov 2016 07:03:08 +0000 (08:03 +0100)
PVE/API2/Qemu.pm

index 779fdd89a9627b2d0056b8583d973bc4b8100034..7de1663f42cf01ce0b2ecf7602a1e30ab08fd294 100644 (file)
@@ -1959,18 +1959,40 @@ __PACKAGE__->register_method({
            }
        }
 
-       my $realcmd = sub {
-           my $upid = shift;
+       if (PVE::HA::Config::vm_is_ha_managed($vmid) &&
+           ($rpcenv->{type} ne 'ha')) {
 
-           syslog('info', "shutdown VM $vmid: $upid\n");
+           my $hacmd = sub {
+               my $upid = shift;
 
-           PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, $param->{timeout},
-                                    $shutdown, $param->{forceStop}, $keepActive);
+               my $service = "vm:$vmid";
 
-           return;
-       };
+               my $cmd = ['ha-manager', 'set', $service, '--state', 'stopped'];
+
+               print "Executing HA stop for VM $vmid\n";
+
+               PVE::Tools::run_command($cmd);
+
+               return;
+           };
+
+           return $rpcenv->fork_worker('hastop', $vmid, $authuser, $hacmd);
+
+       } else {
+
+           my $realcmd = sub {
+               my $upid = shift;
+
+               syslog('info', "shutdown VM $vmid: $upid\n");
 
-       return $rpcenv->fork_worker('qmshutdown', $vmid, $authuser, $realcmd);
+               PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, $param->{timeout},
+                                        $shutdown, $param->{forceStop}, $keepActive);
+
+               return;
+           };
+
+           return $rpcenv->fork_worker('qmshutdown', $vmid, $authuser, $realcmd);
+       }
     }});
 
 __PACKAGE__->register_method({