How to use the napalm.base.helpers.canonical_interface_name 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 / test / base / test_helpers.py View on Github external
def test_canonical_interface_name(self):
        """Test the canonical_interface_name helper function."""
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("Fa0/1"), "FastEthernet0/1"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("FastEthernet0/1"),
            "FastEthernet0/1",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("TenGig1/1/1.5"),
            "TenGigabitEthernet1/1/1.5",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("Gi1/2"), "GigabitEthernet1/2"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("HundredGigE105/1/1"),
            "HundredGigabitEthernet105/1/1",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("Lo0"), "Loopback0"
        )
github napalm-automation / napalm / test / base / test_helpers.py View on Github external
self.assertEqual(
            napalm.base.helpers.canonical_interface_name("TenGig1/1/1.5"),
            "TenGigabitEthernet1/1/1.5",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("Gi1/2"), "GigabitEthernet1/2"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("HundredGigE105/1/1"),
            "HundredGigabitEthernet105/1/1",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("Lo0"), "Loopback0"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("lo0"), "Loopback0"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("no_match0/1"), "no_match0/1"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name(
                "lo10", addl_name_map={"lo": "something_custom"}
            ),
            "something_custom10",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name(
                "uniq0/1/1", addl_name_map={"uniq": "something_custom"}
            ),
            "something_custom0/1/1",
        )
github napalm-automation / napalm / test / base / test_helpers.py View on Github external
)
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("HundredGigE105/1/1"),
            "HundredGigabitEthernet105/1/1",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("Lo0"), "Loopback0"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("lo0"), "Loopback0"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name("no_match0/1"), "no_match0/1"
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name(
                "lo10", addl_name_map={"lo": "something_custom"}
            ),
            "something_custom10",
        )
        self.assertEqual(
            napalm.base.helpers.canonical_interface_name(
                "uniq0/1/1", addl_name_map={"uniq": "something_custom"}
            ),
            "something_custom0/1/1",
        )
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
process_mac_fields(vlan, mac, mac_type, single_interface)
                        )
                else:
                    mac_address_table.append(
                        process_mac_fields(vlan, mac, mac_type, interface)
                    )
            # Cat4500 format
            elif re.search(RE_MACTABLE_4500_1, line) and len(line.split()) == 5:
                vlan, mac, mac_type, _, interface = line.split()
                mac_address_table.append(
                    process_mac_fields(vlan, mac, mac_type, interface)
                )
            # Cat4500 w/PHY interface in Mac Table. Vlan will be -1.
            elif re.search(RE_MACTABLE_4500_3, line) and len(line.split()) == 5:
                interface, mac, mac_type, _, _ = line.split()
                interface = canonical_interface_name(interface)
                vlan = "-1"
                mac_address_table.append(
                    process_mac_fields(vlan, mac, mac_type, interface)
                )
            # Cat2960 format - ignore extra header line
            elif re.search(r"^Vlan\s+Mac Address\s+", line):
                continue
            # Cat2960 format (Cat4500 format multicast entries)
            elif (
                re.search(RE_MACTABLE_2960_1, line)
                or re.search(RE_MACTABLE_GEN_1, line)
            ) and len(line.split()) == 4:
                vlan, mac, mac_type, interface = line.split()
                if "," in interface:
                    interfaces = interface.split(",")
                    fill_down_vlan = vlan
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
return {}

        split_output = split_output.strip()

        for optics_entry in split_output.splitlines():
            # Example, Te1/0/1      34.6       3.29      -2.0      -3.5
            try:
                split_list = optics_entry.split()
            except ValueError:
                return {}

            int_brief = split_list[0]
            output_power = split_list[3]
            input_power = split_list[4]

            port = canonical_interface_name(int_brief)

            port_detail = {"physical_channels": {"channel": []}}

            # If interface is shutdown it returns "N/A" as output power.
            # Converting that to -100.0 float
            try:
                float(output_power)
            except ValueError:
                output_power = -100.0

            # Defaulting avg, min, max values to -100.0 since device does not
            # return these values
            optic_states = {
                "index": 0,
                "state": {
                    "input_power": {
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
fill_down_vlan = vlan
                    fill_down_mac = mac
                    fill_down_mac_type = mac_type
                    for single_interface in interfaces:
                        mac_address_table.append(process_mac_fields(vlan, mac, mac_type,
                                                                    single_interface))
                else:
                    mac_address_table.append(process_mac_fields(vlan, mac, mac_type, interface))
            # Cat4500 format
            elif re.search(RE_MACTABLE_4500_1, line) and len(line.split()) == 5:
                vlan, mac, mac_type, _, interface = line.split()
                mac_address_table.append(process_mac_fields(vlan, mac, mac_type, interface))
            # Cat4500 w/PHY interface in Mac Table. Vlan will be -1.
            elif re.search(RE_MACTABLE_4500_3, line) and len(line.split()) == 5:
                interface, mac, mac_type, _, _ = line.split()
                interface = canonical_interface_name(interface)
                vlan = '-1'
                mac_address_table.append(process_mac_fields(vlan, mac, mac_type, interface))
            # Cat2960 format - ignore extra header line
            elif re.search(r"^Vlan\s+Mac Address\s+", line):
                continue
            # Cat2960 format (Cat4500 format multicast entries)
            elif (re.search(RE_MACTABLE_2960_1, line) or re.search(RE_MACTABLE_GEN_1, line)) and \
                    len(line.split()) == 4:
                vlan, mac, mac_type, interface = line.split()
                if ',' in interface:
                    interfaces = interface.split(',')
                    fill_down_vlan = vlan
                    fill_down_mac = mac
                    fill_down_mac_type = mac_type
                    for single_interface in interfaces:
                        mac_address_table.append(process_mac_fields(vlan, mac, mac_type,
github napalm-automation / napalm / napalm / nxos_ssh / nxos_ssh.py View on Github external
vlan = 0
                if (
                    interface.lower() == "cpu"
                    or re.search(r"router", interface.lower())
                    or re.search(r"switch", interface.lower())
                ):
                    interface = ""
            else:
                static = False
            if mac_type.lower() in ["dynamic"]:
                active = True
            else:
                active = False
            return {
                "mac": helpers.mac(mac),
                "interface": helpers.canonical_interface_name(interface),
                "vlan": int(vlan),
                "static": static,
                "active": active,
                "moves": -1,
                "last_move": -1.0,
            }
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
local_intf = lldp_entry.pop("local_interface") or lldp_interfaces[idx]
            # Convert any 'not advertised' to an empty string
            for field in lldp_entry:
                if "not advertised" in lldp_entry[field]:
                    lldp_entry[field] = ""
            # Add field missing on IOS
            lldp_entry["parent_interface"] = ""
            # Translate the capability fields
            lldp_entry["remote_system_capab"] = transform_lldp_capab(
                lldp_entry["remote_system_capab"]
            )
            lldp_entry["remote_system_enable_capab"] = transform_lldp_capab(
                lldp_entry["remote_system_enable_capab"]
            )
            # Turn the interfaces into their long version
            local_intf = canonical_interface_name(local_intf)
            lldp.setdefault(local_intf, [])
            lldp[local_intf].append(lldp_entry)

        return lldp
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
local_intf = lldp_entry.pop("local_interface") or lldp_interfaces[idx]
            # Convert any 'not advertised' to an empty string
            for field in lldp_entry:
                if "not advertised" in lldp_entry[field]:
                    lldp_entry[field] = ""
            # Add field missing on IOS
            lldp_entry["parent_interface"] = ""
            # Translate the capability fields
            lldp_entry["remote_system_capab"] = transform_lldp_capab(
                lldp_entry["remote_system_capab"]
            )
            lldp_entry["remote_system_enable_capab"] = transform_lldp_capab(
                lldp_entry["remote_system_enable_capab"]
            )
            # Turn the interfaces into their long version
            local_intf = canonical_interface_name(local_intf)
            lldp.setdefault(local_intf, [])
            lldp[local_intf].append(lldp_entry)

        return lldp