VMware Cloud Community
linlin_dl
Contributor
Contributor

Create a domain user for vCenter via python or java sdk

Hi All,

Is it possible to create a domain user for vCenter via python or java sdk?

If there are any script I could use to create a domain user Please also let me know.

Any help is appreciate.

I have a Platform Services Controller and two vCenter applicances (6.5) in link mode.

I want to create a new user for each vCenter and grant the new user with some permissions.

I could create a role for each vCenter via Python SDK but I could not create a vCenter user.

Below is my Python code example:

serviceInst = SmartConnect(host=vcIP,

                           port=self.__vcPort,

                           user=self._username, #administrator@vsphere.local

                           pwd=self._password,

                           sslContext=context)

content = serviceInst.RetrieveContent()

authMgr = content.authorizationManager

roleId=authMgr.AddAuthorizationRole(name,privIds)#works well here

userSpec = vim.HostAccountSpec()

  1. userSpec.id = name
  2. userSpec.password = password
  3. userSpec.description =’test account'

accountMgr = content.accountManager #it is None

  1. accountMgr.CreateUser(userSpec)

#I also tried to create this localAccoutManager,it could not work too.

accountMgr=vim.host.LocalAccountManager("LocalAccountManager",content.rootFolder._stub,content.about.instanceUuid)

ManagedObjectNotFound: (vmodl.fault.ManagedObjectNotFound) {

   dynamicType = <unset>,

   dynamicProperty = (vmodl.DynamicProperty) [],

   msg = "The object 'vim.host.LocalAccountManager:LocalAccountManager' has already been deleted or has

    not been completely created",

   faultCause = <unset>,

   faultMessage = (vmodl.LocalizableMessage) [],

   obj = 'vim.host.LocalAccountManager:LocalAccountManager'

}

In Java SDK, the getAccountManager() also return null

rootRef = serviceContent.getRootFolder();//it works.

ManagedObjectReference accountMgr=serviceContent.getAccountManager();

HostAccountSpec spec = new HostAccountSpec();

spec.setId("fromJava");

spec.setPassword("password");

spec.setDescription("This is created from JDK");

try {

      vimPort.createUser(accountMgr, spec);

} catch (AlreadyExistsFaultMsg e) {

            // TODO Auto-generated catch block

}   

0 Kudos
0 Replies