def parallel_run_os_command(self, cmdline_list, override_hostname_list, \ total_attempts, retry_interval, \ execute_parallelism, really_execute = True, \ debug_cmd = False) : ''' TBD ''' _status = 100 _xfmsg = "An error has occurred, but no error message was captured" _thread_pool = None _child_failure = False try : for _index in range(0, len(override_hostname_list)) : serial_mode = False # only used for debugging if not _thread_pool and not serial_mode : pool_key = 'ai_execute_with_parallelism_' + str(execute_parallelism) if pool_key not in self.thread_pools : _thread_pool = ThreadPool(int(execute_parallelism)) self.thread_pools[pool_key] = _thread_pool else : _thread_pool = self.thread_pools[pool_key] if serial_mode : if len(cmdline_list[_index]) > 0: _status, _fmsg, _object = \ self.retriable_run_os_command(cmdline_list[_index], \ override_hostname_list[_index], \ total_attempts, \ retry_interval, \ really_execute, \ debug_cmd, False) else : _status = 0 _xfmsg = "OK" if _status : _xfmsg = _fmsg _child_failure = True break else : if len(cmdline_list[_index]) > 0: _thread_pool.add_task(self.retriable_run_os_command, \ cmdline_list[_index], \ override_hostname_list[_index], \ total_attempts, retry_interval, \ really_execute, debug_cmd) if _thread_pool and not serial_mode: _xfmsg = '' _results = _thread_pool.wait_completion() if len(_results) : for (_status, _fmsg, _object) in _results : if int(_status) : _xfmsg += _fmsg _child_failure = True break if _child_failure : _status = 81717 else : _status = 0 except KeyboardInterrupt : _status = 42 _xfmsg = "CTRL-C interrupt" cbdebug("Signal children to abort...", True) if _thread_pool : _thread_pool.abort() except Exception, e : _status = 23 _xfmsg = str(e) if _thread_pool : _thread_pool.abort()
def parallel_run_os_command(self, cmdline_list, override_hostname_or_uuid_list, port_list, \ total_attempts, retry_interval, \ execute_parallelism, really_execute = True, \ debug_cmd = False, step = None, remaining_time = 100000, osci = False, get_hostname_using_key = False, ssh_keepalive = True) : ''' TBD ''' _status = 100 _xfmsg = "An error has occurred, but no error message was captured" _thread_pool = None _child_failure = False try: for _index in range(0, len(override_hostname_or_uuid_list)): serial_mode = False # only used for debugging if not _thread_pool and not serial_mode: pool_key = 'ai_execute_with_parallelism_' + str( execute_parallelism) if pool_key not in self.thread_pools: _thread_pool = ThreadPool(int(execute_parallelism)) self.thread_pools[pool_key] = _thread_pool else: _thread_pool = self.thread_pools[pool_key] if serial_mode: if len(cmdline_list[_index]) > 0: _status, _fmsg, _object = \ self.retriable_run_os_command(cmdline_list[_index], \ override_hostname_or_uuid_list[_index], \ total_attempts, \ retry_interval, \ really_execute, \ debug_cmd, \ False, \ step, \ False, \ port_list[_index], \ remaining_time, osci = osci, get_hostname_using_key = get_hostname_using_key, ssh_keepalive = ssh_keepalive ) else: _status = 0 _xfmsg = "OK" if _status: _xfmsg = _fmsg _child_failure = True break else: if len(cmdline_list[_index]) > 0: _thread_pool.add_task(self.retriable_run_os_command, \ cmdline_list[_index], \ override_hostname_or_uuid_list[_index], \ total_attempts, \ retry_interval, \ really_execute, \ debug_cmd, \ False, \ step, \ False, \ port_list[_index], \ remaining_time, \ osci = osci, \ get_hostname_using_key = get_hostname_using_key, ssh_keepalive = ssh_keepalive) if _thread_pool and not serial_mode: _xfmsg = '' _results = _thread_pool.wait_completion() if len(_results): for (_status, _fmsg, _object) in _results: if int(_status): _xfmsg += _fmsg _child_failure = True break if _child_failure: _status = 81717 else: _status = 0 except KeyboardInterrupt: _status = 42 _xfmsg = "CTRL-C interrupt" cbdebug("Signal children to abort...", True) if _thread_pool: _thread_pool.abort() except Exception as e: _status = 23 _xfmsg = str(e) if _thread_pool: _thread_pool.abort() finally: if _status: _msg = "Parallel run os command operation failure: " + _xfmsg cberr(_msg, True) else: _msg = "Parallel run os command success." cbdebug(_msg) return _status, _msg