Hi, All,
I've set up a single ESXi 6 host, from which I run several virtual machines.
In order to shut down the host when it is not necessary, I can use VSphere client, but I would prefer a programmable solution (for example to schedule, or to shut down the host from an android app).
So I investigated the API, and found the solution by tweaking the "hello world" application provided by vmware :
...
System.out.println(serviceContent.getAbout().getFullName());
System.out.println("Server type is "+serviceContent.getAbout().getApiType());
System.out.println("API version is "+serviceContent.getAbout().getApiVersion());
// Added
ManagedObjectReference si=serviceContent.getSearchIndex();
ManagedObjectReference o=vimPort.findByIp(si, null, "192.168.x.x", false); // seach for host o is a managedobjectreference "HostSystem"
System.out.println("Shutting down "+o.getType()+" "+o.getValue());
vimPort.shutdownHostTask(o,false); //gentle shutdown
...
Unfortunately, running the code results in a "license" exception :
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Current license or ESXi version prohibits execution of the requested operation.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:125)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
at com.sun.proxy.$Proxy28.shutdownHostTask(Unknown Source)
at HelloVmware.main(HelloVmware.java:55)
How is it possible that I can shut down from VSphere client, and this operation becomes impossible when accessing the same function from the API ? Isn't it a bug ?