def filter_remediation(self, include_tags=None, exclude_tags=None): """ Run filter jobs, based on tags on self.remediation_config :param include_tags: type list :param exclude_tags: type list :return: self.facts['remediation_conig_raw'] -> type str """ remediation_text = str() if include_tags or exclude_tags is not None: include_tags = H.to_list(include_tags) exclude_tags = H.to_list(exclude_tags) for line in self.remediation_config.all_children_sorted_by_tags( include_tags, exclude_tags): remediation_text += line.cisco_style_text() remediation_text += '\n' else: for line in self.remediation_config.all_children(): remediation_text += line.cisco_style_text() remediation_text += '\n' self.facts["remediation_config_raw"] = remediation_text return self.facts["remediation_config_raw"]
def line_inclusion_test(self, include_tags, exclude_tags): """ Given the line_tags, include_tags, and exclude_tags, determine if the line should be included """ from hier_config.helpers import to_list include_tags_set = set(to_list(include_tags)) if self.tags.intersection(include_tags_set): if self.is_leaf and exclude_tags: exclude_tags_set = set(to_list(exclude_tags)) return not bool(self.tags.intersection(exclude_tags_set)) return True return False
def remove_tags(self, tags): """ Remove tags from self.tags """ tags = H.to_list(tags) # self._tags.difference_update(tags) self.tags.difference_update(tags)
def append_tags(self, tags): """ Add tags to self.tags """ tags = H.to_list(tags) # self._tags.update(tags) self.tags.update(tags)
def remove_tags(self, tags): """ Remove tags from self.tags """ from hier_config.helpers import to_list tags = to_list(tags) if self.is_branch: for child in self.children: child.remove_tags(tags) else: self._tags.difference_update(tags)
def append_tags(self, tags): """ Add tags to self.tags """ from hier_config.helpers import to_list tags = to_list(tags) if self.is_branch: for child in self.children: child.append_tags(tags) else: self._tags.update(tags)
def _lineage_eval_object_rules(rules, section): """ Evaluate a list of lineage object rules. All object rules must match in order to return True """ matches = 0 for rule in rules: if rule['test'] == 'new_in_config': if rule['expression'] == section.new_in_config: matches += 1 elif rule['test'] == 'negative_intersection_tags': rule['expression'] = H.to_list(rule['expression']) if not set(rule['expression']).intersection(section.tags): matches += 1 return matches == len(rules)