Merge pull request #39 from napalm-automation-community/lldp_neighbor_wih_long_names
get_lldp_neighbors can detect owerflown fields
This commit is contained in:
7 files changed
+65
-7
No files matched your search
+28
-5
@@ -406,14 +406,17 @@ class S350Driver(NetworkDriver):
|
|||||||
match = re.match(r'^--------- -+ .*$', line)
|
match = re.match(r'^--------- -+ .*$', line)
|
||||||
if match:
|
if match:
|
||||||
header = False
|
header = False
|
||||||
|
fields_end = self._get_lldp_neighbors_fields_end(line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
line_elems = line.split()
|
line_elems = self._get_lldp_neighbors_line_to_fields(line, fields_end)
|
||||||
|
|
||||||
# long system name owerflow to the other line
|
# info owerflow to the other line
|
||||||
if len(line_elems) == 1:
|
if line_elems[0] == '' or line_elems[4] == '' or line_elems[5] == '' :
|
||||||
# complete remote name
|
# complete owerflown fields
|
||||||
remote_name = remote_name + line_elems[0]
|
local_port = local_port + line_elems[0]
|
||||||
|
remote_port = remote_port + line_elems[2]
|
||||||
|
remote_name = remote_name + line_elems[3]
|
||||||
# then reuse old values na rewrite previous entry
|
# then reuse old values na rewrite previous entry
|
||||||
else:
|
else:
|
||||||
local_port = line_elems[0]
|
local_port = line_elems[0]
|
||||||
@@ -429,6 +432,26 @@ class S350Driver(NetworkDriver):
|
|||||||
|
|
||||||
return neighbors
|
return neighbors
|
||||||
|
|
||||||
|
def _get_lldp_neighbors_line_to_fields(self, line, fields_end):
|
||||||
|
""" dynamic fields lenghts """
|
||||||
|
line_elems={}
|
||||||
|
index=0
|
||||||
|
f_start=0
|
||||||
|
for f_end in fields_end:
|
||||||
|
line_elems[index] = line[f_start:f_end].strip()
|
||||||
|
index += 1
|
||||||
|
f_start = f_end
|
||||||
|
return line_elems
|
||||||
|
|
||||||
|
def _get_lldp_neighbors_fields_end(self, dashline):
|
||||||
|
""" fields length are diferent device to device, detect them on horizontal lin """
|
||||||
|
|
||||||
|
fields_end=[m.start() for m in re.finditer(' ', dashline)]
|
||||||
|
#fields_position.insert(0,0)
|
||||||
|
fields_end.append(len(dashline))
|
||||||
|
|
||||||
|
return fields_end
|
||||||
|
|
||||||
def _get_lldp_line_value(self, line):
|
def _get_lldp_line_value(self, line):
|
||||||
"""
|
"""
|
||||||
Safe-ish method to get the value from an 'lldp neighbors $IF' line.
|
Safe-ish method to get the value from an 'lldp neighbors $IF' line.
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"port" : "74:ac:aa:ff:1a:5f"
|
"port" : "74:ac:aa:ff:1a:5f"
|
||||||
} ],
|
} ],
|
||||||
"gi1/0/35" : [ {
|
"gi1/0/35" : [ {
|
||||||
"hostname" : "O",
|
"hostname" : "",
|
||||||
"port" : "34:e6:aa:ff:53:a8"
|
"port" : "34:e6:aa:ff:53:a8"
|
||||||
} ],
|
} ],
|
||||||
"te1/0/1" : [ {
|
"te1/0/1" : [ {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"port" : "74:ac:aa:ff:1a:5f"
|
"port" : "74:ac:aa:ff:1a:5f"
|
||||||
} ],
|
} ],
|
||||||
"gi1/0/35" : [ {
|
"gi1/0/35" : [ {
|
||||||
"hostname" : "O",
|
"hostname" : "",
|
||||||
"port" : "34:e6:aa:ff:53:a8"
|
"port" : "34:e6:aa:ff:53:a8"
|
||||||
} ],
|
} ],
|
||||||
"te1/0/1" : [ {
|
"te1/0/1" : [ {
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"gi7" : [ {
|
||||||
|
"hostname" : "switchc23cf0",
|
||||||
|
"port" : "gi8"
|
||||||
|
} ],
|
||||||
|
"gi8" : [ {
|
||||||
|
"hostname" : "iai-sti0067.example.net",
|
||||||
|
"port" : "9c:eb:e8:52:bd:7c"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
System capability legend:
|
||||||
|
B - Bridge; R - Router; W - Wlan Access Point; T - telephone;
|
||||||
|
D - DOCSIS Cable Device; H - Host; r - Repeater;
|
||||||
|
TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other
|
||||||
|
|
||||||
|
Port Device ID Port ID System Name Capabilities TTL
|
||||||
|
--------- ----------------- ------------- ----------------- ------------ -----
|
||||||
|
gi7 00:a5:bf:c2:3c:f0 gi8 switchc23cf0 B, R 91
|
||||||
|
gi8 f2:18:98:43:be:9b 9c:eb:e8:52:b iai-sti0067.examp B, W 115
|
||||||
|
d:7c le.net
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"gi7": [{"hostname": "switchc23cf0", "port": "gi8"}], "gi8": [{"hostname": "iai-sti006", "port": "9c:eb:e8:52:bd:7c"}]}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
System capability legend:
|
||||||
|
B - Bridge; R - Router; W - Wlan Access Point; T - telephone;
|
||||||
|
D - DOCSIS Cable Device; H - Host; r - Repeater;
|
||||||
|
TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other
|
||||||
|
|
||||||
|
Port Device ID Port ID System Name Capabilities TTL
|
||||||
|
--------- ----------------- ------------- ----------------- ------------ -----
|
||||||
|
gi7 00:a5:bf:c2:3c:f0 gi8 switchc23cf0 B, R 91
|
||||||
|
gi8 f2:18:98:43:be:9b 9c:eb:e8:52:b iai-sti006 B, W 115
|
||||||
|
d:7c
|
||||||
|
|
||||||
Reference in new issue
Block a user