Last change
on this file since 622 was
622,
checked in by price, 16 years ago
|
not worth defining an exception class for one invocation site
|
-
Property svn:executable set to
*
|
File size:
1.1 KB
|
Line | |
---|
1 | #!/usr/bin/python |
---|
2 | |
---|
3 | """ |
---|
4 | Collates the results of listvms from multiple VM servers. Part of the xvm |
---|
5 | suite. |
---|
6 | """ |
---|
7 | |
---|
8 | from subprocess import PIPE, Popen |
---|
9 | import sys |
---|
10 | import yaml |
---|
11 | |
---|
12 | ### |
---|
13 | |
---|
14 | def main(argv): |
---|
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'] |
---|
19 | # XXX |
---|
20 | pipes = [Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE) |
---|
21 | for server in servers] |
---|
22 | outputs = [p.communicate()[0] for p in pipes] |
---|
23 | for p in pipes: |
---|
24 | if p.returncode != 0: |
---|
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) |
---|
29 | |
---|
30 | # Merge the results and print. |
---|
31 | merged = {} |
---|
32 | for result in results: |
---|
33 | merged.update(result) |
---|
34 | |
---|
35 | print yaml.dump(merged, Dumper=yaml.CSafeDumper, default_flow_style=False) |
---|
36 | |
---|
37 | if __name__ == '__main__': |
---|
38 | main(sys.argv) |
---|
39 | |
---|
40 | # vim:et:sw=4:ts=4 |
---|
Note: See
TracBrowser
for help on using the repository browser.