Index: package_tags/sipb-xen-remote-server/0.10/debian/changelog
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/changelog	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/changelog	(revision 1160)
@@ -0,0 +1,87 @@
+sipb-xen-remote-server (0.10) unstable; urgency=low
+
+  * If a command is invalid, but the machine's on, give an actually useful
+    error message
+
+ -- Evan Broder <broder@mit.edu>  Wed, 22 Oct 2008 00:29:50 -0400
+
+sipb-xen-remote-server (0.9.2) unstable; urgency=low
+
+  * Expose an interface to the autoinstaller over remctl
+  * Validate options to be passed to the autoinstaller on the remctl
+    server
+
+ -- Evan Broder <broder@mit.edu>  Thu, 09 Oct 2008 02:06:00 -0400
+
+sipb-xen-remote-server (0.9.1) unstable; urgency=low
+
+  * Fix a bug in the database handling code
+
+ -- Evan Broder <broder@mit.edu>  Fri, 03 Oct 2008 18:42:48 -0400
+
+sipb-xen-remote-server (0.9) unstable; urgency=low
+
+  [Evan Broder]
+  * Make the acl/ subdir of RemConfFS listable
+  
+  [Greg Price]
+  * Update RemConfFS for new SQLAlchemy code
+
+ -- Evan Broder <broder@mit.edu>  Wed, 01 Oct 2008 19:28:23 -0400
+
+sipb-xen-remote-server (0.8) unstable; urgency=low
+
+  * Use RouteFS for RemConfFS
+
+ -- Evan Broder <broder@mit.edu>  Wed, 01 Oct 2008 02:21:00 -0400
+
+sipb-xen-remote-server (0.7) unstable; urgency=low
+
+  * depend on sipb-xen-base
+
+ -- Greg Price <price@mit.edu>  Tue, 30 Sep 2008 20:47:05 -0400
+
+sipb-xen-remote-server (0.6) unstable; urgency=low
+
+  * sipb_xen_database -> invirt.config
+
+ -- Yang Zhang <y_z@mit.edu>  Sun,  3 Aug 2008 00:54:59 -0400
+
+sipb-xen-remote-server (0.5) unstable; urgency=low
+
+  * use invirt config in sipb-xen-remconffs, sipb-xen-remctl-help,
+    sipb-xen-remote-proxy
+
+ -- Yang Zhang <y_z@mit.edu>  Sun,  3 Aug 2008 00:32:59 -0400
+
+sipb-xen-remote-server (0.4) unstable; urgency=low
+
+  * use invirt.config to get hostnames
+  * refactoring: extracted bcast() function into invirt.remote package
+
+ -- Yang Zhang <y_z@mit.edu>  Sat,  2 Aug 2008 20:34:50 -0400
+
+sipb-xen-remote-server (0.3) unstable; urgency=low
+
+  * Fill in all the code to make the package work (mostly weeks ago.)
+  * sipb-xen-remote-listvms aggregates listvms across hosts (with
+    y_z, broder, andersk)
+  * sipb-xen-remctl-help gives help
+  * sipb-xen-remote-control proxies to where a machine is running
+  * sipb-xen-remote-create chooses where to boot by load-balancing
+
+ -- Greg Price <price@mit.edu>  Thu, 24 Jul 2008 21:34:20 -0400
+
+sipb-xen-remote-server (0.2) unstable; urgency=low
+
+  * FUSE filesystem for remctl configuration.
+  * Remove *register calls, since the FUSE keeps things up to date.
+  * An init script to keep the FUSE fs up.
+
+ -- Greg Price <price@mit.edu>  Sat, 10 May 2008 22:04:32 -0400
+
+sipb-xen-remote-server (0.1) unstable; urgency=low
+
+  * First draft.
+
+ -- Greg Price <price@mit.edu>  Sun, 30 Mar 2008 01:08:50 -0400
Index: package_tags/sipb-xen-remote-server/0.10/debian/compat
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/compat	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/compat	(revision 1160)
@@ -0,0 +1,1 @@
+5
Index: package_tags/sipb-xen-remote-server/0.10/debian/control
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/control	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/control	(revision 1160)
@@ -0,0 +1,14 @@
+Source: sipb-xen-remote-server
+Section: servers
+Priority: important
+Maintainer: sipb-xen@mit.edu
+Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 5)
+Standards-Version: 3.7.2
+
+Package: sipb-xen-remote-server
+Architecture: all
+Provides: ${diverted-files}
+Conflicts: ${diverted-files}
+Depends: ${shlibs:Depends}, ${misc:Depends}, daemon, debathena-kerberos-config, fuse-utils, openssh-server, python-routefs, sipb-xen-chrony-config, sipb-xen-database-common, sipb-xen-base, remctl-server, remctl-client
+Description: SIPB Xen remote-control server
+ This package should be installed to set up the remote-control server.
Index: package_tags/sipb-xen-remote-server/0.10/debian/control.in
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/control.in	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/control.in	(revision 1160)
@@ -0,0 +1,14 @@
+Source: sipb-xen-remote-server
+Section: servers
+Priority: important
+Maintainer: sipb-xen@mit.edu
+Build-Depends: @cdbs@
+Standards-Version: 3.7.2
+
+Package: sipb-xen-remote-server
+Architecture: all
+Provides: ${diverted-files}
+Conflicts: ${diverted-files}
+Depends: ${shlibs:Depends}, ${misc:Depends}, daemon, debathena-kerberos-config, fuse-utils, openssh-server, python-routefs, sipb-xen-chrony-config, sipb-xen-database-common, sipb-xen-base, remctl-server, remctl-client
+Description: SIPB Xen remote-control server
+ This package should be installed to set up the remote-control server.
Index: package_tags/sipb-xen-remote-server/0.10/debian/copyright
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/copyright	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/copyright	(revision 1160)
@@ -0,0 +1,3 @@
+This package was created for internal use of the SIPB Xen Project of
+the MIT Student Information Processing Board.  Ask sipb-xen@mit.edu if
+you have questions about redistribution.
Index: package_tags/sipb-xen-remote-server/0.10/debian/rules
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/rules	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/rules	(revision 1160)
@@ -0,0 +1,11 @@
+#!/usr/bin/make -f
+
+DEB_AUTO_UPDATE_DEBIAN_CONTROL = 1
+DEB_DIVERT_EXTENSION = .sipb-xen
+#DEB_DIVERT_FILES_sipb-xen-remote-server += \
+#	/etc/init.d/bootmisc.sh \
+#	/etc/nscd.conf \
+#	/etc/nsswitch.conf \
+#	/etc/ssh/sshd_config
+
+include /usr/share/cdbs/1/rules/debhelper.mk
Index: package_tags/sipb-xen-remote-server/0.10/debian/sipb-xen-remote-server.init
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/sipb-xen-remote-server.init	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/sipb-xen-remote-server.init	(revision 1160)
@@ -0,0 +1,126 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          sipb-xen-remote-server
+# Required-Start:    $local_fs $remote_fs
+# Required-Stop:     $local_fs $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: sipb-xen remctl configuration filesystem
+# Description:       
+### END INIT INFO
+
+# Author: SIPB Xen Project <sipb-xen@mit.edu>
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="The sipb-xen remctl configuration filesystem"
+NAME=sipb-xen-remconffs
+DAEMON=/usr/sbin/sipb-xen-remconffs
+DAEMON_ARGS="/etc/remctl/remconffs"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	modprobe fuse
+	daemon --running -n $NAME && return 1
+	daemon -r -O daemon.info -E daemon.err -n $NAME -U $DAEMON $DAEMON_ARGS || return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	daemon --stop -n $NAME
+	RETVAL="$?"
+	[ "$RETVAL" = 2 ] && return 2
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	umount "$DAEMON_ARGS"
+	return "$RETVAL"
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  #reload|force-reload)
+	#
+	# If do_reload() is not implemented then leave this commented out
+	# and leave 'force-reload' as an alias for 'restart'.
+	#
+	#log_daemon_msg "Reloading $DESC" "$NAME"
+	#do_reload
+	#log_end_msg $?
+	#;;
+  restart|force-reload)
+	#
+	# If the "reload" option is implemented then remove the
+	# 'force-reload' alias
+	#
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
Index: package_tags/sipb-xen-remote-server/0.10/debian/sipb-xen-remote-server.install
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/debian/sipb-xen-remote-server.install	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/debian/sipb-xen-remote-server.install	(revision 1160)
@@ -0,0 +1,1 @@
+files/* .
Index: package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/acl/web
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/acl/web	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/acl/web	(revision 1160)
@@ -0,0 +1,2 @@
+price/root@ATHENA.MIT.EDU
+daemon/sipb-xen.mit.edu@ATHENA.MIT.EDU
Index: package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/conf.d/remconffs
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/conf.d/remconffs	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/conf.d/remconffs	(revision 1160)
@@ -0,0 +1,1 @@
+include /etc/remctl/remconffs/conf
Index: package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/conf.d/sipb-xen-web
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/conf.d/sipb-xen-web	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/etc/remctl/conf.d/sipb-xen-web	(revision 1160)
@@ -0,0 +1,9 @@
+web lvcreate     /usr/sbin/sipb-xen-remote-proxy-web /etc/remctl/acl/web
+web lvremove     /usr/sbin/sipb-xen-remote-proxy-web /etc/remctl/acl/web
+web lvrename     /usr/sbin/sipb-xen-remote-proxy-web /etc/remctl/acl/web
+web lvresize     /usr/sbin/sipb-xen-remote-proxy-web /etc/remctl/acl/web
+web lvcopy       /usr/sbin/sipb-xen-remote-proxy-web /etc/remctl/acl/web
+web listvms      /usr/sbin/sipb-xen-remote-proxy-web /etc/remctl/acl/web
+test sleep       /usr/bin/env /etc/remctl/acl/web
+control help	 /usr/sbin/sipb-xen-remctl-help	ANYUSER
+help ALL	 /usr/sbin/sipb-xen-remctl-help	ANYUSER
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remconffs
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remconffs	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remconffs	(revision 1160)
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+import routefs
+from routes import Mapper
+
+from syslog import *
+from time import time
+
+from invirt import database
+from invirt.config import structs as config
+
+class RemConfFS(routefs.RouteFS):
+	"""
+	RemConfFS creates a filesytem for configuring remctl, like this:
+	/
+	|-- acl
+	|   |-- machine1
+	|   ...
+	|   `-- machinen
+	`-- conf
+        
+	The machine list and the acls are drawn from a database.
+	"""
+	
+	def __init__(self, *args, **kw):
+		"""Initialize the filesystem and set it to allow_other access besides
+		the user who mounts the filesystem (i.e. root)
+		"""
+		super(RemConfFS, self).__init__(*args, **kw)
+		self.lasttime = time()
+		self.fuse_args.add("allow_other", True)
+		
+		openlog('sipb-xen-remconffs ', LOG_PID, LOG_DAEMON)
+		
+		syslog(LOG_DEBUG, 'Init complete.')
+        
+        def make_map(self):
+                m = Mapper()
+                m.connect('', controller='getroot')
+                m.connect('acl', controller='getmachines')
+                m.connect('acl/:machine', controller='getacl')
+                m.connect('conf', controller='getconf')
+                return m
+        
+        def getroot(self, **kw):
+                return ['acl', 'conf']
+        
+	def getacl(self, machine, **kw):
+		"""Build the ACL file for a machine
+		"""
+		machine = database.Machine.query().filter_by(name=machine).one()
+		users = [acl.user for acl in machine.acl]
+		return "\n".join(map(self.userToPrinc, users)
+				 + ['include /etc/remctl/acl/web',
+				    ''])
+        
+	def getconf(self, **kw):
+		"""Build the master conf file, with all machines
+		"""
+		return '\n'.join("control %s /usr/sbin/sipb-xen-remote-proxy-control"
+				 " /etc/remctl/remconffs/acl/%s"
+				 % (machine_name, machine_name)
+				 for machine_name in self.getmachines())+'\n'
+	
+	def getmachines(self, **kw):
+		"""Get the list of VMs in the database, clearing the cache if it's 
+		older than 15 seconds"""
+		if time() - self.lasttime > 15:
+			self.lasttime = time()
+			database.clear_cache()
+		return [machine.name for machine in database.session.query(database.Machine).all()]
+        
+	def userToPrinc(self, user):
+		"""Convert Kerberos v4-style names to v5-style and append a default
+		realm if none is specified
+		"""
+		if '@' in user:
+			(princ, realm) = user.split('@')
+		else:
+			princ = user
+			realm = config.authn[0].realm
+		
+		return princ.replace('.', '/') + '@' + realm
+
+if __name__ == '__main__':
+	database.connect()
+        routefs.main(RemConfFS)
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remctl-help
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remctl-help	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remctl-help	(revision 1160)
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+"""
+Help on using the Invirt remctl functions.
+"""
+import sys
+from invirt.config import structs as config
+
+help = [
+    ('list',      'show your VM\'s state (with xm list)'),
+    ('listhost',  'show on what host, if any, your VM is running'),
+    ('list-long', 'show your VM\'s state as an sexp (with xm list --long)'),
+    ('vcpu-list', 'show your VM\'s state (with xm vcpu-list)'),
+    ('uptime',    'show your VM\'s state (with xm uptime)'),
+    ('destroy',   'shut down your VM, hard (with xm destroy)'),
+    ('shutdown',  'shut down your VM, softly if paravm (with xm shutdown)'),
+    ('create',    'start up your VM (with xm create)'),
+    ('reboot',    'reboot your VM (with xm destroy and xm create)'),
+    ('install',   'autoinstall your VM (takes a series of key=value pairs; \n\t\tvalid arguments include mirror, dist, arch, imagesize,\n\t\tand noinstall)'),
+    #also CD images on create/reboot
+]
+helpdict = dict(help)
+
+
+def print_help(name, text):
+    print '  %-9s : %s' % (name, text)
+
+def main(args):
+    args = [n for n in args if n in helpdict]
+    print 'remctl %s control <machine> <command>' % config.remote.hostname
+    if args:
+        for name in args:
+            print_help(name, helpdict[name])
+    else:
+        for name, text in help:
+            print_help(name, text)
+        
+    return 0
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:]))
+
+# vim:et:sw=4:ts=4
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-control
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-control	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-control	(revision 1160)
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+"""
+Sends remctl commands about a running VM to the host it's running on.
+"""
+
+from subprocess import PIPE, Popen, call
+import sys
+import yaml
+
+def main(argv):
+    if len(argv) < 3:
+        print >>sys.stderr, "usage: sipb-xen-remote-control <machine> <command>"
+        return 2
+    machine_name = argv[1]
+    command = argv[2]
+
+    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 1
+    host = vms[machine_name]['host']
+
+    p = Popen(['remctl', host, 'remote', 'control'] + argv[1:],
+              stdout=PIPE, stderr=PIPE)
+    (out, err) = p.communicate()
+    if p.returncode == 1:
+        print >>sys.stderr, "ERROR: invalid command"
+        return 1
+    sys.stderr.write(err)
+    sys.stdout.write(out)
+    return p.returncode
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+
+# vim:et:sw=4:ts=4
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-create
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-create	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-create	(revision 1160)
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+
+"""
+Picks a host to "create" (boot) a VM on, and does so.
+
+Current load-balancing algorithm: wherever there's more free RAM.
+
+TODO: use a lock to avoid creating the same VM twice in a race
+"""
+
+from invirt.remote import bcast
+from subprocess import PIPE, Popen, call
+import sys
+import yaml
+
+def choose_host():
+    # Query each of the hosts.
+    # XXX will the output of 'xm info' always be parseable YAML?
+    results = bcast('info')
+    return max((int(o['free_memory']), s) for (s, o) in results)[1]
+
+def main(argv):
+    if len(argv) < 3:
+        print >> sys.stderr, "usage: sipb-xen-remote-create <operation> <machine> [<other args...>]"
+        return 2
+    operation = argv[1]
+    machine_name = argv[2]
+    args = argv[3:]
+    
+    if operation == 'install':
+        options = dict(arg.split('=', 1) for arg in args)
+        valid_keys = set(('mirror', 'dist', 'arch', 'imagesize', 'noinstall'))
+        if not set(options.keys()).issubset(valid_keys):
+            print >> sys.stderr, "Invalid argument. Use the help command to see valid arguments to install"
+            return 1
+        if any(' ' in val for val in options.values()):
+            print >> sys.stderr, "Arguments to the autoinstaller cannot contain spaces"
+            return 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 in vms:
+        host = vms[machine_name]['host']
+        print >> sys.stderr, ("machine '%s' is already running on host %s"
+                              % (machine_name, host))
+        return 1
+
+    host = choose_host()
+    print 'Creating on host %s...' % host
+    sys.stdout.flush()
+    return call(['remctl', host, 'remote', 'control',
+                 machine_name, operation] + args)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+
+# vim:et:sw=4:ts=4
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listhost
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listhost	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listhost	(revision 1160)
@@ -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 <machine>"
+        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
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listvms
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listvms	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listvms	(revision 1160)
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+"""
+Collates the results of listvms from multiple VM servers.  Part of the xvm
+suite.
+"""
+
+from invirt.remote import bcast
+import sys
+import yaml
+
+def main(argv):
+    # Query each of the hosts.
+    results = filter(lambda (_, x): x is not None, bcast('listvms'))
+
+    # Merge the results and print.
+    merged = {}
+    for server, result in results:
+        for data in result.itervalues():
+            data['host'] = server
+        merged.update(result)
+
+    print yaml.dump(merged, Dumper=yaml.CSafeDumper, default_flow_style=False)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+
+# vim:et:sw=4:ts=4
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listvmsd
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listvmsd	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-listvmsd	(revision 1160)
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+# NOTE: In development; not actually used yet.
+
+#Collates the results of listvms from multiple VM servers.  Part of the xvm
+#suite.
+
+use Net::Remctl ();
+use JSON;
+
+our @servers = qw/black-mesa.mit.edu sx-blade-2.mit.edu/;
+
+our %connections;
+
+sub openConnections() {
+    foreach (@servers) { openConnection($_); }
+}
+
+sub openConnection($) {
+    my ($server) = @_;
+    my $remctl = Net::Remctl->new;
+    $remctl->open($server)
+        or die "Cannot connect to $server: ", $remctl->error, "\n";
+    $connections{$server} = $remctl;
+}
+
+sub doListVMs() {
+    foreach my $remctl (values %connections) {
+	$remctl->command("remote", "web", "listvms", "--json");
+    }
+    my %vmstate;
+    foreach my $server (keys %connections) {
+	my $remctl = $connections{$server};
+	my $jsonData = '';
+	do {
+	    $output = $remctl->output;
+	    if ($output->type eq 'output') {
+		if ($output->stream == 1) {
+		    $jsonData .= $output->data;
+		} elsif ($output->stream == 2) {
+		    print STDERR $output->data;
+		}
+	    } elsif ($output->type eq 'error') {
+		warn $output->error, "\n";
+	    } elsif ($output->type eq 'status') {
+		if ($output->status != 0) {
+		    warn "Exit status was ".$output->status;
+		}
+	    } elsif ($output->type eq 'done') {
+		#next;
+	    } else {
+		die "Unknown output token from library: ", $output->type, "\n";
+	    }
+	} while ($output->type ne 'done');
+	my $vmlist = jsonToObj($jsonData);
+	foreach my $key (keys %$vmlist) {
+	    $vmstate{$key} = $vmlist->{$key};
+	    $vmstate{$key}{"host"} = $server;
+	}
+    }
+    return %vmstate;
+}
+
+openConnections();
+
+use Data::Dumper;
+use Benchmark;
+print Dumper({doListVMs()});
+timethis(100, sub {doListVMs()});
+
+# vim:et:sw=4:ts=4
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy	(revision 1160)
@@ -0,0 +1,26 @@
+#!/bin/bash
+# invoke as sipb-xen-remote-proxy-$TYPE, with "TYPE" in the remctl sense.
+
+klist -s || kinit -k
+
+TYPE="${0##*-}"
+case "$TYPE" in
+    control )
+	MACHINE="$1"; SERVICE="$2"; shift; shift ;;
+    * )
+	SERVICE="$1"; shift ;;
+esac
+
+case "$TYPE/$SERVICE" in
+    web/listvms )
+	sipb-xen-remote-listvms "$@" ;;
+    control/create|control/install )
+	sipb-xen-remote-create "$SERVICE" "$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" "$@" ;;
+    * )
+	remctl "$(invirt-getconf hosts.0.hostname)" remote "$TYPE" "$SERVICE" "$@" ;;
+esac
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy-control
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy-control	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy-control	(revision 1160)
@@ -0,0 +1,1 @@
+link sipb-xen-remote-proxy
Index: package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy-web
===================================================================
--- package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy-web	(revision 1160)
+++ package_tags/sipb-xen-remote-server/0.10/files/usr/sbin/sipb-xen-remote-proxy-web	(revision 1160)
@@ -0,0 +1,1 @@
+link sipb-xen-remote-proxy
