4 Collates the results of listvms from multiple VM servers. Part of the xvm
8 from itertools import chain
9 from subprocess import PIPE, Popen
11 from subprocess import CalledProcessError
13 # Python 2.4 doesn't implement CalledProcessError
14 class CalledProcessError(Exception):
15 """This exception is raised when a process run by check_call() returns
16 a non-zero exit status. The exit status will be stored in the
17 returncode attribute."""
18 def __init__(self, returncode, cmd):
19 self.returncode = returncode
22 return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
23 from sys import argv, stdout
24 from yaml import safe_dump, safe_load
29 # Query each of the server for their VMs.
30 # TODO get `servers` from a real list of all the VM hosts (instead of
31 # hardcoding the list here)
32 servers = ['black-mesa.mit.edu', 'sx-blade-2.mit.edu']
34 pipes = [Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE)
35 for server in servers]
36 outputs = [p.communicate()[0] for p in pipes]
39 raise CalledProcessError(p.returncode, cmd)
40 results = [safe_load(o) for o in outputs]
41 results = filter(lambda x: x is not None, results)
43 # Merge the results and print.
45 for result in results:
47 print safe_dump(merged, default_flow_style=False)
49 if __name__ == '__main__':