|
Last change
on this file since 558 was
558,
checked in by andersk, 17 years ago
|
|
Open remctl pipes in parallel.
|
-
Property svn:executable set to
*
|
|
File size:
1.0 KB
|
| Rev | Line | |
|---|
| [538] | 1 | #!/usr/bin/env python2.5 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Collates the results of listvms from multiple VM servers. Part of the xvm |
|---|
| 5 | suite. |
|---|
| 6 | """ |
|---|
| 7 | |
|---|
| 8 | from itertools import chain |
|---|
| 9 | from subprocess import CalledProcessError, PIPE, Popen |
|---|
| [549] | 10 | from sys import argv, stdout |
|---|
| [552] | 11 | from yaml import safe_dump, safe_load |
|---|
| [538] | 12 | |
|---|
| 13 | ### |
|---|
| 14 | |
|---|
| 15 | def 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 |
|---|
| [558] | 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: raise CalledProcessError(p.returncode, cmd) |
|---|
| 26 | results = [ safe_load(o) for o in outputs ] |
|---|
| [538] | 27 | results = filter( lambda x: x is not None, results ) |
|---|
| 28 | |
|---|
| 29 | # Merge the results and print. |
|---|
| 30 | merged = {} |
|---|
| 31 | for result in results: merged.update(result) |
|---|
| [552] | 32 | print safe_dump(merged, default_flow_style=False) |
|---|
| [538] | 33 | |
|---|
| 34 | if __name__ == '__main__': |
|---|
| 35 | main(argv) |
|---|
| 36 | |
|---|
| 37 | # vim:et:sw=2:ts=2 |
|---|
Note: See
TracBrowser
for help on using the repository browser.