Problem with SUSPEND and SUSPENDED state

Jan 8, 2009 at 8:52 AM


First thanks for sharing this library ! it is going to save me lot of time and effort !

I started to write a small piece of code in order to backup my VMs (VMware server 2,   VixCOm 1.6.2, VS 2008 on XP SP3, DotNet 3.5...)

the idea is : 1°) STOP or SUSPEND according to parameter, 2°) COPY all files to another place, then 3°) LEAVE or RESTARTaccording to parameter.
It appears that :

a/ Suspended VMs (status according to VI web access) are reported VM_POWER_STATE=VIX_POWERSTATE.POWERED_OFF, not VIX_POWERSTATE.SUSPENDED.

b/ Restarting a Suspended VM  (still according to VI web access ;-) with  vmObject.PowerOn(VIX.Enums.VIX_VMPOWEROP.NORMAL)  returns back the to calling process BEFORE THE RESUME IS ACCOMPLISHED (Resuming should be synchronous then 100% done, isnt it ?), leading to errors with subsequent commands issued to the VM.

Any idea ?

Thanks in advance.


Jan 8, 2009 at 7:15 PM
Edited Jan 8, 2009 at 7:16 PM

a) Yes, I'm also noticing this on my machine. I think this is a bug in the VIX API itself, I checked it by making a sample application in C++ using vix.dll to be sure VixCOM isn't the cause of the problem. Indeed, it returns the same value here.

However, this only applies when I suspend the virtual machine via the VI Client or VI Web Access. If I'm suspending the VM via API, the GetProperties() function returns the correct value for the power state(VIX_POWERSTATE.SUSPENDED) :-D . When I disconnect and re-connect, it returns POWERED_OFF again.

b) According to my tests, this is related to a feature of VMware Server called "background snapshots". When this feature is enabled (it is by default), VMware Server restores the state of the VM in the background and the call from the API returns before the resume is finished. Try disabling background snapshots by selecting your host in VI Web Access, clicking "Edit Host Settings" and unchecking "Take and restore snapshots in the background".

Hope that helps!

Regards, Alex
Jan 9, 2009 at 12:21 PM

thanks for your response, i'll try it ASAP and let you know.

another one that just happened to me : after asking vmObject.GetProperties(VM_IS_RUNNING, VM_POWER_STATE, VM_TOOLS_STATE, VM_VMX_PATHNAME, VM_MEMORY_SIZE, NUM_VCPUS, VM_READ_ONLY), on one of  the 3 VMs (why one and not the others ?) the VM_POWER_STATE returned as the string "POWERED_ON, TOOLS_RUNNING, UNKNOWN_BIT", making it hard to check against the expected values of the enum ;-)

Regards, DiGeo
Jan 9, 2009 at 7:33 PM
Edited Jan 10, 2009 at 10:18 AM

This is as desired, since the VIX_POWERSTATE enum is a bit-field which means that more than one value can be set.

You should not check against the values of the enum using the string-representation. Instead, cast the result of the GetProperties() function (in your example it would be the second element in the list) to VIX_POWERSTATE and then use a logical AND operation.


// retrieve the value
List<object> result = vmx.GetProperties(new VIX_PROPERTY[] { VIX_PROPERTY.VM_POWER_STATE, VIX_PROPERTY.VM_TOOLS_STATE, ... });

// cast it to the enum
VIX_POWERSTATE powerStateOfTheVM = (VIX_POWERSTATE) result[0];

// check if the POWERED_ON bit is set by AND-ing it with itself, the result of the AND operation will be POWERED_ON if this bit is set
    // VM is powered on

Regards, Alex

*Update* I opened a thread on this topic in the VMware forums: