How to use the napalm.base.helpers.find_txt 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
system_time_xpath = ".//SystemTime/Uptime"
        platform_attr_xpath = ".//RackTable/Rack/Attributes/BasicInfo"
        system_time_tree = facts_rpc_reply.xpath(system_time_xpath)[0]
        try:
            platform_attr_tree = facts_rpc_reply.xpath(platform_attr_xpath)[0]
        except IndexError:
            platform_attr_tree = facts_rpc_reply.xpath(platform_attr_xpath)

        hostname = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(system_time_tree, "Hostname")
        )
        uptime = napalm.base.helpers.convert(
            int, napalm.base.helpers.find_txt(system_time_tree, "Uptime"), -1
        )
        serial = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(platform_attr_tree, "SerialNumber")
        )
        os_version = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(platform_attr_tree, "SoftwareRevision")
        )
        model = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(platform_attr_tree, "ModelName")
        )
        interface_list = sorted(list(self.get_interfaces().keys()))

        facts.update(
            {
                "os_version": os_version,
                "hostname": hostname,
                "model": model,
                "uptime": uptime,
                "serial_number": serial,
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
napalm.base.helpers.find_txt(
                        neighbor, "AFData/Entry/PrefixesAccepted"
                    ),
                    0,
                )
                suppressed_prefix_count = napalm.base.helpers.convert(
                    int,
                    napalm.base.helpers.find_txt(
                        neighbor, "AFData/Entry/PrefixesDenied"
                    ),
                    0,
                )
                received_prefix_count = accepted_prefix_count + suppressed_prefix_count
                advertised_prefix_count = napalm.base.helpers.convert(
                    int,
                    napalm.base.helpers.find_txt(
                        neighbor, "AFData/Entry/PrefixesAdvertised"
                    ),
                    0,
                )
                suppress_4byte_as = (
                    napalm.base.helpers.find_txt(neighbor, "Suppress4ByteAs") == "true"
                )
                local_as_prepend = (
                    napalm.base.helpers.find_txt(neighbor, "LocalASNoPrepend") != "true"
                )
                holdtime = (
                    napalm.base.helpers.convert(
                        int, napalm.base.helpers.find_txt(neighbor, "HoldTime"), 0
                    )
                    or vrf_holdtime
                )
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
def get_mac_address_table(self):

        mac_table = []

        rpc_command = (
            ""
        )

        result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))

        for mac_entry in result_tree.xpath(".//L2FIBMACDetailTable/L2FIBMACDetail"):
            mac_raw = napalm.base.helpers.find_txt(mac_entry, "Naming/Address")
            vlan = napalm.base.helpers.convert(
                int,
                napalm.base.helpers.find_txt(mac_entry, "Naming/Name", "").replace(
                    "vlan", ""
                ),
                0,
            )
            interface = napalm.base.helpers.find_txt(
                mac_entry, "Segment/AC/InterfaceHandle", ""
            )

            mac_table.append(
                {
                    "mac": napalm.base.helpers.mac(mac_raw),
                    "interface": interface,
                    "vlan": vlan,
                    "active": True,
                    "static": False,
                    "moves": 0,
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
.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(
                        neighbor, "AFData/Entry/PrefixesDenied"
                    ),
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
)
                            or napalm.base.helpers.find_txt(
                                bgp_path, "PathInformation/NeighborAddress/IPV6Address"
                            )
                        )
                        as_path = " ".join(
                            [
                                bgp_as.text
                                for bgp_as in bgp_path.xpath(
                                    "AttributesAfterPolicyIn/CommonAttributes/NeighborAS/Entry"
                                )
                            ]
                        )
                        next_hop = napalm.base.helpers.find_txt(
                            bgp_path, "PathInformation/NextHop/IPV4Address"
                        ) or napalm.base.helpers.find_txt(
                            bgp_path, "PathInformation/NextHop/IPV6Address"
                        )
                        single_route_details["current_active"] = best_path
                        single_route_details["next_hop"] = next_hop
                        single_route_details["protocol_attributes"] = {
                            "local_preference": local_preference,
                            "as_path": as_path,
                            "remote_as": remote_as,
                            "remote_address": remote_address,
                        }
                    routes[destination].append(single_route_details)
            else:
                first_route = True
                for route_entry in route.xpath("RoutePath/Entry"):
                    # get all possible entries
                    next_hop = napalm.base.helpers.find_txt(route_entry, "Address")
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
instance_active_list = bgp_neighbors_vrf_all_tree.xpath(
            ".//InstanceTable/Instance/InstanceActive/VRFTable/VRF"
        )

        for vrf_tree in instance_active_list:
            vrf_name = napalm.base.helpers.find_txt(vrf_tree, "Naming/VRFName")
            vrf_keepalive = napalm.base.helpers.convert(
                int,
                napalm.base.helpers.find_txt(
                    instance_active_list, "GlobalProcessInfo/VRF/KeepAliveTime"
                ),
            )
            vrf_holdtime = napalm.base.helpers.convert(
                int,
                napalm.base.helpers.find_txt(
                    instance_active_list, "GlobalProcessInfo/VRF/HoldTime"
                ),
            )
            if vrf_name not in bgp_neighbors_detail.keys():
                bgp_neighbors_detail[vrf_name] = {}
            for neighbor in vrf_tree.xpath("NeighborTable/Neighbor"):
                up = (
                    napalm.base.helpers.find_txt(neighbor, "ConnectionState")
                    == "BGP_ST_ESTAB"
                )
                local_as = napalm.base.helpers.convert(
                    int, napalm.base.helpers.find_txt(neighbor, "LocalAS"), 0
                )
                remote_as = napalm.base.helpers.convert(
                    int, napalm.base.helpers.find_txt(neighbor, "RemoteAS"), 0
                )
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
def get_ntp_servers(self):

        ntp_servers = {}

        rpc_command = ""

        result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))

        for version in ["IPV4", "IPV6"]:
            xpath = ".//Peer{version}Table/Peer{version}".format(version=version)
            for peer in result_tree.xpath(xpath):
                peer_type = napalm.base.helpers.find_txt(
                    peer, "PeerType{version}/Naming/PeerType".format(version=version)
                )
                if peer_type != "Server":
                    continue
                server_address = napalm.base.helpers.find_txt(
                    peer, "Naming/Address{version}".format(version=version)
                )
                if not server_address:
                    continue
                ntp_servers[server_address] = {}

        return ntp_servers
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
# must check
            description = napalm.base.helpers.find_txt(bgp_group, "Description")
            import_policy = napalm.base.helpers.find_txt(
                bgp_group, "NeighborGroupAFTable/NeighborGroupAF/RoutePolicyIn"
            )
            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
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
platform_attr_tree = facts_rpc_reply.xpath(platform_attr_xpath)

        hostname = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(system_time_tree, "Hostname")
        )
        uptime = napalm.base.helpers.convert(
            int, napalm.base.helpers.find_txt(system_time_tree, "Uptime"), -1
        )
        serial = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(platform_attr_tree, "SerialNumber")
        )
        os_version = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(platform_attr_tree, "SoftwareRevision")
        )
        model = napalm.base.helpers.convert(
            str, napalm.base.helpers.find_txt(platform_attr_tree, "ModelName")
        )
        interface_list = sorted(list(self.get_interfaces().keys()))

        facts.update(
            {
                "os_version": os_version,
                "hostname": hostname,
                "model": model,
                "uptime": uptime,
                "serial_number": serial,
                "fqdn": hostname,
                "interface_list": interface_list,
            }
        )

        return facts
