source: trunk/packages/invirt-remote-server/python/remote/bcast.py @ 1684

Last change on this file since 1684 was 1601, checked in by broder, 16 years ago

Return the right output from remctls when doing a "broadcast"

File size: 974 bytes
RevLine 
[816]1from subprocess import PIPE, Popen
2from invirt.config import structs as config
3import yaml
4
5def bcast(cmd, hosts = [h.hostname for h in config.hosts]):
6    """
7    Given a command and a list of hostnames or IPs, issue the command to all
8    the nodes and return a list of (host, output) pairs (the order should be
9    the same as the order of the hosts).
10    """
11    pipes = [(host,
[1598]12              Popen(['remctl', host, 'remote', 'web', cmd], stdout=PIPE, stderr=PIPE))
[816]13             for host in hosts]
[1598]14    outputs = dict((s, p.communicate()) for (s, p) in pipes)
[816]15    for (s, p) in pipes:
16        if p.returncode != 0:
[1598]17            if outputs[s][1].startswith('remctl: cannot connect to %s' % s):
18                del outputs[s]
19            else:
20                raise RuntimeError("remctl to host %s returned non-zero exit status %d"
21                                   % (s, p.returncode))
[1601]22    return [(s, yaml.load(o[0], yaml.CSafeLoader)) for (s, o) in outputs.iteritems()]
Note: See TracBrowser for help on using the repository browser.