Merge pull request #21 from KIT-IAI/f-sg300

Partial support for sg300
This commit is contained in:
Petr Klíma authored and GitHub committed 2020-11-02 11:45:07 +01:00
commit e3f7ecba33
2 files changed
+57 -40

No files matched your search

+56 -39
View File
@@ -141,14 +141,19 @@ 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:
raise ValueError('Unexpected output: {}'.format(line.split()))
@@ -198,11 +203,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():
@@ -244,15 +257,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',
}
@@ -264,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()
@@ -276,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
@@ -310,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]
+1 -1
View File
@@ -12,7 +12,7 @@ with open("README.md", "r") as fs:
setup(
name="napalm-s350",
version="0.2.1",
version="0.2.3",
packages=find_packages(exclude=("test*",)),
author="Jasper Lievisse Adriaanse, Petr Klíma",
author_email="j@jasper.la, qaxi@seznam.cz",