1 from subprocess import PIPE, Popen
2 from invirt.config import structs as config
5 hostnames = [ h.hostname for h in config.hosts ]
7 def monocast(args, hosts = hostnames, randomize = True):
9 Given a command and a list of hostnames or IPs, issue the command to each
10 node until it connects to one of the nodes.
13 host the command ran on
14 hosts that could not be contacted
20 hosts = random.sample(hosts, len(hosts))
23 pipe = Popen(['remctl', host, 'remote', 'web'] + args, stdout=PIPE, stderr=PIPE)
24 output = pipe.communicate()
25 if pipe.returncode != 0:
26 if output[1].startswith('remctl: cannot connect to %s' % host):
27 hostsdown.append(host)
29 #raise RuntimeError("remctl to host %s returned non-zero exit status %d; stderr:\n%s"
30 # % (host, pipe.returncode, output[1]))
31 return (host, hostsdown, pipe.returncode,) + output
33 return (host, hostsdown, pipe.returncode,) + output
34 raise RuntimeError("Failed to contact any hosts: tried %s" % (hostsdown, ))