From f4b075bc792e74b43f7867b5daf4f1d89c7d5a09 Mon Sep 17 00:00:00 2001 From: abhi Date: Mon, 13 Feb 2012 16:42:15 +0530 Subject: [PATCH] bug 13549: cleanup stopped/starting VMs if present on host during MS startup Reviewed-by: kishan --- .../cloud/vm/VirtualMachineManagerImpl.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 7245e5268e8..590924040e7 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1741,6 +1741,24 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene e.printStackTrace(); } } + else if (info != null && (vm.getState() == State.Stopped || vm.getState() == State.Stopping)) { + Host host = _hostDao.findByGuid(info.getHostUuid()); + if (host != null){ + s_logger.warn("Stopping a VM which is stopped/stopping " + info.name); + vm.setState(State.Stopped); // set it as stop and clear it from host + vm.setHostId(null); + _vmDao.persist(vm); + try { + Answer answer = _agentMgr.send(host.getId(), cleanup(info.name)); + if (!answer.getResult()) { + s_logger.warn("Unable to stop a VM due to " + answer.getDetails()); + } + } + catch (Exception e) { + s_logger.warn("Unable to stop a VM due to " + e.getMessage()); + } + } + } else // host id can change if (info != null && vm.getState() == State.Running){