vm2host for vSphere 4
I recently twittered about a neat little new script of mine called hostForVm, which tells you on which host a specific vm runs or which vms run on a specific host. Done using [[http://www.python.org|python]],[[https://fedorahosted.org/suds|suds]] and the [[http://communities.vmware.com/community/vmtn/developer/forums/managementapi|vSphere Web SDK]].
The script is available at github:
[[https://github.com/dploeger/hostForVm]]One thing to note: If you use the script to work against a vSphere 4-vCenter Server, be sure to do a nasty patching of suds, as vSphere 4 expects all types to be NOT prefixed with
To patch that functionality out of suds (and make suds useless for the rest of your installation :-(), change the Following around line #90 of
xta = ':'.join((NS.xsins[0], 'type'))
node.addPrefix(NS.xsins[0], NS.xsins[1])
if ns is None:
to
xta = ':'.join((NS.xsins[0], 'type'))
xta = None
node.addPrefix(NS.xsins[0], NS.xsins[1])
if ns is None:
(add xta = None)
This is sad, but fixed in vSphere 5. So upgrade to vSphere 5 if you’re bothered by it.