X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/blobdiff_plain/c2ef438b4260463f5294e5236d9b66bb9f4f5592..ccdd1009d00397d0f81fa9a95aa96faf448b9e94:/server/usr/sbin/invirt-remote-listhost diff --git a/server/usr/sbin/invirt-remote-listhost b/server/usr/sbin/invirt-remote-listhost new file mode 100755 index 0000000..64f6edf --- /dev/null +++ b/server/usr/sbin/invirt-remote-listhost @@ -0,0 +1,33 @@ +#!/usr/bin/python +""" +Say what host a running VM is on. +""" + +from subprocess import PIPE, Popen, call +import sys +import yaml + +def main(argv): + if len(argv) < 2: + print >>sys.stderr, "usage: invirt-remote-listhost " + return 2 + machine_name = argv[1] + + p = Popen(['/usr/sbin/invirt-remote-proxy-web', 'listvms'], stdout=PIPE) + output = p.communicate()[0] + if p.returncode != 0: + raise RuntimeError("Command '%s' returned non-zero exit status %d" + % ('invirt-remote-proxy-web', p.returncode)) + vms = yaml.load(output, yaml.CSafeLoader) + + if machine_name not in vms: + print >>sys.stderr, "machine '%s' is not on" % machine_name + return 2 + + print vms[machine_name]['host'] + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + +# vim:et:sw=4:ts=4