From 25d11cba05569ab263dd0b02be975ad4a9f0d393 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Fri, 20 Jan 2012 18:48:00 -0800 Subject: [PATCH] bug 12985: give it 3 seconds to realize a poweroff state --- .../vmware/mo/VirtualMachineMO.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java index 20f8149551c..4890ee5ea0c 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java @@ -247,7 +247,29 @@ public class VirtualMachineMO extends BaseMO { } public VirtualMachinePowerState getPowerState() throws Exception { - return (VirtualMachinePowerState)getContext().getServiceUtil().getDynamicProperty(_mor, "runtime.powerState"); + + VirtualMachinePowerState powerState = VirtualMachinePowerState.poweredOff; + + // This is really ugly, there is a case that when windows guest VM is doing sysprep, the temporary + // rebooting process may let us pick up a "poweredOff" state during VMsync process, this can trigger + // a series actions. Unfortunately, from VMware API we can not distinguish power state into such details. + // We hope by giving it 3 second to re-read the state can cover this as a short-term solution. + // + // In the future, VMsync should not kick off CloudStack action (this is not a HA case) based on VM + // state report, until then we can remove this hacking fix + for(int i = 0; i < 3; i++) { + powerState = (VirtualMachinePowerState)getContext().getServiceUtil().getDynamicProperty(_mor, "runtime.powerState"); + if(powerState == VirtualMachinePowerState.poweredOff) { + try { + Thread.sleep(1000); + } catch(InterruptedException e) { + } + } else { + break; + } + } + + return powerState; } public boolean reset() throws Exception {