VMware {code} Community
enricodile
Contributor
Contributor

Retrieve vCenter instance name

Hi,

How can I retrieve vCenter's instance name with SDK?

In vsphere Client i can see the name (in image below : SRVCENTER):

Image

 

I could not find it in any object...

Thanks in advance

Henry

0 Kudos
4 Replies
enricodile
Contributor
Contributor

In attachment the screenshot..
0 Kudos
stumpr
Virtuoso
Virtuoso

You'll want the OptionManager object on the ServiceInstance.

ServiceInstance -> setting ['VirtualCenter.InstanceName']

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
enricodile
Contributor
Contributor

Thank you very much, but i still have a problem.

This is my code:

ServiceInstance si = new ServiceInstance(url, username, password, ignoreCert);

OptionManager om = si.getOptionManager();

OptionValue[] ovs =om.queryOptions("VirtualCenter.InstanceName");

It returns this error on the third line:

Exception in thread "main" com.vmware.vim25.NoPermission

Also, this instruction:

OptionValue[] ovs =om.getSetting();

returns a NullPointerException...

Where is the problem?

0 Kudos
stumpr
Virtuoso
Virtuoso

You'll need to login.  If you are logging in, you also need permissions:

This method might require any of the following privileges depending on where the property fits in the inventory tree.

  • System.View on the root folder, if this is used to read settings in the "client" subtree.
  • System.Read on the root folder, if this is used to read all settings or any settings beside those in the "client" subtree.
  • System.Read on the host, if this is used to read the advanced options for a host configuration.
Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos