Merge branch 'develop' of https://github.com/napalm-automation-community/napalm-s350 into develop
This commit is contained in:
commit
b1bf846e30
1 file changed
+50
-33
+50
-33
@@ -141,14 +141,19 @@ class S350Driver(NetworkDriver):
|
|||||||
"""
|
"""
|
||||||
arp_table = []
|
arp_table = []
|
||||||
|
|
||||||
output = self._send_command('show arp | include (static|dynamic)')
|
output = self._send_command('show arp')
|
||||||
|
|
||||||
for line in output.splitlines():
|
for line in output.splitlines():
|
||||||
# A VLAN may not be set for the entry
|
# A VLAN may not be set for the entry
|
||||||
|
if 'vlan' not in line:
|
||||||
|
continue
|
||||||
if len(line.split()) == 4:
|
if len(line.split()) == 4:
|
||||||
interface, ip, mac, _ = line.split()
|
interface, ip, mac, _ = line.split()
|
||||||
elif len(line.split()) == 5:
|
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:
|
else:
|
||||||
raise ValueError('Unexpected output: {}'.format(line.split()))
|
raise ValueError('Unexpected output: {}'.format(line.split()))
|
||||||
|
|
||||||
@@ -198,11 +203,19 @@ class S350Driver(NetworkDriver):
|
|||||||
show_int_st = self._send_command('show interface status')
|
show_int_st = self._send_command('show interface status')
|
||||||
|
|
||||||
# os_version
|
# os_version
|
||||||
for line in show_ver.splitlines():
|
# detect os ver > 2
|
||||||
# First version line is the active version
|
if 'Active-image' in show_ver:
|
||||||
if 'Version' in line:
|
for line in show_ver.splitlines():
|
||||||
_, os_version = line.split('Version: ')
|
# First version line is the active version
|
||||||
break
|
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
|
# hostname, uptime
|
||||||
for line in show_sys.splitlines():
|
for line in show_sys.splitlines():
|
||||||
@@ -264,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()
|
||||||
@@ -276,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
|
||||||
|
|
||||||
@@ -310,10 +324,13 @@ class S350Driver(NetworkDriver):
|
|||||||
def get_interfaces_ip(self):
|
def get_interfaces_ip(self):
|
||||||
"""Returns all configured interface IP addresses."""
|
"""Returns all configured interface IP addresses."""
|
||||||
interfaces = {}
|
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)
|
# 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:
|
for interface in valid_interfaces:
|
||||||
network, name = interface.split()[:2]
|
network, name = interface.split()[:2]
|
||||||
|
|||||||
Reference in new issue
Block a user