这是我用来在 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