Hello,
I wrote this short programme to manage my tiny cloud, which consists of two machines. One is running windows server 2008 with vCenter 5.0 and the second is a ESXi 5.0 host. On the ESXi i have couple VMs with Ubuntu server 11.10 x64 installed on. I want to develop a programme which will create a bunch of VMs, run an app on each of them and then kill the VMs. Unfortunatelly, few functions throws some errors i don't get.
The code:
#include "vix.h" #include "stdio.h" int main() { VixError err = VIX_OK; VixHandle job, host, vm; printf("connecting to host:"); job=VixHost_Connect(VIX_API_VERSION,VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, "https://10.102.44.128/sdk",NULL,"Administrator","xxx",0,VIX_INVALID_HANDLE,NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_JOB_RESULT_HANDLE,&host,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d\n",err); else printf("\tOK"); Vix_ReleaseHandle(job); printf("\nregistering:"); job=VixHost_RegisterVM(host,"[datastore1] nmaszyna/nmaszyna.vmx",NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d\n",err); else printf("\t\tOK"); Vix_ReleaseHandle(job); printf("\nopening vm:"); job=VixVM_Open(host,"[datastore1] nmaszyna/nmaszyna.vmx",NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_JOB_RESULT_HANDLE,&vm,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t\t%d",err); else printf("\t\tOK"); Vix_ReleaseHandle(job); printf("\npowering the vm on:"); //throws 3008 but the vm got started job=VixVM_PowerOn(vm,VIX_VMPOWEROP_NORMAL,VIX_INVALID_HANDLE,NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d",err); else printf("\tOK"); Vix_ReleaseHandle(job); printf("\ninstalling tools:"); //throws 3016 job=VixVM_InstallTools(vm,VIX_INSTALLTOOLS_AUTO_UPGRADE ,NULL,NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d",err); else printf("\tOK"); Vix_ReleaseHandle(job); printf("\nawaiting for tools:"); //throws 3006 job=VixVM_WaitForToolsInGuest(vm,100,NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d",err); else printf("\tOK"); Vix_ReleaseHandle(job); printf("\nlogging into vm:"); //throws 3006 job=VixVM_LoginInGuest(vm, "root","xxx",VIX_LOGIN_IN_GUEST_REQUIRE_INTERACTIVE_ENVIRONMENT,NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d",err); else printf("\tOK"); Vix_ReleaseHandle(job); printf("\npowering the vm off:"); //no response, but the VM got powered off job = VixVM_PowerOff(vm,VIX_VMPOWEROP_NORMAL,NULL,NULL); err = VixJob_Wait(job,VIX_PROPERTY_NONE); if (VIX_OK != err) printf("\t%d",err); else printf("\tOK"); Vix_ReleaseHandle(job); VixHost_Disconnect(host); return 0; } The output: connecting to host: OK I'll be grateful for your replies and ideas on solving the issue. Cheers, Karol
registering: OK
opening vm: OK
powering the vm on: 3008 //but the vm got started
installing tools: 3016 /*
awaiting for tools: 3006 // immediately end up with errors
logging into vm: 3006 */
powering the vm off: //no output but the vm got powered off