From 18b5fb5a3c6d4dc2d4b132964bc242fe267ec664 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Mon, 3 Feb 2014 17:01:20 -0800 Subject: [PATCH] do not shutdown alien VMs upon host startup. Send StopCommand for out-of-band stopped VM to restore legacy XS/KVM behave --- .../src/com/cloud/vm/VirtualMachineManagerImpl.java | 4 +++- .../hypervisor/xen/resource/CitrixResourceBase.java | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 84c56aea27c..e7e49b8119f 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -4132,7 +4132,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Stopped state according to power-off report from hypervisor"); - // TODO: we need to forcely release all resource allocation + VirtualMachineGuru vmGuru = getVmGuru(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + sendStop(vmGuru, profile, true); break; case Destroyed: diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 12ba7c99c5c..33e7462c6c6 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -347,6 +347,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return _host; } + private static boolean isAlienVm(VM vm, Connection conn) throws XenAPIException, XmlRpcException { + // TODO : we need a better way to tell whether or not the VM belongs to CloudStack + String vmName = vm.getNameLabel(conn); + if (vmName.matches("^[ivs]-\\d+-.+")) + return false; + + return true; + } + protected boolean cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException { Host host = Host.getByUuid(conn, _host.uuid); Map vms = VM.getAllRecords(conn); @@ -358,7 +367,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe continue; } - if (VmPowerState.HALTED.equals(vmRec.powerState) && vmRec.affinity.equals(host)) { + if (VmPowerState.HALTED.equals(vmRec.powerState) && vmRec.affinity.equals(host) && !isAlienVm(vm, conn)) { try { vm.destroy(conn); } catch (Exception e) {