github napalm-automation / napalm / napalm / iosxr / iosxr.py View on Github external
probes_config = (
            self.get_probes_config()
        )  # need to retrieve also the configuration
        # source and tag/test_name not provided

        for probe in sla_results_tree.xpath(".//Operation"):
            probe_name = napalm.base.helpers.find_txt(probe, "Naming/OperationID")
            test_name = list(probes_config.get(probe_name).keys())[0]
            target = napalm.base.helpers.find_txt(
                probe,
                "History/Target/LifeTable/Life/BucketTable/Bucket[0]/TargetAddress\
                /IPv4AddressTarget",
            )
            source = probes_config.get(probe_name).get(test_name, {}).get("source", "")
            probe_type = _PROBE_TYPE_XML_TAG_MAP_.get(
                napalm.base.helpers.find_txt(
                    probe, "Statistics/Latest/Target/SpecificStats/op_type"
                )
            )
            probe_count = (
                probes_config.get(probe_name).get(test_name, {}).get("probe_count", 0)
            )
            response_times = probe.xpath(
                "History/Target/LifeTable/Life[last()]/BucketTable/Bucket/ResponseTime"
            )
            response_times = [
                napalm.base.helpers.convert(
                    int, napalm.base.helpers.find_txt(response_time, ".", "0")
                )
                for response_time in response_times
            ]
            rtt = 0.0