source: trunk/packages/sipb-xen-remote-server/files/usr/sbin/sipb-xen-remote-listvms @ 561

Last change on this file since 561 was 561, checked in by ecprice, 16 years ago

Style adjustments (4-space indentation, no spaces inside parens).

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/env python2.5
2
3"""
4Collates the results of listvms from multiple VM servers.  Part of the xvm
5suite.
6"""
7
8from itertools import chain
9from subprocess import CalledProcessError, PIPE, Popen
10from sys import argv, stdout
11from yaml import safe_dump, safe_load
12
13###
14
15def main(argv):
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']
20    # XXX
21    pipes = [Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE)
22             for server in servers]
23    outputs = [p.communicate()[0] for p in pipes]
24    for p in pipes:
25        if p.returncode != 0:
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)
29
30    # Merge the results and print.
31    merged = {}
32    for result in results:
33        merged.update(result)
34    print safe_dump(merged, default_flow_style=False)
35
36if __name__ == '__main__':
37    main(argv)
38
39# vim:et:sw=2:ts=4
Note: See TracBrowser for help on using the repository browser.