Skip to content

Instantly share code, notes, and snippets.

@hartsock
Created December 3, 2014 23:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hartsock/513a27e0694e151fcea0 to your computer and use it in GitHub Desktop.
Save hartsock/513a27e0694e151fcea0 to your computer and use it in GitHub Desktop.
Get all the datacenters in a vCenter using pyVmomi
from __future__ import print_function
from pyVim import connect
from pyVmomi import vim
si = connect.SmartConnect(host='vcsa', user='my_user', pwd='my_password')
content = si.RetrieveContent()
# A list comprehension of all the root folder's first tier children...
datacenters = [entity for entity in content.rootFolder.childEntity
if hasattr(entity, 'vmFolder')]
# Just to prove to ourselves we have that list:
for dc in datacenters:
print(dc.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment