1 #!/usr/bin/env python2.5
4 Collates the results of listvms from multiple VM servers. Part of the xvm
8 from itertools import chain
9 from subprocess import CalledProcessError, PIPE, Popen
10 from sys import argv, stdout
11 from yaml import safe_dump, safe_load
16 # Query each of the server for their VMs.
17 # TODO get `servers` from a real list of all the VM hosts (instead of
18 # hardcoding the list here)
19 servers = ['black-mesa.mit.edu', 'sx-blade-2.mit.edu']
21 pipes = [Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE)
22 for server in servers]
23 outputs = [p.communicate()[0] for p in pipes]
26 raise CalledProcessError(p.returncode, cmd)
27 results = [safe_load(o) for o in outputs]
28 results = filter(lambda x: x is not None, results)
30 # Merge the results and print.
32 for result in results:
34 print safe_dump(merged, default_flow_style=False)
36 if __name__ == '__main__':