def worker_ping(rank, nodes): '''ping a single node''' node = nodes[rank] nodename = NODESET.get_nodename_from_interface(node) packets_received = 0 # execute ping command and show output with the nodename cmd = '%s %s' % (synctool_param.PING_CMD, node) cmd_arr = shlex.split(cmd) f = synctool_lib.popen(cmd_arr) if not f: stderr('failed to run command %s' % cmd_arr[0]) return while True: line = f.readline() if not line: break line = string.strip(line) # # argh, we have to parse output here # ping says something like: # "2 packets transmitted, 0 packets received, 100.0% packet loss" on BSD # "2 packets transmitted, 0 received, 100.0% packet loss, time 1001ms" on Linux # arr = string.split(line) if len(arr) > 3 and arr[1] == 'packets' and arr[2] == 'transmitted,': try: packets_received = int(arr[3]) except ValueError: pass break # some ping implementations say "hostname is alive" or "hostname is unreachable" elif len(arr) == 3 and arr[1] == 'is': if arr[2] == 'alive': packets_received = 100 elif arr[2] == 'unreachable': packets_received = -1 f.close() if packets_received > 0: print '%s: up' % nodename else: print '%s: not responding' % nodename
def run(cmd_args): '''pipe the output through the aggregator''' # # simply re-run this command, but with a pipe # if '-a' in cmd_args: cmd_args.remove('-a') if '--aggregate' in cmd_args: cmd_args.remove('--aggregate') f = popen(cmd_args) if not f: stderr('failed to run %s' % cmd_args[0]) aggregate(f) f.close()