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

Last change on this file since 677 was 623, checked in by price, 16 years ago

note host in listvms

  • Property svn:executable set to *
File size: 1.2 KB
RevLine 
[562]1#!/usr/bin/python
[538]2
3"""
4Collates the results of listvms from multiple VM servers.  Part of the xvm
5suite.
6"""
7
[562]8from subprocess import PIPE, Popen
[563]9import sys
10import yaml
[538]11
12def main(argv):
[561]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']
17    # XXX
[623]18    pipes = [(server,
19              Popen(['remctl', server, 'remote', 'web', 'listvms'], stdout=PIPE))
[561]20             for server in servers]
[623]21    outputs = [(s, p.communicate()[0]) for (s, p) in pipes]
22    for (s, p) in pipes:
[561]23        if p.returncode != 0:
[623]24            raise RuntimeError("remctl to host %s returned non-zero exit status %d"
25                               % (s, p.returncode)) 
26    results = [(s, yaml.load(o, yaml.CSafeLoader)) for (s, o) in outputs]
27    results = filter(lambda (_, x): x is not None, results)
[538]28
[561]29    # Merge the results and print.
30    merged = {}
[623]31    for server, result in results:
32        for data in result.itervalues():
33            data['host'] = server
[561]34        merged.update(result)
[616]35
[564]36    print yaml.dump(merged, Dumper=yaml.CSafeDumper, default_flow_style=False)
[538]37
38if __name__ == '__main__':
[563]39    main(sys.argv)
[538]40
[617]41# vim:et:sw=4:ts=4
Note: See TracBrowser for help on using the repository browser.