2013-10-21 19 views
2

我在查询ESX主机,其中一些由vCenter服务器管理,有些则不是。我想找出管理此主机的vCenter服务器的名称,如果有的话。 。如何从HostSystem对象确定vCenter Server?

我使用Python psphere模块,但我要的是对象的类型和属性我应该看在这是从我的代码中的相关摘录:

from psphere.client import Client 
import psphere.managedobjects 

items = [] 

cl = Client(hostname, userid, password) 
dcs = psphere.managedobjects.Datacenter.all(cl) 

我确定一个ESX主机与将vCenter服务器通过检查数据中心列表:

if len(dcs) == 1 and dcs[0].name == 'ha-datacenter': 
    hosts = psphere.managedobjects.HostSystem.all(cl) 

典型地,上述的主机将成为一个元件的列表:ESX主机。我想知道如何找出这台主机是否有管理ESX服务器。 vSphere客户端这样做,所以一定有办法。

else: # This is a vCenter server, so we can drill down to find the ESX servers 
    for dc in dcs: 
     items.extend(getEntities(dc, [hostname])) 

getEntities()是我自己的函数,用于收集有关主机和vCenter服务器的详细信息。

回答

1

我在​​对象内发现以下属性:.summary.managementServerIp。并非所有​​对象都会有这样的属性,所以我检查,如下所示:

host = ... a HostSystem object, acquired as described in the question ... 
if 'managementServerIp' in host.summary: 
    ... do something with the management server IP address ... 
1

这些数据字段(managementServerIp)并不总是填充。获取vcenter信息的更好的属性是get-vmhost cmdlet中的ServiceUrl(.extensiondata.Client.ServiceUrl)。此外,不需要对IP进行反向查找以获取名称。

只需解析URL即可获取vCenter服务器的名称。这个正则表达式(使用替换)完成这项工作:

'http[s|]://([^:]*):.*$', '$1' 
相关问题