def main(): f = "../device_list.yml" devices = cfg_load(f) if(devices is None): logger.error("Config file '%s' read error " % f) exit(1) logger.debug("\nStarted: %s" % (datetime.now())) # Create a queue for communication with child processes msg_queue = mp.Queue() # To execute command in parallel on multiple devices # create a separate (child) process for each device jobs = [] for device in devices: p = mp.Process(target=get_version, args=(device, msg_queue)) jobs.append(p) p.start() # Start the process # Get sub-process results from the output queue results = [] for p in jobs: results.append(msg_queue.get()) # Wait until all processes have terminated (making sure all # child processes have been terminated, no zombies left) for p in jobs: p.join() show_results(results) logger.debug("\nEnded: %s" % (datetime.now()))
def main(): f = "../device_list.yml" devices = cfg_load(f) if(devices is None): print("Config file '%s' read error: " % f) exit() print "TBD"
def dispatch_command(cfg_file, cmd_string, read_delay=1): """ Execute command on multiple devices, going one by one, collect and returns results. :param str cfg_file: path to the configuration file containing list of target devices. :param str cmd_string: CLI command to be executed. :param int read_delay: time to wait for the CLI command to complete. :return: command execution results collected from all the devices """ devices_info = cfg_load(cfg_file) if(devices_info is None): print("Config file '%s' read error " % cfg_load) exit(1) results = [] for item in devices_info: output = execute_command(item, cmd_string, read_delay) results.append(output) return results
def dispatch_command(cfg_file, cmd_string, read_delay=1): """ Dispatches command for asynchronous execution on multiple devices, then collects and returns results. :param str cfg_file: path to the configuration file containing list of target devices. :param str cmd_string: CLI command to be executed. :param int read_delay: time to wait for the CLI command to complete. :return: command execution results collected from all the devices """ devices_info = cfg_load(cfg_file) if(devices_info is None): print("Config file '%s' read error " % cfg_load) exit(1) # Create a queue for communication with child processes msg_queue = mp.Queue() # To execute command in parallel on multiple devices # create a separate (child) process for each device jobs = [] for item in devices_info: p = mp.Process(target=execute_command, args=(item, cmd_string, read_delay, msg_queue)) jobs.append(p) p.start() # Start the process # Get sub-process results from the output queue results = [] for p in jobs: results.append(msg_queue.get()) # Wait until all processes have terminated (making sure all # child processes have been terminated, no zombies left) for p in jobs: p.join() return results