From 89a799a34437c126d3b70aaefd0d93597a30ff72 Mon Sep 17 00:00:00 2001 From: Arzhel Younsi Date: Thu, 19 Jan 2017 19:07:59 +0800 Subject: [PATCH 1/8] Add VRF support to traceroute and IOS --- napalm_ios/ios.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index e84f2ba..fcaae52 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1496,7 +1496,7 @@ def get_snmp_information(self): snmp_dict['chassis_id'] = snmp_chassis return snmp_dict - def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5): + def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5, vrf=''): """ Execute ping on the device and returns a dictionary with the result. @@ -1516,7 +1516,11 @@ def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5): * rtt (float) """ ping_dict = {} - command = 'ping {}'.format(destination) + # vrf needs to be right after the ping command + if vrf: + command = 'ping vrf {} {}'.format(vrf, destination) + else: + command = 'ping {}'.format(destination) command += ' timeout {}'.format(timeout) command += ' size {}'.format(size) command += ' repeat {}'.format(count) @@ -1567,7 +1571,7 @@ def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5): return ping_dict def traceroute(self, destination, source=C.TRACEROUTE_SOURCE, - ttl=C.TRACEROUTE_TTL, timeout=C.TRACEROUTE_TIMEOUT): + ttl=C.TRACEROUTE_TTL, timeout=C.TRACEROUTE_TIMEOUT, vrf=C.TRACEROUTE_VRF): """ Executes traceroute on the device and returns a dictionary with the result. @@ -1588,7 +1592,11 @@ def traceroute(self, destination, source=C.TRACEROUTE_SOURCE, * host_name (str) """ - command = "traceroute {}".format(destination) + # vrf needs to be right after the traceroute command + if vrf: + command = "traceroute vrf {} {}".format(vrf, destination) + else: + command = "traceroute {}".format(destination) if source: command += " source {}".format(source) if ttl: From 48c17cb5dfaf1e45afbfc0c18e15d14f4502e2fb Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Tue, 31 Jan 2017 10:10:10 -0600 Subject: [PATCH 2/8] adding conversion to standard mac addr format --- napalm_ios/ios.py | 6 ++- .../normal/expected_result.json | 16 ++++---- .../static_arp_entry/expected_result.json | 16 ++++---- .../normal/expected_result.json | 6 +-- .../2960_format/expected_result.json | 4 +- .../3560_format/expected_result.json | 2 +- .../4500_format/expected_result.json | 2 +- .../4948_format/expected_result.json | 2 +- .../6500_format/expected_result.json | 4 +- .../6500_format2/expected_result.json | 2 +- .../alt_show_cmd/expected_result.json | 38 +++++++++---------- .../normal/expected_result.json | 38 +++++++++---------- 12 files changed, 69 insertions(+), 67 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 44d7513..b79cde4 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -27,6 +27,7 @@ from napalm_base.exceptions import ReplaceConfigException, MergeConfigException from napalm_base.utils import py23_compat import napalm_base.constants as C +import napalm_base.helpers # Easier to store these as constants HOUR_SECONDS = 3600 @@ -847,6 +848,7 @@ def get_interfaces(self): match_mac = re.match(mac_regex, interface_output, flags=re.DOTALL) group_mac = match_mac.groupdict() mac_address = group_mac["mac_address"] + mac_address = napalm_base.helpers.convert(napalm_base.helpers.mac, mac_address) interface_list[interface]['mac_address'] = py23_compat.text_type(mac_address) except AttributeError: interface_list[interface]['mac_address'] = u'N/A' @@ -1341,7 +1343,7 @@ def get_arp_table(self): raise ValueError("Invalid MAC Address detected: {}".format(mac)) entry = { 'interface': interface, - 'mac': mac, + 'mac': napalm_base.helpers.convert(napalm_base.helpers.mac, mac), 'ip': address, 'age': age } @@ -1503,7 +1505,7 @@ def process_mac_fields(vlan, mac, mac_type, interface): else: active = False return { - 'mac': mac, + 'mac': napalm_base.helpers.convert(napalm_base.helpers.mac, mac), 'interface': interface, 'vlan': int(vlan), 'static': static, diff --git a/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json b/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json index c8de3b1..7d7f096 100644 --- a/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json @@ -1,41 +1,41 @@ [{ "interface": "Vlan20", "ip": "172.29.50.1", - "mac": "84b8.0276.ac0e", + "mac": "84:B8:02:76:AC:0E", "age": 8.0 }, { "interface": "Vlan20", "ip": "172.29.50.2", - "mac": "0019.0725.344a", + "mac": "00:19:07:25:34:4A", "age": 221.0 }, { "interface": "Vlan20", "ip": "172.29.50.3", - "mac": "0024.f7dd.7741", + "mac": "00:24:F7:DD:77:41", "age": 0.0 }, { "interface": "Vlan20", "ip": "172.29.50.10", - "mac": "6805.ca12.71c2", + "mac": "68:05:CA:12:71:C2", "age": 37.0 }, { "interface": "Vlan41", "ip": "172.29.52.33", - "mac": "84b8.0276.ac0e", + "mac": "84:B8:02:76:AC:0E", "age": 61.0 }, { "interface": "Vlan41", "ip": "172.29.52.34", - "mac": "0024.f7dd.7743", + "mac": "00:24:F7:DD:77:43", "age": 0.0 }, { "interface": "Vlan41", "ip": "172.29.52.40", - "mac": "a099.9b1c.dfa7", + "mac": "A0:99:9B:1C:DF:A7", "age": 3.0 }, { "interface": "Vlan41", "ip": "192.168.81.34", - "mac": "0024.f7dd.7743", + "mac": "00:24:F7:DD:77:43", "age": 0.0 }] diff --git a/test/unit/mocked_data/test_get_arp_table/static_arp_entry/expected_result.json b/test/unit/mocked_data/test_get_arp_table/static_arp_entry/expected_result.json index de89360..191713e 100644 --- a/test/unit/mocked_data/test_get_arp_table/static_arp_entry/expected_result.json +++ b/test/unit/mocked_data/test_get_arp_table/static_arp_entry/expected_result.json @@ -1,41 +1,41 @@ [{ "interface": "", "ip": "172.29.50.1", - "mac": "84b8.0276.ac0e", + "mac": "84:B8:02:76:AC:0E", "age": 8.0 }, { "interface": "Vlan20", "ip": "172.29.50.2", - "mac": "0019.0725.344a", + "mac": "00:19:07:25:34:4A", "age": 221.0 }, { "interface": "Vlan20", "ip": "172.29.50.3", - "mac": "0024.f7dd.7741", + "mac": "00:24:F7:DD:77:41", "age": 0.0 }, { "interface": "Vlan20", "ip": "172.29.50.10", - "mac": "6805.ca12.71c2", + "mac": "68:05:CA:12:71:C2", "age": 37.0 }, { "interface": "Vlan41", "ip": "172.29.52.33", - "mac": "84b8.0276.ac0e", + "mac": "84:B8:02:76:AC:0E", "age": 61.0 }, { "interface": "Vlan41", "ip": "172.29.52.34", - "mac": "0024.f7dd.7743", + "mac": "00:24:F7:DD:77:43", "age": 0.0 }, { "interface": "Vlan41", "ip": "172.29.52.40", - "mac": "a099.9b1c.dfa7", + "mac": "A0:99:9B:1C:DF:A7", "age": 3.0 }, { "interface": "Vlan41", "ip": "192.168.81.34", - "mac": "0024.f7dd.7743", + "mac": "00:24:F7:DD:77:43", "age": 0.0 }] diff --git a/test/unit/mocked_data/test_get_interfaces/normal/expected_result.json b/test/unit/mocked_data/test_get_interfaces/normal/expected_result.json index 706c2b9..efe87cc 100644 --- a/test/unit/mocked_data/test_get_interfaces/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_interfaces/normal/expected_result.json @@ -1,7 +1,7 @@ { "GigabitEthernet3": { "speed": 1000, - "mac_address": "0800.2782.516b", + "mac_address": "08:00:27:82:51:6B", "is_up": false, "last_flapped": -1.0, "description": "N/A", @@ -9,7 +9,7 @@ }, "GigabitEthernet2": { "speed": 1000, - "mac_address": "0800.2779.e896", + "mac_address": "08:00:27:79:E8:96", "is_up": true, "last_flapped": -1.0, "description": "blah bleh", @@ -17,7 +17,7 @@ }, "GigabitEthernet1": { "speed": 1000, - "mac_address": "0800.27f8.e842", + "mac_address": "08:00:27:F8:E8:42", "is_up": true, "last_flapped": -1.0, "description": "N/A", diff --git a/test/unit/mocked_data/test_get_mac_address_table/2960_format/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/2960_format/expected_result.json index 5397daa..a84ff5b 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/2960_format/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/2960_format/expected_result.json @@ -2,7 +2,7 @@ "static": true, "active": false, "vlan": 0, - "mac": "1111.2222.3333", + "mac": "11:11:22:22:33:33", "interface": "", "moves": -1, "last_move": -1.0 @@ -11,7 +11,7 @@ "static": false, "active": true, "vlan": 6, - "mac": "0018.b974.528f", + "mac": "00:18:B9:74:52:8F", "interface": "Fa0/16", "moves": -1, "last_move": -1.0 diff --git a/test/unit/mocked_data/test_get_mac_address_table/3560_format/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/3560_format/expected_result.json index 87cd0a1..9ebdeb7 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/3560_format/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/3560_format/expected_result.json @@ -1 +1 @@ -[{"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0100.0ccc.cccc", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0100.0ccc.cccd", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0000", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0001", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0002", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0003", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0004", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0005", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0006", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0007", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0008", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0009", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.000a", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.000b", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.000c", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.000d", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.000e", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.000f", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "0180.c200.0010", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "ffff.ffff.ffff", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "000a.b82d.10e0", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/3", "last_move": -1.0, "active": true, "mac": "0012.80b6.4cd8", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0012.80b6.4cd9", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0014.6915.4100", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b921.9200", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/1", "last_move": -1.0, "active": true, "mac": "0018.b921.9278", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b974.528f", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/13", "last_move": -1.0, "active": true, "mac": "0019.0617.660f", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/14", "last_move": -1.0, "active": true, "mac": "0019.0617.6610", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/15", "last_move": -1.0, "active": true, "mac": "0019.0617.6611", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/19", "last_move": -1.0, "active": true, "mac": "001b.d450.970f", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/20", "last_move": -1.0, "active": true, "mac": "001b.d450.9710", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/21", "last_move": -1.0, "active": true, "mac": "001b.d450.9711", "moves": -1}, {"vlan": 4, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b974.528f", "moves": -1}, {"vlan": 45, "static": false, "interface": "Fa0/19", "last_move": -1.0, "active": true, "mac": "0018.b945.d5a9", "moves": -1}, {"vlan": 45, "static": false, "interface": "Fa0/5", "last_move": -1.0, "active": true, "mac": "0018.b945.f780", "moves": -1}, {"vlan": 45, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b974.528f", "moves": -1}, {"vlan": 56, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b945.f781", "moves": -1}, {"vlan": 56, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b974.528f", "moves": -1}, {"vlan": 56, "static": false, "interface": "Fa0/19", "last_move": -1.0, "active": true, "mac": "0019.069c.80e1", "moves": -1}, {"vlan": 6, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "0018.b974.528f", "moves": -1}, {"vlan": 6, "static": false, "interface": "Fa0/13", "last_move": -1.0, "active": true, "mac": "0019.069c.80e0", "moves": -1}] +[{"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:00:0C:CC:CC:CC", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:00:0C:CC:CC:CD", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:00", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:01", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:02", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:03", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:04", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:05", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:06", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:07", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:08", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:09", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:0A", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:0B", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:0C", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:0D", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:0E", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:0F", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "01:80:C2:00:00:10", "moves": -1}, {"vlan": 0, "static": true, "interface": "", "last_move": -1.0, "active": false, "mac": "FF:FF:FF:FF:FF:FF", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:0A:B8:2D:10:E0", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/3", "last_move": -1.0, "active": true, "mac": "00:12:80:B6:4C:D8", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:12:80:B6:4C:D9", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:14:69:15:41:00", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:21:92:00", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/1", "last_move": -1.0, "active": true, "mac": "00:18:B9:21:92:78", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:74:52:8F", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/13", "last_move": -1.0, "active": true, "mac": "00:19:06:17:66:0F", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/14", "last_move": -1.0, "active": true, "mac": "00:19:06:17:66:10", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/15", "last_move": -1.0, "active": true, "mac": "00:19:06:17:66:11", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/19", "last_move": -1.0, "active": true, "mac": "00:1B:D4:50:97:0F", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/20", "last_move": -1.0, "active": true, "mac": "00:1B:D4:50:97:10", "moves": -1}, {"vlan": 1, "static": false, "interface": "Fa0/21", "last_move": -1.0, "active": true, "mac": "00:1B:D4:50:97:11", "moves": -1}, {"vlan": 4, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:74:52:8F", "moves": -1}, {"vlan": 45, "static": false, "interface": "Fa0/19", "last_move": -1.0, "active": true, "mac": "00:18:B9:45:D5:A9", "moves": -1}, {"vlan": 45, "static": false, "interface": "Fa0/5", "last_move": -1.0, "active": true, "mac": "00:18:B9:45:F7:80", "moves": -1}, {"vlan": 45, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:74:52:8F", "moves": -1}, {"vlan": 56, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:45:F7:81", "moves": -1}, {"vlan": 56, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:74:52:8F", "moves": -1}, {"vlan": 56, "static": false, "interface": "Fa0/19", "last_move": -1.0, "active": true, "mac": "00:19:06:9C:80:E1", "moves": -1}, {"vlan": 6, "static": false, "interface": "Fa0/16", "last_move": -1.0, "active": true, "mac": "00:18:B9:74:52:8F", "moves": -1}, {"vlan": 6, "static": false, "interface": "Fa0/13", "last_move": -1.0, "active": true, "mac": "00:19:06:9C:80:E0", "moves": -1}] diff --git a/test/unit/mocked_data/test_get_mac_address_table/4500_format/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/4500_format/expected_result.json index a08408d..02d9b3a 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/4500_format/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/4500_format/expected_result.json @@ -1 +1 @@ -[{"moves": -1, "interface": "Port-channel1", "vlan": 1, "static": false, "mac": "30a3.30a3.a1c3", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1c4", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1c5", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1c6", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1c7", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1c8", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1c9", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30a3.30a3.a1ca", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Po1", "vlan": 1, "static": true, "mac": "0100.0ccc.ccce", "active": false, "last_move": -1.0}, {"moves": -1, "interface": "Po1", "vlan": 1, "static": true, "mac": "ffff.ffff.ffff", "active": false, "last_move": -1.0}, {"moves": -1, "interface": "", "vlan": 39, "static": true, "mac": "ffff.ffff.ffff", "active": false, "last_move": -1.0}] +[{"moves": -1, "interface": "Port-channel1", "vlan": 1, "static": false, "mac": "30:A3:30:A3:A1:C3", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:C4", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:C5", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:C6", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:C7", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:C8", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:C9", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Port-channel1", "vlan": 99, "static": false, "mac": "30:A3:30:A3:A1:CA", "active": true, "last_move": -1.0}, {"moves": -1, "interface": "Po1", "vlan": 1, "static": true, "mac": "01:00:0C:CC:CC:CE", "active": false, "last_move": -1.0}, {"moves": -1, "interface": "Po1", "vlan": 1, "static": true, "mac": "FF:FF:FF:FF:FF:FF", "active": false, "last_move": -1.0}, {"moves": -1, "interface": "", "vlan": 39, "static": true, "mac": "FF:FF:FF:FF:FF:FF", "active": false, "last_move": -1.0}] diff --git a/test/unit/mocked_data/test_get_mac_address_table/4948_format/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/4948_format/expected_result.json index 47417d8..53bebb6 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/4948_format/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/4948_format/expected_result.json @@ -2,7 +2,7 @@ "static": false, "active": true, "vlan": 999, - "mac": "1111.2222.3333", + "mac": "11:11:22:22:33:33", "interface": "Port-channel1", "moves": -1, "last_move": -1.0 diff --git a/test/unit/mocked_data/test_get_mac_address_table/6500_format/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/6500_format/expected_result.json index 86c76a4..477efcd 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/6500_format/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/6500_format/expected_result.json @@ -2,7 +2,7 @@ "static": false, "active": true, "vlan": 999, - "mac": "1111.2222.3333", + "mac": "11:11:22:22:33:33", "interface": "Port-channel1", "moves": -1, "last_move": -1.0 @@ -11,7 +11,7 @@ "static": false, "active": true, "vlan": 999, - "mac": "1111.2222.3333", + "mac": "11:11:22:22:33:33", "interface": "Port-channel2", "moves": -1, "last_move": -1.0 diff --git a/test/unit/mocked_data/test_get_mac_address_table/6500_format2/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/6500_format2/expected_result.json index 9be13e7..6b7fc52 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/6500_format2/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/6500_format2/expected_result.json @@ -1 +1 @@ -[{"last_move": -1.0, "vlan": 666, "moves": -1, "mac": "30a3.30a3.a1c3", "static": false, "interface": "Te1/30", "active": true}, {"last_move": -1.0, "vlan": 666, "moves": -1, "mac": "30a3.30a3.5ab8", "static": false, "interface": "Po3", "active": true}, {"last_move": -1.0, "vlan": 60, "moves": -1, "mac": "30a3.30a3.4d54", "static": false, "interface": "Te1/21", "active": true}, {"last_move": -1.0, "vlan": 777, "moves": -1, "mac": "0000.30a3.0167", "static": true, "interface": "", "active": false}, {"last_move": -1.0, "vlan": 664, "moves": -1, "mac": "30a3.30a3.58b5", "static": false, "interface": "Po6", "active": true}, {"last_move": -1.0, "vlan": 667, "moves": -1, "mac": "30a3.30a3.daf5", "static": false, "interface": "Te3/20", "active": true}, {"last_move": -1.0, "vlan": 668, "moves": -1, "mac": "30a3.30a3.e401", "static": false, "interface": "Po6", "active": true}, {"last_move": -1.0, "vlan": 669, "moves": -1, "mac": "30a3.30a3.5a22", "static": false, "interface": "Te3/20", "active": true}, {"last_move": -1.0, "vlan": 0, "moves": -1, "mac": "0000.0000.0000", "static": true, "interface": "", "active": false}] +[{"last_move": -1.0, "vlan": 666, "moves": -1, "mac": "30:A3:30:A3:A1:C3", "static": false, "interface": "Te1/30", "active": true}, {"last_move": -1.0, "vlan": 666, "moves": -1, "mac": "30:A3:30:A3:5A:B8", "static": false, "interface": "Po3", "active": true}, {"last_move": -1.0, "vlan": 60, "moves": -1, "mac": "30:A3:30:A3:4D:54", "static": false, "interface": "Te1/21", "active": true}, {"last_move": -1.0, "vlan": 777, "moves": -1, "mac": "00:00:30:A3:01:67", "static": true, "interface": "", "active": false}, {"last_move": -1.0, "vlan": 664, "moves": -1, "mac": "30:A3:30:A3:58:B5", "static": false, "interface": "Po6", "active": true}, {"last_move": -1.0, "vlan": 667, "moves": -1, "mac": "30:A3:30:A3:DA:F5", "static": false, "interface": "Te3/20", "active": true}, {"last_move": -1.0, "vlan": 668, "moves": -1, "mac": "30:A3:30:A3:E4:01", "static": false, "interface": "Po6", "active": true}, {"last_move": -1.0, "vlan": 669, "moves": -1, "mac": "30:A3:30:A3:5A:22", "static": false, "interface": "Te3/20", "active": true}, {"last_move": -1.0, "vlan": 0, "moves": -1, "mac": "00:00:00:00:00:00", "static": true, "interface": "", "active": false}] diff --git a/test/unit/mocked_data/test_get_mac_address_table/alt_show_cmd/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/alt_show_cmd/expected_result.json index ed12c29..f6c72ef 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/alt_show_cmd/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/alt_show_cmd/expected_result.json @@ -2,7 +2,7 @@ "static": false, "active": true, "vlan": 1, - "mac": "6400.f1cf.2cc6", + "mac": "64:00:F1:CF:2C:C6", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -10,7 +10,7 @@ "static": true, "active": false, "vlan": 1, - "mac": "a493.4cc1.67a7", + "mac": "A4:93:4C:C1:67:A7", "interface": "Vlan1", "moves": -1, "last_move": -1.0 @@ -18,7 +18,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "000c.2906.17d6", + "mac": "00:0C:29:06:17:D6", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -26,7 +26,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "000c.2913.421b", + "mac": "00:0C:29:13:42:1B", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -34,7 +34,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0018.0ab3.59f1", + "mac": "00:18:0A:B3:59:F1", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -42,7 +42,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0018.dd32.1f7c", + "mac": "00:18:DD:32:1F:7C", "interface": "FastEthernet6", "moves": -1, "last_move": -1.0 @@ -50,7 +50,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0025.64f5.d352", + "mac": "00:25:64:F5:D3:52", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -58,7 +58,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0026.abb9.a503", + "mac": "00:26:AB:B9:A5:03", "interface": "FastEthernet4", "moves": -1, "last_move": -1.0 @@ -66,7 +66,7 @@ "static": true, "active": false, "vlan": 100, - "mac": "a493.4cc1.67a7", + "mac": "A4:93:4C:C1:67:A7", "interface": "Vlan100", "moves": -1, "last_move": -1.0 @@ -74,7 +74,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "ac3a.7a1a.ba4b", + "mac": "AC:3A:7A:1A:BA:4B", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -82,7 +82,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "b0a7.376f.b3b4", + "mac": "B0:A7:37:6F:B3:B4", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -90,7 +90,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "bc5f.f435.fa0e", + "mac": "BC:5F:F4:35:FA:0E", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -98,7 +98,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "dc3a.5e67.1a98", + "mac": "DC:3A:5E:67:1A:98", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -106,7 +106,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "dc3a.5ee2.6a95", + "mac": "DC:3A:5E:E2:6A:95", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -114,7 +114,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "f04f.7c92.5a45", + "mac": "F0:4F:7C:92:5A:45", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -122,7 +122,7 @@ "static": false, "active": true, "vlan": 200, - "mac": "0009.b754.1a88", + "mac": "00:09:B7:54:1A:88", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -130,7 +130,7 @@ "static": false, "active": true, "vlan": 200, - "mac": "10bd.1801.a0b4", + "mac": "10:BD:18:01:A0:B4", "interface": "FastEthernet3", "moves": -1, "last_move": -1.0 @@ -138,7 +138,7 @@ "static": false, "active": true, "vlan": 200, - "mac": "204c.9ed7.cb80", + "mac": "20:4C:9E:D7:CB:80", "interface": "FastEthernet2", "moves": -1, "last_move": -1.0 @@ -146,7 +146,7 @@ "static": true, "active": false, "vlan": 200, - "mac": "a493.4cc1.67a7", + "mac": "A4:93:4C:C1:67:A7", "interface": "Vlan200", "moves": -1, "last_move": -1.0 diff --git a/test/unit/mocked_data/test_get_mac_address_table/normal/expected_result.json b/test/unit/mocked_data/test_get_mac_address_table/normal/expected_result.json index ed12c29..f6c72ef 100644 --- a/test/unit/mocked_data/test_get_mac_address_table/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_mac_address_table/normal/expected_result.json @@ -2,7 +2,7 @@ "static": false, "active": true, "vlan": 1, - "mac": "6400.f1cf.2cc6", + "mac": "64:00:F1:CF:2C:C6", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -10,7 +10,7 @@ "static": true, "active": false, "vlan": 1, - "mac": "a493.4cc1.67a7", + "mac": "A4:93:4C:C1:67:A7", "interface": "Vlan1", "moves": -1, "last_move": -1.0 @@ -18,7 +18,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "000c.2906.17d6", + "mac": "00:0C:29:06:17:D6", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -26,7 +26,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "000c.2913.421b", + "mac": "00:0C:29:13:42:1B", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -34,7 +34,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0018.0ab3.59f1", + "mac": "00:18:0A:B3:59:F1", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -42,7 +42,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0018.dd32.1f7c", + "mac": "00:18:DD:32:1F:7C", "interface": "FastEthernet6", "moves": -1, "last_move": -1.0 @@ -50,7 +50,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0025.64f5.d352", + "mac": "00:25:64:F5:D3:52", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -58,7 +58,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "0026.abb9.a503", + "mac": "00:26:AB:B9:A5:03", "interface": "FastEthernet4", "moves": -1, "last_move": -1.0 @@ -66,7 +66,7 @@ "static": true, "active": false, "vlan": 100, - "mac": "a493.4cc1.67a7", + "mac": "A4:93:4C:C1:67:A7", "interface": "Vlan100", "moves": -1, "last_move": -1.0 @@ -74,7 +74,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "ac3a.7a1a.ba4b", + "mac": "AC:3A:7A:1A:BA:4B", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -82,7 +82,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "b0a7.376f.b3b4", + "mac": "B0:A7:37:6F:B3:B4", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -90,7 +90,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "bc5f.f435.fa0e", + "mac": "BC:5F:F4:35:FA:0E", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -98,7 +98,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "dc3a.5e67.1a98", + "mac": "DC:3A:5E:67:1A:98", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -106,7 +106,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "dc3a.5ee2.6a95", + "mac": "DC:3A:5E:E2:6A:95", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -114,7 +114,7 @@ "static": false, "active": true, "vlan": 100, - "mac": "f04f.7c92.5a45", + "mac": "F0:4F:7C:92:5A:45", "interface": "Wlan-GigabitEthernet0", "moves": -1, "last_move": -1.0 @@ -122,7 +122,7 @@ "static": false, "active": true, "vlan": 200, - "mac": "0009.b754.1a88", + "mac": "00:09:B7:54:1A:88", "interface": "FastEthernet7", "moves": -1, "last_move": -1.0 @@ -130,7 +130,7 @@ "static": false, "active": true, "vlan": 200, - "mac": "10bd.1801.a0b4", + "mac": "10:BD:18:01:A0:B4", "interface": "FastEthernet3", "moves": -1, "last_move": -1.0 @@ -138,7 +138,7 @@ "static": false, "active": true, "vlan": 200, - "mac": "204c.9ed7.cb80", + "mac": "20:4C:9E:D7:CB:80", "interface": "FastEthernet2", "moves": -1, "last_move": -1.0 @@ -146,7 +146,7 @@ "static": true, "active": false, "vlan": 200, - "mac": "a493.4cc1.67a7", + "mac": "A4:93:4C:C1:67:A7", "interface": "Vlan200", "moves": -1, "last_move": -1.0 From 33f2cc8f03e399c191e394abe111bf862a19ff7d Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Wed, 1 Feb 2017 21:56:58 -0600 Subject: [PATCH 3/8] converting to use helpers.mac() directly --- napalm_ios/ios.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index b79cde4..9607db9 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -848,7 +848,7 @@ def get_interfaces(self): match_mac = re.match(mac_regex, interface_output, flags=re.DOTALL) group_mac = match_mac.groupdict() mac_address = group_mac["mac_address"] - mac_address = napalm_base.helpers.convert(napalm_base.helpers.mac, mac_address) + mac_address = napalm_base.helpers.mac(mac_address) interface_list[interface]['mac_address'] = py23_compat.text_type(mac_address) except AttributeError: interface_list[interface]['mac_address'] = u'N/A' @@ -1343,7 +1343,7 @@ def get_arp_table(self): raise ValueError("Invalid MAC Address detected: {}".format(mac)) entry = { 'interface': interface, - 'mac': napalm_base.helpers.convert(napalm_base.helpers.mac, mac), + 'mac': napalm_base.helpers.mac(mac), 'ip': address, 'age': age } @@ -1505,7 +1505,7 @@ def process_mac_fields(vlan, mac, mac_type, interface): else: active = False return { - 'mac': napalm_base.helpers.convert(napalm_base.helpers.mac, mac), + 'mac': napalm_base.helpers.mac(mac), 'interface': interface, 'vlan': int(vlan), 'static': static, From c7aea53d59036fa5b513ee118e24e6e6fd7fcd4a Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Mon, 6 Feb 2017 11:38:00 -0800 Subject: [PATCH 4/8] Better error handling on commit when archive is not enabled, fixes #10 --- napalm_ios/ios.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 9607db9..684ea29 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -360,6 +360,9 @@ def commit_config(self): if ('Failed to apply command' in output) or \ ('original configuration has been successfully restored' in output): raise ReplaceConfigException("Candidate config could not be applied") + elif '%Please turn config archive on' in output: + msg = "napalm-ios replace() requires Cisco 'archive' feature to be enabled." + raise ReplaceConfigException(msg) else: # Merge operation filename = self.merge_cfg From 122e9f97446f16e33693b108b1f1171d014e23bf Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Tue, 7 Feb 2017 01:09:53 -0500 Subject: [PATCH 5/8] Version 0.6.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c00f850..7032080 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="napalm-ios", - version="0.6.0", + version="0.6.1", packages=find_packages(), author="Kirk Byers", author_email="ktbyers@twb-tech.com", From 23104e3734b06516603ced5d76fc12c73be3dfb7 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 7 Feb 2017 11:43:11 -0800 Subject: [PATCH 6/8] Fix issue with show lldp neighbors and long names (stupid Cisco), Fixes #103 --- napalm_ios/ios.py | 58 ++++++++++++------- .../long_names/expected_result.json | 10 ++++ .../long_names/show_int_Gi1.txt | 28 +++++++++ .../long_names/show_int_Gi2.txt | 30 ++++++++++ .../long_names/show_lldp_neighbors.txt | 9 +++ .../show_lldp_neighbors_Gi1_detail.txt | 22 +++++++ 6 files changed, 137 insertions(+), 20 deletions(-) create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/long_names/expected_result.json create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi1.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi2.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors_Gi1_detail.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 684ea29..d4b4e5d 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -579,7 +579,22 @@ def get_lldp_neighbors(self): for lldp_entry in split_output.splitlines(): # Example, twb-sf-hpsw1 Fa4 120 B 17 - device_id, local_int_brief, hold_time, capability, remote_port = lldp_entry.split() + try: + device_id, local_int_brief, hold_time, capability, remote_port = lldp_entry.split() + except ValueError: + # Check for long names (device_id is 20 chars long) + if len(lldp_entry.split()) == 4: + tmp_field, hold_time, capability, remote_port = lldp_entry.split() + device_id = tmp_field[:20] + local_int_brief = tmp_field[20:] + # device_id might be abbreviated, try to get full name + lldp_tmp = self._lldp_detail_parser(local_int_brief) + device_id_new = lldp_tmp[3][0] + # Verify abbreviated and full name are consistent + if device_id_new[:20] == device_id: + device_id = device_id_new + else: + raise ValueError("Unable to obtain remote device name") local_port = self._expand_interface_name(local_int_brief) entry = {'port': remote_port, 'hostname': device_id} @@ -588,6 +603,26 @@ def get_lldp_neighbors(self): return lldp + def _lldp_detail_parser(self, interface): + command = "show lldp neighbors {} detail".format(interface) + output = self._send_command(command) + + # Check if router supports the command + if '% Invalid input' in output: + raise ValueError("Command not supported by network device") + + port_id = re.findall(r"Port id:\s+(.+)", output) + port_description = re.findall(r"Port Description(?:\s\-|:)\s+(.+)", output) + chassis_id = re.findall(r"Chassis id:\s+(.+)", output) + system_name = re.findall(r"System Name:\s+(.+)", output) + system_description = re.findall(r"System Description:\s*\n(.+)", output) + system_capabilities = re.findall(r"System Capabilities:\s+(.+)", output) + enabled_capabilities = re.findall(r"Enabled Capabilities:\s+(.+)", output) + remote_address = re.findall(r"Management Addresses:\n\s+(?:IP|Other)(?::\s+?)(.+)", + output) + return [port_id, port_description, chassis_id, system_name, system_description, + system_capabilities, enabled_capabilities, remote_address] + def get_lldp_neighbors_detail(self, interface=''): """ IOS implementation of get_lldp_neighbors_detail. @@ -606,26 +641,9 @@ def get_lldp_neighbors_detail(self, interface=''): lldp_neighbors = {} for interface in lldp_neighbors: - command = "show lldp neighbors {} detail".format(interface) - output = self._send_command(command) - - # Check if router supports the command - if '% Invalid input' in output: - return {} - local_port = interface - port_id = re.findall(r"Port id:\s+(.+)", output) - port_description = re.findall(r"Port Description(?:\s\-|:)\s+(.+)", output) - chassis_id = re.findall(r"Chassis id:\s+(.+)", output) - system_name = re.findall(r"System Name:\s+(.+)", output) - system_description = re.findall(r"System Description:\s*\n(.+)", output) - system_capabilities = re.findall(r"System Capabilities:\s+(.+)", output) - enabled_capabilities = re.findall(r"Enabled Capabilities:\s+(.+)", output) - remote_address = re.findall(r"Management Addresses:\n\s+(?:IP|Other)(?::\s+?)(.+)", - output) - number_entries = len(port_id) - lldp_fields = [port_id, port_description, chassis_id, system_name, system_description, - system_capabilities, enabled_capabilities, remote_address] + lldp_fields = self._lldp_detail_parser(interface) + number_entries = len(lldp_fields[0]) # re.findall will return a list. Make sure same number of entries always returned. for test_list in lldp_fields: diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/long_names/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/expected_result.json new file mode 100644 index 0000000..c41d603 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/expected_result.json @@ -0,0 +1,10 @@ +{ + "GigabitEthernet1": [{ + "port": "17", + "hostname": "twb-sf-hpsw1.local.domain" + }], + "GigabitEthernet2": [{ + "port": "18", + "hostname": "twb-sf-hpsw2" + }] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi1.txt b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi1.txt new file mode 100644 index 0000000..2b6cdc9 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi1.txt @@ -0,0 +1,28 @@ +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 0800.27f8.e842 (bia 0800.27f8.e842) + Internet address is 10.0.2.15/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:42:01, output 00:00:05, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 1000 bits/sec, 1 packets/sec + 5 minute output rate 1000 bits/sec, 1 packets/sec + 14028 packets input, 1766902 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 9446 packets output, 1379617 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi2.txt b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi2.txt new file mode 100644 index 0000000..ef18819 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_int_Gi2.txt @@ -0,0 +1,30 @@ +GigabitEthernet2 is up, line protocol is up + Hardware is CSR vNIC, address is 0800.2779.e896 (bia 0800.2779.e896) + Description: blah bleh + Internet address is 192.168.0.1/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:04, output 00:00:05, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 118 packets input, 11502 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 177 packets output, 19267 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors.txt new file mode 100644 index 0000000..51bf156 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors.txt @@ -0,0 +1,9 @@ +Capability codes: + (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device + (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other + +Device ID Local Intf Hold-time Capability Port ID +twb-sf-hpsw1.local.dGi1 120 B 17 +twb-sf-hpsw2 Gi2 120 B 18 + +Total entries displayed: 2 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors_Gi1_detail.txt b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors_Gi1_detail.txt new file mode 100644 index 0000000..4844d20 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/long_names/show_lldp_neighbors_Gi1_detail.txt @@ -0,0 +1,22 @@ +------------------------------------------------ +Chassis id: 0018.fe1e.b020 +Port id: 17 +Port Description: 17 +System Name: twb-sf-hpsw1.local.domain + +System Description: +ProCurve J9019A Switch 2510-24, revision Q.10.01, ROM Q.10.02 (/sw/code/build/harp(harp)) + +Time remaining: 93 seconds +System Capabilities: B +Enabled Capabilities: B +Management Addresses: + IP: 10.220.88.10 +Auto Negotiation - not supported +Physical media capabilities - not advertised +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + + +Total entries displayed: 1 + From 66a9143c0cc02f4abfa844b382308f11e2448ba9 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 7 Feb 2017 12:13:44 -0800 Subject: [PATCH 7/8] Fixes show lldp neighbors issue with missing capability, fixes # 86 --- napalm_ios/ios.py | 27 ++++++++++------- .../missing_capability/expected_result.json | 10 +++++++ .../missing_capability/show_int_Gi1.txt | 28 +++++++++++++++++ .../missing_capability/show_int_Gi2.txt | 30 +++++++++++++++++++ .../show_lldp_neighbors.txt | 9 ++++++ .../show_lldp_neighbors_Gi1_detail.txt | 22 ++++++++++++++ 6 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/expected_result.json create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi1.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi2.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors_Gi1_detail.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index d4b4e5d..ba7cce2 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -582,19 +582,24 @@ def get_lldp_neighbors(self): try: device_id, local_int_brief, hold_time, capability, remote_port = lldp_entry.split() except ValueError: - # Check for long names (device_id is 20 chars long) if len(lldp_entry.split()) == 4: - tmp_field, hold_time, capability, remote_port = lldp_entry.split() - device_id = tmp_field[:20] - local_int_brief = tmp_field[20:] - # device_id might be abbreviated, try to get full name - lldp_tmp = self._lldp_detail_parser(local_int_brief) - device_id_new = lldp_tmp[3][0] - # Verify abbreviated and full name are consistent - if device_id_new[:20] == device_id: - device_id = device_id_new + # Four fields might be long_name or missing capability + capability_missing = True if lldp_entry[46] == ' ' else False + if capability_missing: + device_id, local_int_brief, hold_time, remote_port = lldp_entry.split() else: - raise ValueError("Unable to obtain remote device name") + # Might be long_name issue + tmp_field, hold_time, capability, remote_port = lldp_entry.split() + device_id = tmp_field[:20] + local_int_brief = tmp_field[20:] + # device_id might be abbreviated, try to get full name + lldp_tmp = self._lldp_detail_parser(local_int_brief) + device_id_new = lldp_tmp[3][0] + # Verify abbreviated and full name are consistent + if device_id_new[:20] == device_id: + device_id = device_id_new + else: + raise ValueError("Unable to obtain remote device name") local_port = self._expand_interface_name(local_int_brief) entry = {'port': remote_port, 'hostname': device_id} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/expected_result.json new file mode 100644 index 0000000..444ecce --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/expected_result.json @@ -0,0 +1,10 @@ +{ + "GigabitEthernet1": [{ + "port": "17", + "hostname": "twb-sf-hpsw1" + }], + "GigabitEthernet2": [{ + "port": "18", + "hostname": "twb-sf-hpsw2" + }] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi1.txt b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi1.txt new file mode 100644 index 0000000..2b6cdc9 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi1.txt @@ -0,0 +1,28 @@ +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 0800.27f8.e842 (bia 0800.27f8.e842) + Internet address is 10.0.2.15/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:42:01, output 00:00:05, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 1000 bits/sec, 1 packets/sec + 5 minute output rate 1000 bits/sec, 1 packets/sec + 14028 packets input, 1766902 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 9446 packets output, 1379617 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi2.txt b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi2.txt new file mode 100644 index 0000000..ef18819 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_int_Gi2.txt @@ -0,0 +1,30 @@ +GigabitEthernet2 is up, line protocol is up + Hardware is CSR vNIC, address is 0800.2779.e896 (bia 0800.2779.e896) + Description: blah bleh + Internet address is 192.168.0.1/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:04, output 00:00:05, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 118 packets input, 11502 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 177 packets output, 19267 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors.txt new file mode 100644 index 0000000..aaa46af --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors.txt @@ -0,0 +1,9 @@ +Capability codes: + (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device + (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other + +Device ID Local Intf Hold-time Capability Port ID +twb-sf-hpsw1 Gi1 120 17 +twb-sf-hpsw2 Gi2 120 B 18 + +Total entries displayed: 2 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors_Gi1_detail.txt b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors_Gi1_detail.txt new file mode 100644 index 0000000..4844d20 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/missing_capability/show_lldp_neighbors_Gi1_detail.txt @@ -0,0 +1,22 @@ +------------------------------------------------ +Chassis id: 0018.fe1e.b020 +Port id: 17 +Port Description: 17 +System Name: twb-sf-hpsw1.local.domain + +System Description: +ProCurve J9019A Switch 2510-24, revision Q.10.01, ROM Q.10.02 (/sw/code/build/harp(harp)) + +Time remaining: 93 seconds +System Capabilities: B +Enabled Capabilities: B +Management Addresses: + IP: 10.220.88.10 +Auto Negotiation - not supported +Physical media capabilities - not advertised +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + + +Total entries displayed: 1 + From 2afdfec2d57a7cf002d2822c29d5d47d38c09fa2 Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Wed, 8 Feb 2017 20:23:33 +0000 Subject: [PATCH 8/8] Correcting spaces vs two-space tabs. And use base constants --- napalm_ios/ios.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index fcaae52..a153b06 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1496,7 +1496,8 @@ def get_snmp_information(self): snmp_dict['chassis_id'] = snmp_chassis return snmp_dict - def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5, vrf=''): + def ping(self, destination, source=C.PING_SOURCE, ttl=C.PING_TTL, timeout=C.PING_TIMEOUT, + size=C.PING_SIZE, count=C.PING_COUNT, vrf=C.PING_VRF): """ Execute ping on the device and returns a dictionary with the result. @@ -1594,9 +1595,9 @@ def traceroute(self, destination, source=C.TRACEROUTE_SOURCE, # vrf needs to be right after the traceroute command if vrf: - command = "traceroute vrf {} {}".format(vrf, destination) + command = "traceroute vrf {} {}".format(vrf, destination) else: - command = "traceroute {}".format(destination) + command = "traceroute {}".format(destination) if source: command += " source {}".format(source) if ttl: