def populate_facts(self, connection, ansible_facts, data=None):
        """Populate the facts for Ospf_interfaces network resource

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

        :rtype: dictionary
        :returns: facts
        """
        facts = {}
        objs = []

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

        # parse native config using the Ospf_interfaces template
        ospf_interfaces_parser = Ospf_interfacesTemplate(
            lines=data.splitlines(),
            module=self._module,
        )
        objs = list(ospf_interfaces_parser.parse().values())
        if objs:
            for item in objs:
                item["address_family"] = list(item["address_family"].values())
                if "address_family" in item:
                    for af in item["address_family"]:
                        if af.get("processes"):
                            af["processes"] = list(af["processes"].values())
                        if af.get("multi_areas"):
                            af["multi_areas"].sort()
                    item["address_family"] = sorted(item["address_family"],
                                                    key=lambda i: i["afi"])

            objs = sorted(
                objs,
                key=lambda i:
                [int(k) if k.isdigit() else k for k in i["name"].split("/")],
            )

        ansible_facts["ansible_network_resources"].pop("ospf_interfaces", None)

        params = utils.remove_empties(
            ospf_interfaces_parser.validate_config(
                self.argument_spec,
                {"config": objs},
                redact=True,
            ), )

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

        return ansible_facts
Beispiel #2
0
    def populate_facts(self, connection, ansible_facts, data=None):
        """ Populate the facts for Ospf_interfaces network resource

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

        :rtype: dictionary
        :returns: facts
        """
        facts = {}
        objs = []

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

        # parse native config using the Ospf_interfaces template
        ospf_interfaces_parser = Ospf_interfacesTemplate(
            lines=data.splitlines()
        )
        objs = list(ospf_interfaces_parser.parse().values())
        if objs:
            for item in objs:
                item["address_family"] = list(item["address_family"].values())
                for af in item["address_family"]:
                    if af.get("processes"):
                        af["processes"] = list(af["processes"].values())

        ansible_facts["ansible_network_resources"].pop("ospf_interfaces", None)

        params = utils.remove_empties(
            utils.validate_config(self.argument_spec, {"config": objs})
        )

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

        return ansible_facts
 def __init__(self, module):
     super(Ospf_interfaces, self).__init__(
         empty_fact_val=[],
         facts_module=Facts(module),
         module=module,
         resource="ospf_interfaces",
         tmplt=Ospf_interfacesTemplate(),
     )
     self.parsers = [
         "authentication",
         "authentication_key",
         "message_digest_key",
         "cost",
         "dead_interval",
         "hello_interval",
         "instance",
         "mtu_ignore",
         "network",
         "passive_interface",
         "priority",
         "retransmit_interval",
         "shutdown",
         "transmit_delay",
     ]