Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pyVim.connect import SmartConnect, SmartConnectNoSSL, Disconnect
- from pyVmomi import vim
- import atexit
- host = " "
- user = " "
- password = ' '
- serviceInstance = SmartConnectNoSSL(host=host,
- user=user,
- pwd=password,
- port=443)
- atexit.register(Disconnect, serviceInstance)
- content = serviceInstance.RetrieveContent()
- def get_all_objs(content, vimtype):
- obj = {}
- container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
- for managed_object_ref in container.view:
- obj.update({managed_object_ref: managed_object_ref.name})
- return obj
- # dvss = get_all_objs(content, [vim.DistributedVirtualSwitch])
- # portgroups = get_all_objs(content, [vim.DistributedVirtualPortgroup])
- children = content.rootFolder.childEntity
- for child in children: # Iterate though DataCenters
- dc = child
- clusters = dc.hostFolder.childEntity
- for cluster in clusters: # Iterate through the clusters in the DC
- for network in cluster.network: # Iterate through the networks in the cluster
- name = network.name
- # print name
- try:
- vlan = network.config.defaultPortConfig.vlan.vlanId
- if isinstance(vlan, int):
- count = 0
- for vm in network.vm:
- # print vm
- count += 1
- print("vmware_portgroup_connected_vms dc={0} cluster={1} portgroup={2} vlan={3} {4}".format(dc.name, cluster.name, name, vlan, count))
- except:
- print "exception"
Add Comment
Please, Sign In to add comment