OpenVM() hanging

Jan 30, 2009 at 3:37 PM
I'm doing the following:

Host hostObject = VixCOMWrapper.Instance.Connect(
                     VIX_SERVICEPROVIDER.VMWARE_VI_SERVER,
                     "http://" + domain + "/sdk",
                     0,
                     username,
                     password);

VM vm = host.OpenVM(vmname);

I can connect to the server successfully (confirmed by calling FindItems()).
But when I step through the code it always hangs on VM vm = host.OpenVM(vmname)
I know I'm using the right vmname because its copied from the FindItems(VIX_FIND.REGISTERED_VMS) call and when I switch vmname to "Idontexist" it fails right away.

I checked some of the VixCOM message boards without success ...
Any thoughts?

cheers in advance
Jan 30, 2009 at 4:03 PM
Hello,

Like you i didn't succeed in opening with vm name directly :-(

after struglin' a while, what works for me is :

a/ connect to server
b/ get vms list (==list of vm objects)
c/ iterate thru list, and string compare (yes, i know...but...well...) to find the correct vm object from vmlist
d/ open that vm object

here's what my code looks like, that may help (ensure to properly try/catch eveything ;-) :

// looking for machine machineName at myServerFQDN

VIX.Host hostObject = null;
VIX.VM vmObject = null;

System.Collections.Generic.List<string> vmList = null;
System.Collections.Generic.List<object> vmProperties = null;

VIX_POWERSTATE VM_POWER_STATE = VIX_POWERSTATE.UNKNOWN_BIT;
VIX_TOOLSSTATE VM_TOOLS_STATE = VIX_TOOLSSTATE.UNKNOWN;
string VM_VMX_PATHNAME = null;
int VM_MEMORY_SIZE = 0;
int VM_NUM_VCPUS = 0;
bool VM_READ_ONLY = false;
bool VM_IS_RUNNING = false;

hostObject = VIX.VixCOMWrapper.Instance.Connect(
      VIX_SERVICEPROVIDER.VMWARE_VI_SERVER,
      "https://" + myServerFQDN + ":8333/sdk",
      0,
      serverUsername,
      serverPassword);
     
if (hostObject != null)
{

    //======================= get VM info =======================
    vmList = hostObject.FindItems(VIX_FIND.REGISTERED_VMS);
    if (vmList != null)
    {
 foreach (string machine in vmList)
 {
     if (machine.ToLower().Contains(machineName.ToLower() + "/" + machineName.ToLower() + ".vmx")) // each VM is ......\machineName\machineName.vmx
     {
  vmObject = hostObject.OpenVM(machine);    // open the VM object, not the machine Name
     }
 }
    }
    vmList = null;
    if (vmObject != null)
    {
  vmProperties = vmObject.GetProperties(
   new VIX_PROPERTY[] {    VIX_PROPERTY.VM_POWER_STATE,
         VIX_PROPERTY.VM_TOOLS_STATE,
         VIX_PROPERTY.VM_VMX_PATHNAME,
         VIX_PROPERTY.VM_MEMORY_SIZE,
         VIX_PROPERTY.VM_NUM_VCPUS,
         VIX_PROPERTY.VM_READ_ONLY,
         VIX_PROPERTY.VM_IS_RUNNING   
   });
 if (vmProperties != null)
 {
     VM_POWER_STATE = (VIX_POWERSTATE)vmProperties[0];
     VM_TOOLS_STATE = (VIX_TOOLSSTATE)vmProperties[1];
     VM_VMX_PATHNAME = (string)vmProperties[2];
     VM_MEMORY_SIZE = (int)vmProperties[3];
     VM_NUM_VCPUS = (int)vmProperties[4];
     VM_READ_ONLY = (bool)vmProperties[5];
     VM_IS_RUNNING = (bool)vmProperties[6];
 }
    }
}

Enjoy !
Regards. Didier

Jan 30, 2009 at 4:31 PM
Hi Didier,

Thanks for the quick response.
I was actually doing exactly what you were doing to obtain the vmname.
After testing a little more let me expand on the current issue:

Scenario
1) When VM is currently powered off
- I can successfully call the OpenVM() method as well as GetProperties()
- when I call PowerOn() it actually starts the VM (confirmed by watching the Virtual Infrastructure Client 2.0)
   BUT
- it also hangs on the PowerOn() so I can't get any further in my code

I could create a work around to handle this if my call to OpenVM() worked when the VM is already powered on, but this brings us to scenario 2

Scenario
2) When VM is currently powered on
- Any call to OpenVM() hangs as alluded to in my initial post

Any other ideas from the community as to why I'm experiencing this strange behavior?

cheers in advance