From 5bc1bce26f7825d7f6a477a2ed282d0dd3407772 Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 30 Oct 2020 09:11:35 +0100 Subject: [PATCH 1/5] make get_facts sgx00 compatible --- napalm_s350/s350.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 092a458..f283b57 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -198,11 +198,19 @@ class S350Driver(NetworkDriver): show_int_st = self._send_command('show interface status') # os_version - for line in show_ver.splitlines(): - # First version line is the active version - if 'Version' in line: - _, os_version = line.split('Version: ') - break + # detect os ver > 2 + if 'Active-image' in show_ver: + for line in show_ver.splitlines(): + # First version line is the active version + if 'Version' in line: + _, os_version = line.split('Version: ') + break + else: + for line in show_ver.splitlines(): + if 'SW version' in line: + _, ver = line.split(' ') + os_version, _ = ver.split(' (') + break # hostname, uptime for line in show_sys.splitlines(): From d6bc004e28a32204f272ef87d2a9deb163887566 Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 30 Oct 2020 09:30:14 +0100 Subject: [PATCH 2/5] fix get_arp_table function on sgx50 devices possible output ``` vlan 1 gi8 192.168.1.1 9c:eb:e8:52:bd:7c dynamic ``` leads to value error --- napalm_s350/s350.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index f283b57..80f023e 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -149,6 +149,8 @@ class S350Driver(NetworkDriver): interface, ip, mac, _ = line.split() elif len(line.split()) == 5: _, interface, mac, _ = line.split() + elif len(line.split()) == 6: + _, _, interface, ip, mac, _ = line.split() else: raise ValueError('Unexpected output: {}'.format(line.split())) From 7a1f027cdb6d067bcb0a020df85ee1fcbe7e3b0d Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 30 Oct 2020 09:54:46 +0100 Subject: [PATCH 3/5] adjust get_arp_table function for compatibility with sgx00 series include is not available on sgx00 devices --- napalm_s350/s350.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 80f023e..ca01b2b 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -141,14 +141,17 @@ class S350Driver(NetworkDriver): """ arp_table = [] - output = self._send_command('show arp | include (static|dynamic)') + output = self._send_command('show arp') for line in output.splitlines(): # A VLAN may not be set for the entry + if 'vlan' not in line: + continue if len(line.split()) == 4: interface, ip, mac, _ = line.split() elif len(line.split()) == 5: - _, interface, mac, _ = line.split() + if1, if2, ip, mac, _ = line.split() + interface = "{} {}".format(if1, if2) elif len(line.split()) == 6: _, _, interface, ip, mac, _ = line.split() else: From 5a2d22302ad2d4a4af1961eb5c096377d85c41e3 Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 30 Oct 2020 10:31:42 +0100 Subject: [PATCH 4/5] adjust get_interfaces function for compatibility with sgx00 series include and begin are not available on sgx00 devices --- napalm_s350/s350.py | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index ca01b2b..3e4c92f 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -277,11 +277,11 @@ class S350Driver(NetworkDriver): """ interfaces = {} - show_status_output = self._send_command('show interfaces status | include (Up|Down)') + show_status_output = self._send_command('show interfaces status') show_description_output = self._send_command('show interfaces description') # Since the MAC address for all the local ports are equal, get the address # from the first port and use it everywhere. - show_system_output = self._send_command('show lldp local GigabitEthernet1 | begin Device\ ID') + show_system_output = self._send_command('show lldp local GigabitEthernet1') try: mac = show_system_output.splitlines()[0].split(':', maxsplit=1)[1].strip() @@ -289,33 +289,34 @@ class S350Driver(NetworkDriver): mac = '0' for status_line in show_status_output.splitlines(): - interface, _, _, speed, _, _, link_state, _, _ = status_line.split() + if 'Up' in status_line or 'Down' in status_line: + interface, _, _, speed, _, _, link_state, _, _ = status_line.split() - if speed == '--': - is_enabled = False - speed = 0 - else: - is_enabled = True - speed = int(speed) + if speed == '--': + is_enabled = False + speed = 0 + else: + is_enabled = True + speed = int(speed) - is_up = (link_state == 'Up') + is_up = (link_state == 'Up') - for descr_line in show_description_output.splitlines(): - description = 0 - if descr_line.startswith(interface): - description = ' '.join(descr_line.split()[1:]) - break + for descr_line in show_description_output.splitlines(): + description = 0 + if descr_line.startswith(interface): + description = ' '.join(descr_line.split()[1:]) + break - entry = { - 'is_up': is_up, - 'is_enabled': is_enabled, - 'speed': speed, - 'last_flapped': -1, - 'description': description, - 'mac_address': napalm.base.helpers.mac(mac) - } + entry = { + 'is_up': is_up, + 'is_enabled': is_enabled, + 'speed': speed, + 'last_flapped': -1, + 'description': description, + 'mac_address': napalm.base.helpers.mac(mac) + } - interfaces[interface] = entry + interfaces[interface] = entry return interfaces From c7d6577a2ca1ac145b4b41b0021856d9c362c3a6 Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 30 Oct 2020 10:46:37 +0100 Subject: [PATCH 5/5] adjust get_interfaces_ip function for compatibility with sgx00 series include and begin are not available on sgx00 devices --- napalm_s350/s350.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 3e4c92f..5121234 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -324,10 +324,13 @@ class S350Driver(NetworkDriver): def get_interfaces_ip(self): """Returns all configured interface IP addresses.""" interfaces = {} - show_ip_int = self._send_command('show ip int | include (UP|DOWN)') + valid_interfaces = [] + show_ip_int = self._send_command('show ip int') # Limit to valid interfaces (i.e. ignore vlan 1) - valid_interfaces = [i for i in show_ip_int.splitlines() if i.split()[-1] == 'Valid'] + for line in show_ip_int.splitlines(): + if ('UP' in line or 'DOWN' in line) and line.split()[-1] == 'Valid': + valid_interfaces.append(line) for interface in valid_interfaces: network, name = interface.split()[:2]