我在虚拟交换机上有许多虚拟端口组。当我执行
datacenters = si.RetrieveContent().rootFolder.childEntity
for datacenter in datacenters:
hosts = datacenter.hostFolder.childEntity
for host in hosts:
networks = host.network
for network in networks:
print network.name
(si是一个服务实例)我在网络上获得了所有的vlans (Portgroup),但是没有一个交换机( docs声称应该在网络目录中)。如果文件夹也有name属性,那么我查看的任何文件夹都应该打印出来。那么vsphere/vcenter把这些交换机放在哪里呢?
发布于 2015-08-18 04:31:14
要用vSwitches和pyVmomi检索,可以这样做:
def _get_vim_objects(content, vim_type):
'''Get vim objects of a given type.'''
return [item for item in content.viewManager.CreateContainerView(
content.rootFolder, [vim_type], recursive=True
).view]
content = si.RetrieveContent()
for host in self._get_vim_objects(content, vim.HostSystem):
for vswitch in host.config.network.vswitch:
print(vswitch.name)
结果将是:
vSwitch0
vSwitch1
vSwitch2
要检索_get_vim_objects分布式vSwitches,可以使用带有vim_type=vim.dvs.VmwareDistributedVirtualSwitch参数的函数(上面)。
发布于 2014-06-05 12:09:17
获取host.network将为您提供一个网络对象数组,而不是交换信息。要获取开关信息,这可能是最简单的方法。
datacenters = si.RetrieveContent().rootFolder.childEntity
for datacenter in datacenters:
networks = datacenter.networkFolder.childEntity
for network in networks:
print network.name
网络文件夹具有虚拟开关以及所有的portgroups。
发布于 2020-05-07 00:55:40
这是我用来在vCenter和检查版本中找到所有DV交换机的工具。
def find_all_dvs():
Q = "DVS unsupported versions"
try:
log.info("Testing %s" % Q)
host_ip, usr, pwd = vx.vc_ip, vx.vc_mu, vx.vc_mp # Reusing credentials
is_Old = False
si = connect.SmartConnect(host=host_ip, user=usr, pwd=pwd, port=int("443"))
datacenters = si.RetrieveContent().rootFolder.childEntity
for datacenter in datacenters:
networks = datacenter.networkFolder.childEntity
for vds in networks:
if (isinstance(vds, vim.DistributedVirtualSwitch)): # Find only DV switches
log.debug("DVS version: %s, DVS name: %s" %(vds.summary.productInfo.version, vds.summary.name))
if loose(vds.summary.productInfo.version) <= loose("6.0.0"):
is_Old = True
if is_Old:
log.info("vSphere 7.x unsupported DVS found.")
return
else:
return
except Exception as err:
log.error("%s error: %s" % (Q, str(err)))
log.error("Error detail:%s", traceback.format_exc())
return
https://stackoverflow.com/questions/24068815
复制