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): ...@@ -34,31 +34,83 @@ class Script(BaseScript):
r"^port id: (?P<port_id>\S+)\n+" r"^port id: (?P<port_id>\S+)\n+"
r"^port description: (?P<port_description>.+)\n+" r"^port description: (?P<port_description>.+)\n+"
r"^system name: (?P<system_name>\S+|)\n+" r"^system name: (?P<system_name>\S+|)\n+"
r"^system description: (?P<system_description>\S+|)\n+" r"^system description: (:?Device:\s+|)(?P<system_description>.+|)"
r"^.+\n+^system capabilities: (?P<capabilities>.+)", r"[\s\S]+^system capabilities: (?P<capabilities>\S\s\S|\S+)",
re.MULTILINE, re.MULTILINE,
) )
rx_search = re.compile( 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, 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 = [] r = []
data = [] for line in res.splitlines():
try: match = self.rx_search.search(line)
v = self.cli("show lldp neighbors") if not match:
except self.CLISyntaxError: continue
raise self.NotSupportedError() iface = self.cli("show lldp neighbors interface %s" % match.group("iface"))
t = parse_table(v, allow_wrap=True) iface_match = self.rx_port2.search(iface)
if not t: chassis_id = iface_match.group("device_id")
for line in v.splitlines(): if is_ipv4(chassis_id) or is_ipv6(chassis_id):
if not self.rx_search.search(line): chassis_id_subtype = 5
continue elif is_mac(chassis_id):
data.append( chassis_id_subtype = 4
list([c[1], c[0], c[2], "", c[3]] for c in self.rx_search.findall(line))[0] else:
) chassis_id_subtype = 7
t = data 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: for i in t:
chassis_id = i[1] chassis_id = i[1]
if is_ipv4(chassis_id) or is_ipv6(chassis_id): if is_ipv4(chassis_id) or is_ipv6(chassis_id):
...@@ -78,25 +130,7 @@ class Script(BaseScript): ...@@ -78,25 +130,7 @@ class Script(BaseScript):
for c in i[4].split(","): for c in i[4].split(","):
c = c.strip() c = c.strip()
if c: if c:
caps |= {"O": 1, "r": 2, "B": 4, "W": 8, "R": 16, "T": 32, "C": 64, "S": 128}[c] caps |= self.data[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
"""
neighbor = { neighbor = {
"remote_chassis_id": chassis_id, "remote_chassis_id": chassis_id,
"remote_chassis_id_subtype": chassis_id_subtype, "remote_chassis_id_subtype": chassis_id_subtype,
...@@ -106,22 +140,22 @@ class Script(BaseScript): ...@@ -106,22 +140,22 @@ class Script(BaseScript):
} }
if i[3]: if i[3]:
neighbor["remote_system_name"] = i[3] neighbor["remote_system_name"] = i[3]
if self.is_escom_l: try:
try: v = self.cli("show lldp neighbors %s" % i[0])
v = self.cli("show lldp neighbors interface %s" % i[0]) match = self.rx_port.search(v)
match = self.rx_port2.search(v) except self.CLISyntaxError:
except self.CLISyntaxError: pass
pass
else:
try:
v = self.cli("show lldp neighbors %s" % i[0])
match = self.rx_port.search(v)
except self.CLISyntaxError:
pass
if match: 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_system_description"] = match.group("system_description").strip()
neighbor["remote_port_description"] = match.group("port_description").strip() neighbor["remote_port_description"] = match.group("port_description").strip()
r += [{"local_interface": i[0], "neighbors": [neighbor]}] r += [{"local_interface": i[0], "neighbors": [neighbor]}]
return r 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