How to use the napalm.base.helpers.convert function in napalm

To help you get started, we’ve selected a few napalm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
if results_error:
            return {"error": results_error}

        traceroute_result["success"] = {}

        last_hop_index = 1
        last_probe_index = 1
        last_probe_ip_address = "*"
        last_probe_host_name = ""
        last_hop_dict = {"probes": {}}

        for thanks_cisco in results_tree[0].getchildren():
            tag_name = thanks_cisco.tag
            tag_value = thanks_cisco.text
            if tag_name == "HopIndex":
                new_hop_index = napalm.base.helpers.convert(
                    int, napalm.base.helpers.find_txt(thanks_cisco, ".", "-1")
                )
                if last_hop_index and last_hop_index != new_hop_index:
                    traceroute_result["success"][last_hop_index] = copy.deepcopy(
                        last_hop_dict
                    )
                    last_hop_dict = {"probes": {}}
                    last_probe_ip_address = "*"
                    last_probe_host_name = ""
                last_hop_index = new_hop_index
                continue
            tag_value = napalm.base.helpers.find_txt(thanks_cisco, ".", "")
            if tag_name == "ProbeIndex":
                last_probe_index = napalm.base.helpers.convert(int, tag_value, 0) + 1
                if last_probe_index not in last_hop_dict.get("probes").keys():
                    last_hop_dict["probes"][last_probe_index] = {}
github napalm-automation / napalm / napalm / eos / eos.py View on Github external
str, item["export_policy"]
                )
                item["last_event"] = napalm.base.helpers.convert(
                    str, item["last_event"]
                )
                item["remote_address"] = napalm.base.helpers.ip(item["remote_address"])
                item["previous_connection_state"] = napalm.base.helpers.convert(
                    str, item["previous_connection_state"]
                )
                item["import_policy"] = napalm.base.helpers.convert(
                    str, item["import_policy"]
                )
                item["connection_state"] = napalm.base.helpers.convert(
                    str, item["connection_state"]
                )
                item["routing_table"] = napalm.base.helpers.convert(
                    str, item["routing_table"]
                )
                item["router_id"] = napalm.base.helpers.ip(item["router_id"])
                item["local_address"] = napalm.base.helpers.convert(
                    napalm.base.helpers.ip, item["local_address"]
                )

                peer_details.append(item)

            return peer_details
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
if "NotFound" not in bgp_path.keys():
                        best_path = (
                            napalm.base.helpers.find_txt(
                                bgp_path, "PathInformation/IsBestPath"
                            )
                            == "true"
                        )
                        local_preference = napalm.base.helpers.convert(
                            int,
                            napalm.base.helpers.find_txt(
                                bgp_path,
                                "AttributesAfterPolicyIn/CommonAttributes/LocalPreference",
                            ),
                            0,
                        )
                        local_preference = napalm.base.helpers.convert(
                            int,
                            napalm.base.helpers.find_txt(
                                bgp_path,
                                "AttributesAfterPolicyIn/CommonAttributes/LocalPreference",
                            ),
                            0,
                        )
                        remote_as = napalm.base.helpers.convert(
                            int,
                            napalm.base.helpers.find_txt(
                                bgp_path,
                                "AttributesAfterPolicyIn/CommonAttributes/NeighborAS",
                            ),
                            0,
                        )
                        remote_address = napalm.base.helpers.ip(
github napalm-automation / napalm / napalm / junos / junos.py View on Github external
def get_probes_config(self):
        """Return the configuration of the RPM probes."""
        probes = {}

        probes_table = junos_views.junos_rpm_probes_config_table(self.device)
        probes_table.get(options={"database": self.junos_config_database})
        probes_table_items = probes_table.items()

        for probe_test in probes_table_items:
            test_name = str(probe_test[0])
            test_details = {p[0]: p[1] for p in probe_test[1]}
            probe_name = napalm.base.helpers.convert(
                str, test_details.pop("probe_name")
            )
            target = napalm.base.helpers.convert(str, test_details.pop("target", ""))
            test_interval = napalm.base.helpers.convert(
                int, test_details.pop("test_interval", "0")
            )
            probe_count = napalm.base.helpers.convert(
                int, test_details.pop("probe_count", "0")
            )
            probe_type = napalm.base.helpers.convert(
                str, test_details.pop("probe_type", "")
            )
            source = napalm.base.helpers.convert(
                str, test_details.pop("source_address", "")
            )
            if probe_name not in probes.keys():
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
export_policy = napalm.base.helpers.find_txt(
                bgp_group, "NeighborGroupAFTable/NeighborGroupAF/RoutePolicyOut"
            )
            multipath = (
                napalm.base.helpers.find_txt(
                    bgp_group, "NeighborGroupAFTable/NeighborGroupAF/Multipath"
                )
                == "true"
            )
            peer_as = napalm.base.helpers.convert(
                int, napalm.base.helpers.find_txt(bgp_group, "RemoteAS/AS_YY"), 0
            )
            local_as = napalm.base.helpers.convert(
                int, napalm.base.helpers.find_txt(bgp_group, "LocalAS/AS_YY"), 0
            )
            multihop_ttl = napalm.base.helpers.convert(
                int,
                napalm.base.helpers.find_txt(bgp_group, "EBGPMultihop/MaxHopCount"),
                0,
            )
            local_addr_raw = napalm.base.helpers.find_txt(
                bgp_group, "LocalAddress/LocalIPAddress/IPV4Address"
            ) or napalm.base.helpers.find_txt(
                bgp_group, "LocalAddress/LocalIPAddress/IPV6Address"
            )
            local_address = napalm.base.helpers.convert(
                napalm.base.helpers.ip, local_addr_raw, local_addr_raw
            )
            af_table = napalm.base.helpers.find_txt(
                bgp_group, "NeighborAFTable/NeighborAF/Naming/AFName"
            )
            prefix_limit = napalm.base.helpers.convert(
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
if not is_xrv:
            rpc_command = "\
            "
            result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))

            for node in result_tree.xpath(".//Node"):
                if (
                    napalm.base.helpers.find_txt(node, "Naming/NodeName/Slot")
                    == active_modules["RSP"][0]
                ):
                    available_ram = napalm.base.helpers.convert(
                        int,
                        napalm.base.helpers.find_txt(node, "Summary/SystemRAMMemory"),
                    )
                    free_ram = napalm.base.helpers.convert(
                        int,
                        napalm.base.helpers.find_txt(
                            node, "Summary/FreeApplicationMemory"
                        ),
                    )
                    break  # we're only looking at one of the RSP's

            if available_ram and free_ram:
                used_ram = available_ram - free_ram
                memory = {}
                memory["available_ram"] = available_ram
                memory["used_ram"] = used_ram
                environment_status["memory"] = memory

            #
            # Fans
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
connection_state = (
                    napalm.base.helpers.find_txt(neighbor, "ConnectionState")
                    .replace("BGP_ST_", "")
                    .title()
                )
                if connection_state == "Estab":
                    connection_state = "Established"
                previous_connection_state = napalm.base.helpers.convert(
                    str,
                    _BGP_STATE_.get(
                        napalm.base.helpers.find_txt(
                            neighbor, "PreviousConnectionState", "0"
                        )
                    ),
                )
                active_prefix_count = napalm.base.helpers.convert(
                    int,
                    napalm.base.helpers.find_txt(
                        neighbor, "AFData/Entry/NumberOfBestpaths"
                    ),
                    0,
                )
                accepted_prefix_count = napalm.base.helpers.convert(
                    int,
                    napalm.base.helpers.find_txt(
                        neighbor, "AFData/Entry/PrefixesAccepted"
                    ),
                    0,
                )
                suppressed_prefix_count = napalm.base.helpers.convert(
                    int,
                    napalm.base.helpers.find_txt(
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
"History/Target/LifeTable/Life[last()]/BucketTable/Bucket/ReturnCode"
            )
            return_codes = [
                napalm.base.helpers.find_txt(return_code, ".")
                for return_code in return_codes
            ]

            last_test_loss = 0.0
            if len(return_codes):
                last_test_loss = napalm.base.helpers.convert(
                    int,
                    100
                    * (
                        1
                        - return_codes.count("ipslaRetCodeOK")
                        / napalm.base.helpers.convert(float, len(return_codes))
                    ),
                )
            rms = napalm.base.helpers.convert(
                float,
                napalm.base.helpers.find_txt(
                    probe,
                    "Statistics/Aggregated/HourTable/Hour\
                    /Distributed/Target/DistributionIntervalTable/DistributionInterval/CommonStats\
                    /Sum2ResponseTime",
                ),
            )
            global_test_updates = napalm.base.helpers.convert(
                float,
                napalm.base.helpers.find_txt(
                    probe,
                    "Statistics/Aggregated/HourTable/Hour\
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
neighbor, "Naming/NeighborAddress/IPV6Address"
                    )
                )
                local_address_configured = (
                    napalm.base.helpers.find_txt(neighbor, "IsLocalAddressConfigured")
                    == "true"
                )
                local_address = napalm.base.helpers.ip(
                    napalm.base.helpers.find_txt(
                        neighbor, "ConnectionLocalAddress/IPV4Address"
                    )
                    or napalm.base.helpers.find_txt(
                        neighbor, "ConnectionLocalAddress/IPV6Address"
                    )
                )
                local_port = napalm.base.helpers.convert(
                    int, napalm.base.helpers.find_txt(neighbor, "ConnectionLocalPort")
                )
                remote_address = napalm.base.helpers.ip(
                    napalm.base.helpers.find_txt(
                        neighbor, "ConnectionRemoteAddress/IPV4Address"
                    )
                    or napalm.base.helpers.find_txt(
                        neighbor, "ConnectionRemoteAddress/IPV6Address"
                    )
                )
                remote_port = napalm.base.helpers.convert(
                    int, napalm.base.helpers.find_txt(neighbor, "ConnectionRemotePort")
                )
                multihop = (
                    napalm.base.helpers.find_txt(
                        neighbor, "IsExternalNeighborNotDirectlyConnected"