From 9d0995b3aaabd851c8cb9ac4c25641ac9a51541b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kl=C3=ADma?= Date: Fri, 9 Oct 2020 07:10:04 +0000 Subject: [PATCH 1/9] bump to version 0.2.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7f48030..5adaea6 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ with open("README.md", "r") as fs: setup( name="napalm-s350", - version="0.2.1", + version="0.2.2", packages=find_packages(exclude=("test*",)), author="Jasper Lievisse Adriaanse, Petr Klíma", author_email="j@jasper.la, qaxi@seznam.cz", From 1ff7c2a090143e674c9358ef37ef1c62889c08a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kl=C3=ADma?= Date: Wed, 28 Oct 2020 12:40:36 +0100 Subject: [PATCH 2/9] get back from py23_compat removing py2 support needs more work and testing --- napalm_s350/s350.py | 1 + 1 file changed, 1 insertion(+) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 70a935b..01b1b2d 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -36,6 +36,7 @@ from napalm.base.exceptions import ( CommandErrorException, ) +from napalm.base.utils import py23_compat import napalm.base.helpers From 34ac2e5d4cbebfc76b666ae8840dd896f06e130d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kl=C3=ADma?= Date: Wed, 28 Oct 2020 12:56:34 +0100 Subject: [PATCH 3/9] fully remove py23_compat --- napalm_s350/s350.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 01b1b2d..092a458 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -36,7 +36,6 @@ from napalm.base.exceptions import ( CommandErrorException, ) -from napalm.base.utils import py23_compat import napalm.base.helpers @@ -245,15 +244,15 @@ class S350Driver(NetworkDriver): if not line: continue interface = line.split()[0] - interfaces.append(py23_compat.text_type(interface)) + interfaces.append(str(interface)) return { - 'fqdn': py23_compat.text_type(fqdn), - 'hostname': py23_compat.text_type(hostname), + 'fqdn':str(fqdn), + 'hostname': str(hostname), 'interface_list': interfaces, - 'model': py23_compat.text_type(model), - 'os_version': py23_compat.text_type(os_version), - 'serial_number': py23_compat.text_type(serial_number), + 'model': str(model), + 'os_version': str(os_version), + 'serial_number': str(serial_number), 'uptime': uptime, 'vendor': u'Cisco', } From ae33f4cc40d6ea9a1162e13226ce4645b498bf12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kl=C3=ADma?= Date: Wed, 28 Oct 2020 13:09:32 +0100 Subject: [PATCH 4/9] bump to version 0.2.3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5adaea6..bebe178 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ with open("README.md", "r") as fs: setup( name="napalm-s350", - version="0.2.2", + version="0.2.3", packages=find_packages(exclude=("test*",)), author="Jasper Lievisse Adriaanse, Petr Klíma", author_email="j@jasper.la, qaxi@seznam.cz", From 5bc1bce26f7825d7f6a477a2ed282d0dd3407772 Mon Sep 17 00:00:00 2001 From: Daniel Bacher Date: Fri, 30 Oct 2020 09:11:35 +0100 Subject: [PATCH 5/9] 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 6/9] 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 7/9] 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 8/9] 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 9/9] 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]