def _merge_artifacts(self, at_object, strategy="latest", artifacts=None): """Gather and merge all artifacts associated with an object and its children :param at_object: object you want to merge :param strategy: strategies:- - latest: overwrite existing values with newer values - branch: each branched child gets its own sub-dictionary (todo) - min-branch: only branch children if conflict is detected (todo) :param artifacts: default to none :return: dictionary of merged artifact, used for constructing host """ logger.debug(f"Attempting to merge: {at_object.name}") if not artifacts: artifacts = {} if getattr(at_object, "artifacts", None): logger.debug(f"Found artifacts: {at_object.artifacts}") if strategy == "latest": artifacts = helpers.merge_dicts(artifacts, at_object.artifacts) if "workflow_nodes" in at_object.related: children = at_object.get_related("workflow_nodes").results for child in children: if child.type == "workflow_job_node": child_id = child.summary_fields.job.id child_obj = self.v2.jobs.get(id=child_id).results.pop() artifacts = self._merge_artifacts(child_obj, strategy, artifacts) return artifacts
def __init__(self, **kwargs): self._hosts = kwargs.pop("hosts", []) # if a nick was specified, pull in the resolved arguments if "nick" in kwargs: nick = kwargs.pop("nick") kwargs = helpers.merge_dicts(kwargs, helpers.resolve_nick(nick)) # determine the provider actions based on kwarg parameters self._provider_actions = {} for key, action in PROVIDER_ACTIONS.items(): if key in kwargs: self._provider_actions[key] = action self._kwargs = kwargs
def _merge_artifacts(self, at_object, strategy="last", artifacts=None): """Gather and merge all artifacts associated with an object and its children :param at_object: object you want to merge :param strategy: strategies: - merge: merge artifact dictionaries together - branch: each branched child gets its own sub-dictionary (todo) - min-branch: only branch children if conflict is detected (todo) :param artifacts: default to none :return: dictionary of merged artifact, used for constructing host """ logger.debug(f"Attempting to merge: {at_object.name}") if not artifacts: artifacts = {} if getattr(at_object, "artifacts", None): logger.debug(f"Found artifacts: {at_object.artifacts}") if strategy == "merge": artifacts = helpers.merge_dicts(artifacts, at_object.artifacts) elif strategy == "last": artifacts = at_object.artifacts if "workflow_nodes" in at_object.related: children = at_object.get_related("workflow_nodes").results # filter out children with no associated job children = list( filter( lambda child: getattr(child.summary_fields, "job", None), children ) ) children.sort(key=lambda child: child.summary_fields.job.id) if strategy == "last": children = children[-1:] for child in children: if child.type == "workflow_job_node": logger.debug(child) child_id = child.summary_fields.job.id child_obj = self.v2.jobs.get(id=child_id).results if child_obj: child_obj = child_obj.pop() artifacts = ( self._merge_artifacts(child_obj, strategy, artifacts) or artifacts ) else: logger.warning( f"Unable to pull information from child job with id {child_id}." ) return artifacts
def __init__(self, **kwargs): self._hosts = kwargs.pop("hosts", []) self.host_classes = {"host": Host} # if a nick was specified, pull in the resolved arguments logger.debug(f"Broker instantiated with {kwargs=}") if "nick" in kwargs: nick = kwargs.pop("nick") kwargs = helpers.merge_dicts(kwargs, helpers.resolve_nick(nick)) logger.debug(f"kwargs after nick resolution {kwargs=}") if "host_classes" in kwargs: self.host_classes.update(kwargs.pop("host_classes")) # determine the provider actions based on kwarg parameters self._provider_actions = {} for key, action in PROVIDER_ACTIONS.items(): if key in kwargs: self._provider_actions[key] = action self._kwargs = kwargs