4 Collates the results of listvms from multiple VM servers. Part of the xvm
8 from subprocess import PIPE, Popen
15 # Query each of the server for their VMs.
16 # TODO get `servers` from a real list of all the VM hosts (instead of
17 # hardcoding the list here)
18 servers = ['black-mesa.mit.edu', 'sx-blade-2.mit.edu']
20 pipes = [Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE)
21 for server in servers]
22 outputs = [p.communicate()[0] for p in pipes]
25 raise RuntimeError("Command '%s' returned non-zero exit status %d"
26 % ('remctl', p.returncode))
27 results = [yaml.load(o, yaml.CSafeLoader) 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:
35 print yaml.dump(merged, Dumper=yaml.CSafeDumper, default_flow_style=False)
37 if __name__ == '__main__':