From d39ddb212dc47091ff530b655d769e869f7ca108 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 29 Jun 2008 00:39:58 -0400 Subject: [PATCH] remctl .. control .. listhost: say where a VM is running svn path=/trunk/packages/sipb-xen-remote-server/; revision=661 --- files/usr/sbin/sipb-xen-remote-listhost | 33 +++++++++++++++++++++++++++++++ files/usr/sbin/sipb-xen-remote-proxy | 2 ++ 2 files changed, 35 insertions(+) create mode 100755 files/usr/sbin/sipb-xen-remote-listhost diff --git a/files/usr/sbin/sipb-xen-remote-listhost b/files/usr/sbin/sipb-xen-remote-listhost new file mode 100755 index 0000000..fa3d43b --- /dev/null +++ b/files/usr/sbin/sipb-xen-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: sipb-xen-remote-listhost " + return 2 + machine_name = argv[1] + + p = Popen(['/usr/sbin/sipb-xen-remote-proxy-web', 'listvms'], stdout=PIPE) + output = p.communicate()[0] + if p.returncode != 0: + raise RuntimeError("Command '%s' returned non-zero exit status %d" + % ('sipb-xen-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 diff --git a/files/usr/sbin/sipb-xen-remote-proxy b/files/usr/sbin/sipb-xen-remote-proxy index 59555b3..069ad47 100755 --- a/files/usr/sbin/sipb-xen-remote-proxy +++ b/files/usr/sbin/sipb-xen-remote-proxy @@ -16,6 +16,8 @@ case "$TYPE/$SERVICE" in sipb-xen-remote-listvms "$@" ;; control/create ) sipb-xen-remote-create "$MACHINE" "$@" ;; + control/listhost ) + sipb-xen-remote-listhost "$MACHINE" "$@" ;; control/* ) # Everything but create must go where the VM is already running. sipb-xen-remote-control "$MACHINE" "$SERVICE" "$@" ;; -- 1.7.9.5