4 Collates the results of listvms from multiple VM servers. Part of the xvm
8 from subprocess import PIPE, Popen
13 # Query each of the server for their VMs.
14 # TODO get `servers` from a real list of all the VM hosts (instead of
15 # hardcoding the list here)
16 servers = ['black-mesa.mit.edu', 'sx-blade-2.mit.edu']
19 Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE))
20 for server in servers]
21 outputs = [(s, p.communicate()[0]) for (s, p) in pipes]
24 raise RuntimeError("remctl to host %s returned non-zero exit status %d"
26 results = [(s, yaml.load(o, yaml.CSafeLoader)) for (s, o) in outputs]
27 results = filter(lambda (_, x): x is not None, results)
29 # Merge the results and print.
31 for server, result in results:
32 for data in result.itervalues():
36 print yaml.dump(merged, Dumper=yaml.CSafeDumper, default_flow_style=False)
38 if __name__ == '__main__':