| 
                Last change
                  on this file since 622 was
                  622,
                  checked in by price, 17 years ago
           | 
        
        
          | 
               
not worth defining an exception class for one invocation site 
 
           | 
        
        
          
            
              - 
                  Property svn:executable set to
                  
*
               
             
           | 
        
        | 
            File size:
            1.1 KB
           | 
      
      
        
  | Rev | Line |   | 
|---|
| [562] | 1 | #!/usr/bin/python | 
|---|
| [538] | 2 |  | 
|---|
 | 3 | """ | 
|---|
 | 4 | Collates the results of listvms from multiple VM servers.  Part of the xvm | 
|---|
 | 5 | suite. | 
|---|
 | 6 | """ | 
|---|
 | 7 |  | 
|---|
| [562] | 8 | from subprocess import PIPE, Popen | 
|---|
| [563] | 9 | import sys | 
|---|
 | 10 | import yaml | 
|---|
| [538] | 11 |  | 
|---|
 | 12 | ### | 
|---|
 | 13 |  | 
|---|
 | 14 | def main(argv): | 
|---|
| [561] | 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: | 
|---|
| [622] | 25 |             raise RuntimeError("Command '%s' returned non-zero exit status %d" | 
|---|
 | 26 |                                % ('remctl', p.returncode))  | 
|---|
| [563] | 27 |     results = [yaml.load(o, yaml.CSafeLoader) for o in outputs] | 
|---|
| [561] | 28 |     results = filter(lambda x: x is not None, results) | 
|---|
| [538] | 29 |  | 
|---|
| [561] | 30 |     # Merge the results and print. | 
|---|
 | 31 |     merged = {} | 
|---|
 | 32 |     for result in results: | 
|---|
 | 33 |         merged.update(result) | 
|---|
| [616] | 34 |  | 
|---|
| [564] | 35 |     print yaml.dump(merged, Dumper=yaml.CSafeDumper, default_flow_style=False) | 
|---|
| [538] | 36 |  | 
|---|
 | 37 | if __name__ == '__main__': | 
|---|
| [563] | 38 |     main(sys.argv) | 
|---|
| [538] | 39 |  | 
|---|
| [617] | 40 | # vim:et:sw=4:ts=4 | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.