VMware Cloud Community
bwinchell2
Contributor
Contributor
Jump to solution

Find the vCenter associated with ESXi host

Hello,

I am trying to find a way to extract the vCenter(VC) associated with a particular ESXi hosts?

I can find the VC:HostSystem but cannot seem to figure out how to link this back to the vCenter.  I cannot use "EsxiHost.parent.parent.parent" as the host might not be part of a cluster.  Might only be under a DC.  I looked under the HostConfig, About, Summary but could not find anything related to VC.

I could find all the hosts of a VC and then compare that array with my array of hosts but, that is ugly.

I did find an option to get the managedserverip which is the Ip of VC and then do a nslookup but, again ugly.

Any suggestions would be great.  I am writing this workflow in JS.

Thanks

B

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Registered vCenters are represented in vRO by VC:SdkConnection objects.

If you want to get the VC:SdkConnection associated with your host system, you can use the following code (it is a property of most managed objects):

var sdkConnection = host.sdkConnection;

System.log("SDK Connection: " + sdkConnection);

If you want to get vCenter's FQDN or instance name, you can use the following code:

var sdkConnection = host.sdkConnection; 

var optionManager = sdkConnection.optionManager; 

 

var vCenterInstanceName = optionManager.queryOptions("VirtualCenter.InstanceName").shift().value; 

var vCenterFqdn = optionManager.queryOptions("VirtualCenter.FQDN").shift().value; 

 

System.log("vCenter Instance Name: " + vCenterInstanceName); 

System.log("vCenter FQDN: " + vCenterFqdn);

In both code snippets, the input parameter is host of type VC:HostSystem

View solution in original post

Reply
0 Kudos
3 Replies
vijayrana968
Virtuoso
Virtuoso
Jump to solution

Are you trying this with PowerCli ?

Reply
0 Kudos
vijayrana968
Virtuoso
Virtuoso
Jump to solution

If you view the content of file /etc/vmware/vpxa/vpxa/cfg on a particular host then you will find associated vCenter IP in parameters with ServerIP.

<serverIp>10.0.0.26</serverIp>

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Registered vCenters are represented in vRO by VC:SdkConnection objects.

If you want to get the VC:SdkConnection associated with your host system, you can use the following code (it is a property of most managed objects):

var sdkConnection = host.sdkConnection;

System.log("SDK Connection: " + sdkConnection);

If you want to get vCenter's FQDN or instance name, you can use the following code:

var sdkConnection = host.sdkConnection; 

var optionManager = sdkConnection.optionManager; 

 

var vCenterInstanceName = optionManager.queryOptions("VirtualCenter.InstanceName").shift().value; 

var vCenterFqdn = optionManager.queryOptions("VirtualCenter.FQDN").shift().value; 

 

System.log("vCenter Instance Name: " + vCenterInstanceName); 

System.log("vCenter FQDN: " + vCenterFqdn);

In both code snippets, the input parameter is host of type VC:HostSystem

Reply
0 Kudos