Java Example of
Retrieving a
vCenter
Server
ID by Using the Lookup Service
vCenter
Server
ID by Using the Lookup ServiceThis example is
based on the in the
LookupServiceHelper.java
sample file.
This example uses the steps that are
described in the
Retrieve a vCenter Server ID by Using the Lookup Service
procedure.
For a complete and
up-to-date version of the sample code, see the
vSphere
Automation SDK Java samples at GitHub.
... getMgmtNodeId(String targetNodeName) { // 1 - List the vCenter Server instances. List<LookupServiceRegistrationInfo> serviceInfos = lookupServiceUrls(“com.vmware.cis”, “vcenterserver”, “vmomi”, “com.vmware.vim”); // 2 - Find the matching node name and save the ID. for (LookupServiceRegistrationInfo serviceInfo : serviceInfos) { for (LookupServiceRegistrationAttribute serviceAtttr : serviceInfo.getServiceAttributes()) { if (“com.vmware.vim.vcenter.instanceName”.equals(serviceAttr.getKey())) { if (serviceAttr.getValue().equals(targetNodeName)) { return serviceInfo.getNodeId(); } } } } } ...