예제 #1
0
    def populate_facts(self, connection, ansible_facts, data=None):
        """Populate the facts for Ospfv3 network resource

        :param connection: the device connection
        :param ansible_facts: Facts dictionary
        :param data: previously collected conf

        :rtype: dictionary
        :returns: facts
        """
        facts = {}
        objs = []
        ospfv3_parser = Ospfv3Template(lines=[], module=self._module)

        if not data:
            data = self.get_config(connection)

        # split the config into instances of the resource
        resource_delim = "router ospfv3"
        find_pattern = r"(?:^|\n)%s.*?(?=(?:^|\n)%s|$)" % (
            resource_delim,
            resource_delim,
        )
        resources = [
            p.strip() for p in re.findall(find_pattern, data, re.DOTALL)
        ]

        # parse native config using the Ospfv3 template
        ospfv3_facts = {"processes": []}
        for resource in resources:
            ospfv3_parser = Ospfv3Template(lines=resource.splitlines(),
                                           module=self._module)
            objs = ospfv3_parser.parse()
            for key, sortv in [("address_family", "afi")]:
                if key in objs["processes"] and objs["processes"][key]:
                    objs["processes"][key] = list(
                        objs["processes"][key].values())

            for addr_family in objs["processes"]["address_family"]:
                if "areas" in addr_family:
                    addr_family["areas"] = list(addr_family["areas"].values())

            for addr_family in objs["processes"]["address_family"]:
                if not addr_family.get("afi"):
                    # global vars
                    objs["processes"].update(addr_family)
                    objs["processes"]["address_family"].remove(addr_family)

            ospfv3_facts["processes"].append(objs["processes"])

        ansible_facts["ansible_network_resources"].pop("ospfv3", None)
        params = ospfv3_parser.validate_config(self.argument_spec,
                                               {"config": ospfv3_facts},
                                               redact=True)
        params = utils.remove_empties(params)

        facts["ospfv3"] = params.get("config", [])
        ansible_facts["ansible_network_resources"].update(facts)

        return ansible_facts
예제 #2
0
 def __init__(self, module):
     super(Ospfv3, self).__init__(
         empty_fact_val={},
         facts_module=Facts(module),
         module=module,
         resource="ospfv3",
         tmplt=Ospfv3Template(),
     )
     self.parsers = [
         "vrf",
         "address_family",
         "adjacency",
         "auto_cost",
         "area.default_cost",
         "area.authentication",
         "area.encryption",
         "area.nssa",
         "area.ranges",
         "area.stub",
         "bfd",
         "default_information",
         "default_metric",
         "distance",
         "fips_restrictions",
         "graceful_restart",
         "graceful_restart_period",
         "graceful_restart_helper",
         "log_adjacency_changes",
         "max_metric",
         "maximum_paths",
         "passive_interface",
         "redistribute",
         "router_id",
         "shutdown",
         "timers.lsa",
         "timers.out_delay",
         "timers.pacing",
         "timers.throttle.lsa",
         "timers.throttle.spf",
     ]