Communicate with the
Server
Connections to the server machine require
credentials: user name, password, and host name (or IP address). The following
code connects to the server and extracts information useful for manipulating a
service:
- Create the service instancemoRef:ManagedObjectReference svcRef = new ManagedObjectReference(); svcRef.setType("ServiceInstance"); svcRef.setValue("ServiceInstance");
- Locate the service:VimServiceLocator locator = new VimServiceLocator(); locator.setMaintainSession(true); VimPortType serviceConnection = locator.getVimPort("https://your_server/sdk");
- Log in to the session manager:ServiceInstanceContent serviceContent = serviceConnection.retrieveContent(svcRef); ManagedObjectReference sessionManager = serviceInstance.getSessionManager(); UserSession us = serviceConnection.login(sessionManager, username, password, null);