@ For & ever 2009-12-31
Refer to the VMware WebService API documentation to connect to the ESX | esxi host.
Version: ESX | esxi 4.0
The Java code is as follows:
Import java.net. URL; </P> <p> Import COM. VMware. vim25.managedobjectreference; <br/> Import COM. VMware. vim25.servicecontent; <br/> Import COM. VMware. vim25.vimporttype; <br/> Import COM. VMware. vim25.vimservicelocator; </P> <p>/** <br/> * obtain the connection to VMware ESX or esxi <br/> * ESX | esxi version: 4.0 <br/> * @ author forandever <br/> * @ date 2009-12-29 <br/> */<br/> public class serverconn {</P> <p> private managedob Jectreference _ svcref; <br/> private vimservicelocator _ locator; <br/> private vimporttype _ service; <br/> private servicecontent _ SiC; </P> <p> private void createserviceref () throws exception {<br/> _ svcref = new managedobjectreference (); <br/> _ svcref. settype ("serviceinstance"); <br/> _ svcref. set_value ("serviceinstance"); <br/>}</P> <p> Public void prepare (string hostname, string username, string passwor D) throws exception {<br/> system. setproperty ("axis. socketsecurefactory "," org.apache.axis.components.net. sunfaketrustsocketfactory "); <br/> string url =" https: // "+ hostname +"/SDK/vimservice "; <br/> createserviceref (); <br/> _ locator = new vimservicelocator (); <br/> _ locator. setmaintainsession (true); <br/> _ service = _ locator. getvimport (new URL (URL); <br/> _ SiC = _ service. retrieveservicecontent (_ SV Cref); <br/> If (_ SiC. getsessionmanager ()! = NULL) {<br/> _ service. login (_ SiC. getsessionmanager (), username, password, null); <br/>}< br/> system. out. println (_ SiC. getabout (). getfullname (); <br/> system. out. println ("API type is" + _ SiC. getabout (). getapitype (); <br/> system. out. println ("API version is" + _ SiC. getabout (). getapiversion (); <br/>}</P> <p> Public managedobjectreference get_svcref () {<br/> return _ svcref; <br/>}</P> <p> Public void set_svcref (managedobjectreference ref) {<br/> _ svcref = ref; <br/>}</P> <p> Public vimservicelocator get_locator () {<br/> return _ locator; <br/>}</P> <p> Public void set_locator (vimservicelocator _ Locator) {<br/> This. _ locator = _ locator; <br/>}</P> <p> Public vimporttype get_service () {<br/> return _ service; <br/>}</P> <p> Public void set_service (vimporttype _ service) {<br/> This. _ service = _ service; <br/>}</P> <p> Public servicecontent get_sic () {<br/> return _ SiC; <br/>}</P> <p> Public void set_sic (servicecontent _ SIC) {<br/> This. _ SiC = _ SiC; <br/>}</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> // todo auto-generated method stub </P> <p >}< br/>
@ Forandever 2009-12-31