Created
December 22, 2014 22:08
Revisions
-
Shawn Hartsock created this gist
Dec 22, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/env python 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() host_list = [] stack = [content.rootFolder] while stack: entity = stack.pop() if entity.__class__.__name__ == 'vim.HostSystem': host_list.append(entity) if hasattr(entity, 'host'): if isinstance(entity.host, list): for host in entity.host: host_list.append(host) else: host_list.append(entity.host) if hasattr(entity, 'hostFolder'): stack.append(entity.hostFolder) if hasattr(entity, 'childEntity'): for child in entity.childEntity: stack.append(child) print('Host systems found: ') for host in host_list: print(host.name)