adjust get_interfaces function for compatibility with sgx00 series

include and begin are not available on sgx00 devices
This commit is contained in:
Daniel Bacher committed 2020-10-30 10:31:42 +01:00
1 parent 7a1f027cdb
commit 5a2d22302a
1 file changed
+25 -24
+25 -24
View File
@@ -277,11 +277,11 @@ class S350Driver(NetworkDriver):
""" """
interfaces = {} 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') show_description_output = self._send_command('show interfaces description')
# Since the MAC address for all the local ports are equal, get the address # Since the MAC address for all the local ports are equal, get the address
# from the first port and use it everywhere. # 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: try:
mac = show_system_output.splitlines()[0].split(':', maxsplit=1)[1].strip() mac = show_system_output.splitlines()[0].split(':', maxsplit=1)[1].strip()
@@ -289,33 +289,34 @@ class S350Driver(NetworkDriver):
mac = '0' mac = '0'
for status_line in show_status_output.splitlines(): 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 == '--': if speed == '--':
is_enabled = False is_enabled = False
speed = 0 speed = 0
else: else:
is_enabled = True is_enabled = True
speed = int(speed) speed = int(speed)
is_up = (link_state == 'Up') is_up = (link_state == 'Up')
for descr_line in show_description_output.splitlines(): for descr_line in show_description_output.splitlines():
description = 0 description = 0
if descr_line.startswith(interface): if descr_line.startswith(interface):
description = ' '.join(descr_line.split()[1:]) description = ' '.join(descr_line.split()[1:])
break break
entry = { entry = {
'is_up': is_up, 'is_up': is_up,
'is_enabled': is_enabled, 'is_enabled': is_enabled,
'speed': speed, 'speed': speed,
'last_flapped': -1, 'last_flapped': -1,
'description': description, 'description': description,
'mac_address': napalm.base.helpers.mac(mac) 'mac_address': napalm.base.helpers.mac(mac)
} }
interfaces[interface] = entry interfaces[interface] = entry
return interfaces return interfaces