def _process_pending_results(self, iterator, one_pass=False, max_passes=None): if not hasattr(self, "curr_host"): return super(StrategyModule, self)._process_pending_results(iterator, one_pass, max_passes) prev_host_state = iterator.get_host_state(self.curr_host) results = super(StrategyModule, self)._process_pending_results(iterator, one_pass) while self._need_debug(results): next_action = NextAction() dbg = Debugger(self, results, next_action) dbg.cmdloop() if next_action.result == NextAction.REDO: # rollback host state self.curr_tqm.clear_failed_hosts() iterator._host_states[self.curr_host.name] = prev_host_state if reduce(lambda total, res : res.is_failed() or total, results, False): self._tqm._stats.failures[self.curr_host.name] -= 1 elif reduce(lambda total, res : res.is_unreachable() or total, results, False): self._tqm._stats.dark[self.curr_host.name] -= 1 # redo super(StrategyModule, self)._queue_task(self.curr_host, self.curr_task, self.curr_task_vars, self.curr_play_context) results = super(StrategyModule, self)._process_pending_results(iterator, one_pass) elif next_action.result == NextAction.CONTINUE: break elif next_action.result == NextAction.EXIT: exit(1) return results
def _process_pending_results(self, iterator, one_pass=False, max_passes=None): if not hasattr(self, "curr_host"): return super(StrategyModule, self)._process_pending_results( iterator, one_pass, max_passes) prev_host_state = iterator.get_host_state(self.curr_host) results = super(StrategyModule, self)._process_pending_results(iterator, one_pass) while self._need_debug(results): next_action = NextAction() dbg = Debugger(self, results, next_action) dbg.cmdloop() if next_action.result == NextAction.REDO: # rollback host state self.curr_tqm.clear_failed_hosts() iterator._host_states[self.curr_host.name] = prev_host_state if reduce(lambda total, res: res.is_failed() or total, results, False): self._tqm._stats.failures[self.curr_host.name] -= 1 elif reduce(lambda total, res: res.is_unreachable() or total, results, False): self._tqm._stats.dark[self.curr_host.name] -= 1 # redo super(StrategyModule, self)._queue_task(self.curr_host, self.curr_task, self.curr_task_vars, self.curr_play_context) results = super(StrategyModule, self)._process_pending_results( iterator, one_pass) elif next_action.result == NextAction.CONTINUE: break elif next_action.result == NextAction.EXIT: exit(1) return results
def combine(*terms, **kwargs): recursive = kwargs.get('recursive', False) if len(kwargs) > 1 or (len(kwargs) == 1 and 'recursive' not in kwargs): raise errors.AnsibleFilterError("'recursive' is the only valid keyword argument") for t in terms: if not isinstance(t, dict): raise errors.AnsibleFilterError("|combine expects dictionaries, got " + repr(t)) if recursive: return reduce(merge_hash, terms) else: return dict(itertools.chain(*map(iteritems, terms)))
def extract(item, container, morekeys=None): from jinja2.runtime import Undefined value = container[item] if value is not Undefined and morekeys is not None: if not isinstance(morekeys, list): morekeys = [morekeys] try: value = reduce(lambda d, k: d[k], morekeys, value) except KeyError: value = Undefined() return value
def secondsToStr(t): # http://bytes.com/topic/python/answers/635958-handy-short-cut-formatting-elapsed-time-floating-point-seconds rediv = lambda ll, b: list(divmod(ll[0], b)) + ll[1:] return "%d:%02d:%02d.%03d" % tuple(reduce(rediv, [[t * 1000, ], 1000, 60, 60]))
def _need_debug(self, results): return reduce( lambda total, res: res.is_failed() or res.is_unreachable() or total, results, False)
def _need_debug(self, results): return reduce(lambda total, res : res.is_failed() or res.is_unreachable() or total, results, False)