Commit 65bb53c9 authored by bee26's avatar bee26
Browse files

Merge branch 'fix/profile_iscratel_escom' into 'master'

Iskratel.ESCOM fix lldp neigborg script

See merge request noc/noc!3332
parents df04fbb8 ec4d09ef
......@@ -34,31 +34,83 @@ class Script(BaseScript):
r"^port id: (?P<port_id>\S+)\n+"
r"^port description: (?P<port_description>.+)\n+"
r"^system name: (?P<system_name>\S+|)\n+"
r"^system description: (?P<system_description>\S+|)\n+"
r"^.+\n+^system capabilities: (?P<capabilities>.+)",
r"^system description: (:?Device:\s+|)(?P<system_description>.+|)"
r"[\s\S]+^system capabilities: (?P<capabilities>\S\s\S|\S+)",
re.MULTILINE,
)
rx_search = re.compile(
r"^(?:(?P<chassis_id>\S+)|)\s+(?P<iface>\S+)\s+\d+\s+(?P<port_id>\S+)\s+(?:(?P<caps>\S+)|)?",
r"^(:?\S+\s+|\s+)(?P<iface>\S+\d+\/\d+)\s+\d+\s+(?P<port_id>[da-fA-F0-9]{4}.[da-fA-F0-9]{4}.[da-fA-F0-9]{4}|\S+)(:?\s+)(\w\s\w|\w)(:?\s)",
re.MULTILINE,
)
data = {"O": 1, "r": 2, "B": 4, "W": 8, "R": 16, "T": 32, "C": 64, "S": 128}
def execute(self):
"""
if "O" in i[4]:
caps += 1
elif "r" in i[4]:
caps += 2
elif "B" in i[4]:
caps += 4
elif "W" in i[4]:
caps += 8
elif "R" in i[4]:
caps += 16
elif "T" in i[4]:
caps += 32
elif "D" in i[4]:
caps += 64
elif "H" in i[4]:
caps += 128
"""
def execute_l(self, res):
r = []
data = []
try:
v = self.cli("show lldp neighbors")
except self.CLISyntaxError:
raise self.NotSupportedError()
t = parse_table(v, allow_wrap=True)
if not t:
for line in v.splitlines():
if not self.rx_search.search(line):
continue
data.append(
list([c[1], c[0], c[2], "", c[3]] for c in self.rx_search.findall(line))[0]
)
t = data
for line in res.splitlines():
match = self.rx_search.search(line)
if not match:
continue
iface = self.cli("show lldp neighbors interface %s" % match.group("iface"))
iface_match = self.rx_port2.search(iface)
chassis_id = iface_match.group("device_id")
if is_ipv4(chassis_id) or is_ipv6(chassis_id):
chassis_id_subtype = 5
elif is_mac(chassis_id):
chassis_id_subtype = 4
else:
chassis_id_subtype = 7
port_id = iface_match.group("port_id")
if is_ipv4(port_id) or is_ipv6(port_id):
port_id_subtype = 4
elif is_mac(port_id):
port_id_subtype = 3
else:
port_id_subtype = 7
caps = 0
for c in iface_match.group("capabilities").split():
c = c.strip()
if c:
caps |= self.data[c]
neighbor = {
"remote_chassis_id": chassis_id,
"remote_chassis_id_subtype": chassis_id_subtype,
"remote_port": port_id,
"remote_port_subtype": port_id_subtype,
"remote_capabilities": caps,
}
if iface_match.group("system_name"):
neighbor["remote_system_name"] = iface_match.group("system_name")
if iface_match.group("system_description"):
neighbor["remote_system_description"] = iface_match.group(
"system_description"
).strip()
if iface_match.group("port_description"):
neighbor["remote_port_description"] = iface_match.group("port_description").strip()
r += [{"local_interface": match.group("iface"), "neighbors": [neighbor]}]
return r
def execute_n(self, res):
r = []
t = parse_table(res, allow_wrap=True)
for i in t:
chassis_id = i[1]
if is_ipv4(chassis_id) or is_ipv6(chassis_id):
......@@ -78,25 +130,7 @@ class Script(BaseScript):
for c in i[4].split(","):
c = c.strip()
if c:
caps |= {"O": 1, "r": 2, "B": 4, "W": 8, "R": 16, "T": 32, "C": 64, "S": 128}[c]
"""
if "O" in i[4]:
caps += 1
elif "r" in i[4]:
caps += 2
elif "B" in i[4]:
caps += 4
elif "W" in i[4]:
caps += 8
elif "R" in i[4]:
caps += 16
elif "T" in i[4]:
caps += 32
elif "D" in i[4]:
caps += 64
elif "H" in i[4]:
caps += 128
"""
caps |= self.data[c]
neighbor = {
"remote_chassis_id": chassis_id,
"remote_chassis_id_subtype": chassis_id_subtype,
......@@ -106,22 +140,22 @@ class Script(BaseScript):
}
if i[3]:
neighbor["remote_system_name"] = i[3]
if self.is_escom_l:
try:
v = self.cli("show lldp neighbors interface %s" % i[0])
match = self.rx_port2.search(v)
except self.CLISyntaxError:
pass
else:
try:
v = self.cli("show lldp neighbors %s" % i[0])
match = self.rx_port.search(v)
except self.CLISyntaxError:
pass
try:
v = self.cli("show lldp neighbors %s" % i[0])
match = self.rx_port.search(v)
except self.CLISyntaxError:
pass
if match:
if not neighbor["remote_chassis_id"] and match.group("device_id"):
neighbor["remote_chassis_id"] = match.group("device_id")
neighbor["remote_system_description"] = match.group("system_description").strip()
neighbor["remote_port_description"] = match.group("port_description").strip()
r += [{"local_interface": i[0], "neighbors": [neighbor]}]
return r
def execute(self):
try:
v = self.cli("show lldp neighbors")
except self.CLISyntaxError:
raise self.NotSupportedError()
if self.is_escom_l:
return self.execute_l(v)
return self.execute_n(v)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment