Hi, can anybody help me please, I think I'm missing something. I had some code working fine with Workstation, but then moved the VM I want to open onto an ESXi box.
I'm using
ESX Server 3i version 3.5.0 build 153875
ViX version 1.6.2.2190
And here's the C# code:
const string vmxFilePath = "[ESX5 1] PmTest_WS2003_32/PmTest_WS2003_32.vmx";
String hostName = "http://192.168.25.76/sdk";
String userName = "theUserName";
String password = "thePassword";
VixCOM.VixLibClass vixLib = new VixCOM.VixLibClass();
// Connect
VixCOM.IHost hostHandle;
{
VixCOM.IJob jobHandle = vixLib.Connect(
VixCOM.Constants.VIX_API_VERSION,
VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER,
hostName, 0, userName, password, 0, null, null);
int[] propertyIds = new int[1] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };
object results = new object();
ulong vixError = jobHandle.Wait(propertyIds, ref results);
if (vixError != VixCOM.Constants.VIX_OK)
throw new ApplicationException();
object[] objectArray = (object[])results;
hostHandle = (VixCOM.IHost)objectArray[0];
}
// Register
{
ulong vixError = hostHandle.RegisterVM(vmxFilePath, null).WaitWithoutResults();
if (vixError != VixCOM.Constants.VIX_OK)
throw new ApplicationException();
}
// OpenVM
VixCOM.IVM vmHandle;
{
VixCOM.IJob jobHandle = hostHandle.OpenVM(vmxFilePath, null);
int[] propertyIds = new int[1] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };
object results = new object();
ulong vixError = jobHandle.Wait(propertyIds, ref results);
if (vixError != VixCOM.Constants.VIX_OK)
throw new ApplicationException(); // Fails here with vixError 26 which is VIX_E_HOST_NOT_CONNECTED
object[] objectArray = (object[])results;
vmHandle = (VixCOM.IVM)objectArray[0];
}
I get error 26 after waiting for the OpenVM job to complete. I'm pretty sure the username, password, hostName and vmxFilePath are correct because if I change any of them, then I get an appropriate error. Why does it report not connected, when clearly, only a few lines above, the connect call succeeded?
One thing I've noticed is that if I browse to the ESXi box, I get a warning about SSL certificates, but I would have thought if that was a problem, the original connect call would fail.
Any help would be appreciated, thanks,
-Scott
PS. Are there any logs I can look at that might give some kind of hint?
Aha. I seem to have got a bit further.
Initially I didn't have the Register call in, and so OpenVM was failing. Then, I added the Register call which registered the machine. But, on subsequent runs Register was being called everytime. The documentation says it's ok to call multiple times, and it returns success. But, in the event log on the ESXi box (seen via VMWare Infrastructure Client), the register call gets reported as an error.
I can only guess, that although the client end thinks the Register call succeeded, the host end is dropping the connection.
So... removing the Register call again got it working.
I guess I need some fancy workaround. If OpenVM fails, then do the Register, and then retry the OpenVM or something like that.
-Scott
Vix rewrites any "already registered" error to VIX_OK, and you should be able to safely re-register as many times as you want. So what you're doing should work, and out tests do this all the time. The network loss suggests ESX3i might be very unhappy though, and it may have reset.
Another test you could do is to use VixHost_FindItems with VIX_FIND_REGISTERED_VMS.
