source: trunk/packages/sipb-xen-base/files/usr/share/python-support/sipb-xen-base/invirt/ @ 816

Last change on this file since 816 was 816, checked in by y_z, 16 years ago
  • use invirt.config to get hostnames
  • refactoring: extracted bcast() function into invirt.remote package
  • fixed os.rename import bug
  • using correct default paths in invirt-getconf
File size: 811 bytes
1from subprocess import PIPE, Popen
2from invirt.config import structs as config
3import yaml
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,
12              Popen(['remctl', host, 'remote', 'web', cmd], stdout=PIPE))
13             for host in hosts]
14    outputs = [(s, p.communicate()[0]) for (s, p) in pipes]
15    for (s, p) in pipes:
16        if p.returncode != 0:
17            raise RuntimeError("remctl to host %s returned non-zero exit status %d"
18                               % (s, p.returncode))
19    return [(s, yaml.load(o, yaml.CSafeLoader)) for (s, o) in outputs]
Note: See TracBrowser for help on using the repository browser.