implement get_lldp_neighbors_detail()
This commit is contained in:
1 parent
f81b99dc3c
commit
bea9ef6be4
1 file changed
+71
@@ -287,6 +287,77 @@ class S350Driver(NetworkDriver):
|
||||
|
||||
return neighbors
|
||||
|
||||
def _get_lldp_line_value(self, line):
|
||||
"""
|
||||
Safe-ish method to get the value from an 'lldp neighbors $IF' line.
|
||||
"""
|
||||
try:
|
||||
value = line.split(':')[1:][0].strip()
|
||||
except:
|
||||
value = u'N/A'
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def get_lldp_neighbors_detail(self):
|
||||
"""
|
||||
get_lldp_neighbors_detail() implementation for s350
|
||||
"""
|
||||
details = {}
|
||||
|
||||
# First determine all interfaces with valid LLDP neighbors
|
||||
for local_port in self.get_lldp_neighbors().keys():
|
||||
# Set defaults, just in case the remote fails to provide a field.
|
||||
remote_port_id, remote_port_description, remote_chassis_id, \
|
||||
remote_system_name, remote_system_description, \
|
||||
remote_system_capab, remote_system_enable_capab = (u'N/A',) * 7
|
||||
|
||||
output = self._send_command('show lldp neighbor {}'.format(local_port))
|
||||
|
||||
for line in output.splitlines():
|
||||
if line.startswith('Port ID'):
|
||||
remote_port_id = line.split()[-1]
|
||||
elif line.startswith('Device ID'):
|
||||
remote_chassis_id = line.split()[-1]
|
||||
elif line.startswith('Port description'):
|
||||
remote_port_description = self._get_lldp_line_value(line)
|
||||
elif line.startswith('System Name'):
|
||||
remote_system_name = self._get_lldp_line_value(line)
|
||||
elif line.startswith('System description'):
|
||||
remote_system_description = self._get_lldp_line_value(line)
|
||||
elif line.startswith('Capabilities'):
|
||||
try:
|
||||
# Split a line like 'Capabilities: Bridge, Router, Wlan-Access-Point'
|
||||
capabilities = line.split(':')[1:][0].split(',')
|
||||
except:
|
||||
capabilities = []
|
||||
|
||||
caps = []
|
||||
# For all capabilities, except 'Repeater', the shorthand
|
||||
# is the first character.
|
||||
for cap in capabilities:
|
||||
cap = cap.strip()
|
||||
if cap == 'Repeater':
|
||||
caps.append('r')
|
||||
else:
|
||||
caps.append(cap[0])
|
||||
|
||||
entry = {
|
||||
'parent_interface': u'N/A',
|
||||
'remote_port': remote_port_id,
|
||||
'remote_port_description': remote_port_description,
|
||||
'remote_chassis_id': remote_chassis_id,
|
||||
'remote_system_name': remote_system_name,
|
||||
'remote_system_description': remote_system_description,
|
||||
'remote_system_capab': u', '.join(caps),
|
||||
'remote_system_enable_capab': u', '.join(caps),
|
||||
}
|
||||
|
||||
details[local_port] = entry
|
||||
|
||||
|
||||
return details
|
||||
|
||||
|
||||
def get_ntp_servers(self):
|
||||
"""get_ntp_servers implementation for S350"""
|
||||
|
||||
Reference in new issue
Block a user