Use VMware's WebService API to connect to ESX | Java source code of the esxi host

Source: Internet
Author: User

@ 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

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.