Create Java source code for ESX/esxi users through VMware's WebService API

Source: Internet
Author: User

@ For & ever 2009-12-31

 

Refer to the VMware WebService API documentation to create ESX | esxi users and assign them to user groups.

Version: ESX | esxi 4.0

 

JavaCodeAs follows:

Import java.net. URL; </P> <p> Import COM. VMware. vim25.hostaccountspec; <br/> Import COM. VMware. vim25.managedobjectreference; <br/> Import COM. VMware. vim25.permission; <br/> Import COM. VMware. vim25.servicecontent; <br/> Import COM. VMware. vim25.vimporttype; <br/> Import COM. VMware. vim25.vimservicelocator; <br/> Import COM. VMware. security. credstore. *; </P> <p>/** <br/> * <p> <br/> * Create an ESX or esxi user (non-vcenter) <br /> * </P> <br/> * @ author forandever <br/> * @ date 2009-12-31 <br/> */<br/> public class createuser {</P> <p>/** <br/> * create a user <br/> * @ Param hostname Host IP address. Example: 202.101.1.121 <br/> * @ Param username connection username. For example, root <br/> * @ Param password indicates the connection password. Example: 123456 <br/> * @ throws exception <br/> */<br/> private void createuser (string hostname, string username, string password) throws exception {<br/> serverconn conn = new serverconn (); <br/> Conn. prepare (hostname, username, password); </P> <p> managedobjectreference hostlocalaccountmanager = <br/> Conn. get_sic (). getaccountmanager (); </P> <p> managedobjectreference hostauthorizationmanager = <br/> Conn. get_sic (). getauthorizationmanager (); </P> <p> string new_username = generateusername (); <br/> string new_password = generatepassword (); </P> <p> hostaccountspec = new hostaccountspec (); <br/> hostaccountspec. setid (new_username); <br/> hostaccountspec. setpassword (new_password); <br/> hostaccountspec. setdescription ("this is a new user created through API"); </P> <p> Conn. get_service (). createuser (hostlocalaccountmanager, <br/> hostaccountspec); </P> <p> system. out. println (new_username + "" + new_password); </P> <p> managedobjectreference rootfolder = <br/> Conn. get_sic (). getrootfolder (); </P> <p> // set the permission group <br/> permission per = new permission (); <br/> Per. setgroup (false); <br/> Per. setprincipal (new_username); <br/> Per. setroleid (-1); <br/> Per. setpropagate (true); <br/> Per. setentity (rootfolder); <br/> Conn. get_service (). setentitypermissions (hostauthorizationmanager, <br/> rootfolder, <br/> New permission [] {per}); </P> <p> // credentialstore csobj = credentialstorefactory. getcredentialstore (); <br/> // csobj. addpassword (getservername (), username, password. tochararray (); <br/> system. out. println ("new user created successfully"); <br/>}</P> <p> Public static void main (string [] ARGs) throws exception {<br/> createuser = new createuser (); <br/> createuser. createuser ("202.101.1.121", "root", "123456"); <br/>}< br/>

 

 

 

@ Forandever 2009-12-31

 

 

 

 

 

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.