Created
February 20, 2014 17:19
-
-
Save mcowger/9118777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_subs(thething, level=0): | |
if level == 0: | |
_all_objects.clear() | |
#print "cleared all objects" | |
if type(thething).__name__ not in _all_objects.keys(): | |
_all_objects[type(thething).__name__] = [] | |
#print "added key " + type(thething).__name__ | |
# if we have a datacenter object, there are specific subobjects | |
if type(thething) is pyVmomi.types.vim.Datacenter: | |
#print "added datacenter" | |
_all_objects[type(thething).__name__].append(thething) | |
for sub in [thething.hostFolder, thething.networkFolder, thething.vmFolder]: | |
get_subs(sub, level=level + 1) | |
#If we have any kind of object that can contain others (Folders and ResourcePools), lets recurse on ourseves. | |
elif type(thething) in [pyVmomi.types.vim.Folder, pyVmomi.types.vim.ResourcePool]: | |
#print "added folder or RP " + thething.name | |
_all_objects[type(thething).__name__].append(thething) | |
for sub in thething.childEntity: | |
get_subs(sub, level=level + 1) | |
#If we have a compute resource (either a DRS cluster or a single host), lets get its bits: | |
elif type(thething) in [pyVmomi.types.vim.ComputeResource, pyVmomi.types.vim.ClusterComputeResource]: | |
#print "added cluster or host " + thething.name | |
_all_objects[type(thething).__name__].append(thething) | |
for elem in chain.from_iterable([thething.host, thething.network, thething.datastore]): | |
get_subs(elem, level=level + 1) | |
elif type(thething) in [pyVmomi.types.vim.ResourcePool]: | |
#print "added RP " + thething.name | |
_all_objects[type(thething).__name__].append(thething) | |
for elem in chain.from_iterable([thething.resourcePool, thething.vm]): | |
get_subs(elem, level=level + 1) | |
else: | |
#print "added entity " + thething.name | |
_all_objects[type(thething).__name__].append(thething) | |
return _all_objects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment