Commit 0d584695 authored by Dmitry Lukhtionov's avatar Dmitry Lukhtionov
Browse files

Update NAG.SNR profile

parent ab949063
Pipeline #36583 failed with stages
in 36 seconds
# ---------------------------------------------------------------------
# NAG.SNR.get_arp
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -20,6 +20,7 @@ class Script(BaseScript):
cache = True
rx_arp = re.compile(r"^(?P<ip>\d+\S+)\s+(?P<mac>\S+)\s+(?P<interface>\S+\d+)", re.MULTILINE)
rx_arp2 = re.compile(r"^(?P<ip>\d+\S+)\s+(?P<mac>\S+)\s+\d+\s+(?P<interface>\S+\d+)", re.MULTILINE)
def execute_snmp(self):
r = []
......@@ -35,6 +36,12 @@ class Script(BaseScript):
def execute_cli(self):
r = []
for match in self.rx_arp.finditer(self.cli("show arp")):
r += [match.groupdict()]
try:
v = self.cli("show arp")
for match in self.rx_arp.finditer(v):
r += [match.groupdict()]
except self.CLISyntaxError:
v = self.cli("show arp all")
for match in self.rx_arp2.finditer(v):
r += [match.groupdict()]
return r
# ---------------------------------------------------------------------
# NAG.SNR.get_capabilities
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -25,6 +25,9 @@ class Script(BaseScript):
Check box has lldp enabled on SNR
"""
cmd = self.cli("show lldp", ignore_errors=True)
if "% Incomplete command" in cmd:
cmd = self.cli("show lldp interface", ignore_errors=True)
return "System LLDP: enable" in cmd
return self.rx_lldp_en.search(cmd) is not None
def execute_platform_cli(self, caps):
......
# ---------------------------------------------------------------------
# NAG.SNR.get_chassis_id
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -20,11 +20,14 @@ class Script(BaseScript):
cache = True
rx_mac = re.compile(r"^\s+\S+\s+mac\s+(\S+)\s*\n", re.MULTILINE | re.IGNORECASE)
rx_mac2 = re.compile(r"^MAC address\s+: (?P<mac>\S+)", re.MULTILINE)
SNMP_GET_OIDS = {"SNMP": [mib["IF-MIB::ifPhysAddress", 1]]}
def execute_cli(self):
macs = sorted(self.rx_mac.findall(self.cli("show version", cached=True)))
if not macs:
macs = sorted(self.rx_mac2.findall(self.cli("show ip", cached=True)))
return [
{"first_chassis_mac": f, "last_chassis_mac": t} for f, t in self.macs_to_ranges(macs)
]
# ---------------------------------------------------------------------
# NAG.SNR.get_interfaces
# ---------------------------------------------------------------------
# Copyright (C) 2007-2021 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -29,6 +29,24 @@ class Script(BaseScript):
r"(?:^\s+Encapsulation |^\s+Output packets statistics:)",
re.MULTILINE,
)
rx_sh_int_old = re.compile(
r"^\s+(?:Fast|Gigabit) Ethernet (?P<interface>\S+) current state: (?P<admin_status>\S+), port link is (?P<oper_status>\S+)\s*\n"
r"(?:^\s+Port type status : .+\n)?"
r"(?:^\s+Time duration of linkup is .+\n)?"
r"^\s+Hardware address is (?P<mac>\S+)\s*\n"
r"^\s+SetSpeed is .+\n"
r"^\s+Current port type: .+\n"
r"(?:^\s+Transceiver is .+\n)?"
r"(?:^\s+Transceiver Compliance: .+\n)?"
r"^\s+Priority is \d+\s*\n"
r"^\s+Flow control is .+\n"
r"^\s+Broadcast storm control target rate is .+\n"
r"^\s+PVID is (?P<pvid>\d+)\s*\n"
r"^\s+Port mode: (?P<mode>trunk|access)\s*\n"
r"(?:^\s+Untagged\s+VLAN ID: (?P<untagged>\d+)\s*\n)?"
r"(?:^\s+Vlan\s+allowed: (?P<tagged>\S+)\s*\n)?",
re.MULTILINE,
)
rx_hw = re.compile(
r"^\s+Hardware is (?P<hw_type>\S+)(\(card not installed\))?(, active is \S+)?"
r"(,\s+address is (?P<mac>\S+))?\s*\n",
......@@ -50,6 +68,14 @@ class Script(BaseScript):
r"(^Trunk allowed Vlan\s*:\s*(?P<tagged_vlans>\S+)\s*\n)?",
re.MULTILINE,
)
rx_mgmt = re.compile(
r"^ip address\s+: (?P<ip>\S+)\s*\n"
r"^netmask\s+: (?P<mask>\S+)\s*\n"
r"^gateway\s+: .+\n"
r"^ManageVLAN\s+: (?P<vlan_id>\d+)\s*\n"
r"^MAC address\s+: (?P<mac>\S+)",
re.MULTILINE,
)
rx_lag_port = re.compile(r"\s*\S+ is LAG member port, LAG port:(?P<lag_port>\S+)\n")
def execute_cli(self):
......@@ -126,15 +152,68 @@ class Script(BaseScript):
sub["enabled_afi"] = ["IPv4"]
iface["subinterfaces"] = [sub]
interfaces += [iface]
v = self.cli("show switchport interface")
for match in self.rx_vlan.finditer(v):
ifname = match.group("ifname")
untagged_vlan = match.group("untagged_vlan")
for i in interfaces:
if ifname == i["name"]:
i["subinterfaces"][0]["untagged_vlan"] = untagged_vlan
if match.group("tagged_vlans"):
tagged_vlans = match.group("tagged_vlans").replace(";", ",")
i["subinterfaces"][0]["tagged_vlans"] = self.expand_rangelist(tagged_vlans)
break
if interfaces:
# New CLI syntax
v = self.cli("show switchport interface")
for match in self.rx_vlan.finditer(v):
ifname = match.group("ifname")
untagged_vlan = match.group("untagged_vlan")
for i in interfaces:
if ifname == i["name"]:
i["subinterfaces"][0]["untagged_vlan"] = untagged_vlan
if match.group("tagged_vlans"):
tagged_vlans = match.group("tagged_vlans").replace(";", ",")
i["subinterfaces"][0]["tagged_vlans"] = self.expand_rangelist(
tagged_vlans
)
break
else:
# Old CLI syntax. V6.5.1.21 and older
for match in self.rx_sh_int_old.finditer(v):
iface = {
"name": match.group("interface"),
"type": "physical",
"admin_status": match.group("admin_status") == "enabled",
"oper_status": match.group("oper_status") == "up",
"mac": match.group("mac"),
}
sub = {
"name": match.group("interface"),
"admin_status": match.group("admin_status") == "enabled",
"oper_status": match.group("oper_status") == "up",
"mac": match.group("mac"),
"enabled_afi": ["BRIDGE"],
}
if match.group("mode") == "access":
sub["untagged_vlan"] = match.group("untagged")
else:
sub["untagged_vlan"] = match.group("pvid")
sub["tagged_vlans"] = self.expand_rangelist(match.group("tagged"))
iface["subinterfaces"] = [sub]
interfaces += [iface]
v = self.cli("show ip", cached=True)
match = self.rx_mgmt.search(v)
ip_address = "%s/%s" % (
match.group("ip"),
IPv4.netmask_to_len(match.group("mask")),
)
iface = {
"name": "system",
"type": "SVI",
"admin_status": True,
"oper_status": True,
"mac": match.group("mac"),
"subinterfaces": [
{
"name": "system",
"admin_status": True,
"oper_status": True,
"mac": match.group("mac"),
"enabled_afi": ["IPv4"],
"ipv4_addresses": [ip_address],
"vlan_ids": match.group("vlan_id"),
}
],
}
interfaces += [iface]
return [{"interfaces": interfaces}]
# ---------------------------------------------------------------------
# NAG.SNR.get_inventory
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -56,12 +56,16 @@ class Script(BaseScript):
revision = s["attributes"]["HW version"]
serial = s["attributes"]["Serial Number"]
part_no = s["platform"]
slot = self.cli("show slot")
vendor = s["vendor"]
try:
slot = self.cli("show slot")
except self.CLISyntaxError:
slot = "Invalid"
slot_id = 0
if "Invalid" in slot:
p = {
"type": "CHASSIS",
"vendor": "NAG",
"vendor": vendor,
"part_no": part_no,
"revision": revision,
"serial": serial,
......@@ -77,7 +81,7 @@ class Script(BaseScript):
sl = {
"type": "CHASSIS",
"number": slot_id,
"vendor": "NAG",
"vendor": vendor,
"mfg_date": date,
"part_no": part_no,
"revision": match.group("hardware"),
......
# ---------------------------------------------------------------------
# NAG.SNR.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -20,13 +20,13 @@ class Script(BaseScript):
cache = True
rx_ver = re.compile(
r"^\s+(?P<platform>\S+) Device, Compiled on.*\n"
r"^\s+(?:(?P<vendor>FoxGate) )?(?P<platform>\S+) Device, Compiled on.*\n"
r"(^\s+sysLocation.*\n)?"
r"(^\s+CPU Mac \S+\s*\n)?"
r"(^\s+Vlan MAC \S+\s*\n)?"
r"^\s+SoftWare(?: Package)? Version (?P<version>\S+)\s*\n"
r"^\s+Soft[Ww]are(?: Package)? Version (?P<version>\S+)\s*\n"
r"^\s+BootRom Version (?P<bootprom>\S+)\s*\n"
r"^\s+HardWare Version (?P<hardware>\S+)\s*\n"
r"^\s+Hard[Ww]are Version (?P<hardware>\S+)\s*\n"
r"^\s+CPLD Version.*\n"
r"^\s+(?:Serial No.:|Device serial number)\s*(?P<serial>\S+)\s*\n",
re.MULTILINE,
......@@ -39,12 +39,14 @@ class Script(BaseScript):
r"^\s+(?:Serial No.:|Device serial number)\s*(?P<serial>\S+)\s*\n",
re.MULTILINE,
)
rx_ver_snmp2 = re.compile(r"^(?P<vendor>FoxGate) (?P<platform>\S+)$", re.MULTILINE)
def execute_snmp(self):
match = self.rx_ver_snmp.search(self.snmp.get(mib["SNMPv2-MIB::sysDescr.0"], cached=True))
v = self.snmp.get(mib["SNMPv2-MIB::sysDescr.0"], cached=True)
match = self.rx_ver_snmp.search(v)
if match:
return {
"vendor": "NAG",
"vendor": "NAG", # Need more examples for other vendors
"platform": match.group("platform"),
"version": match.group("version"),
"attributes": {
......@@ -53,6 +55,15 @@ class Script(BaseScript):
"Serial Number": match.group("serial"),
},
}
else:
match = self.rx_ver_snmp.search(v)
if match:
# Device do not support .1.3.6.1.2.1.47.x SNMP table
return {
"vendor": "FoxGate",
"platform": match.group("platform"),
"version": "unknown", # I do not know right OID
}
vendor = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.12.1", cached=True)
platform = self.snmp.get(mib["SNMPv2-MIB::sysDescr.0"], cached=True)
platform = platform.split(" ")[0]
......@@ -72,8 +83,12 @@ class Script(BaseScript):
match = self.rx_ver.search(v)
if not match:
match = self.rx_ver_snmp.search(v)
if match.group("vendor"):
vendor = "FoxGate"
else:
vendor = "NAG"
return {
"vendor": "NAG",
"vendor": vendor,
"platform": match.group("platform"),
"version": match.group("version"),
"attributes": {
......
......@@ -18,7 +18,11 @@ class Profile(BaseProfile):
pattern_more = [
(rb"^ --More-- ", b"\n"),
(rb"^Confirm to overwrite current startup-config configuration \[Y/N\]:", b"y\n"),
(rb"^\.\.\.\.press ENTER to next line, Q to quit, other key to next page\.\.\.\.", b" "),
]
pattern_syntax_error = (
rb"% (?:Unrecognized|Incomplete) command, and error detected at"
)
username_submit = b"\r"
password_submit = b"\r"
command_submit = b"\r"
......@@ -44,6 +48,7 @@ class Profile(BaseProfile):
INTERFACE_TYPES = {
"Ethe": "physical", # Ethernet
"Vlan": "SVI", # Vlan
"syst": "SVI", # system
"Port": "aggregated", # Port-Channel
"Vsf-": "aggregated", # Vsf-Port
"vpls": "unknown", # vpls_dev
......@@ -54,4 +59,6 @@ class Profile(BaseProfile):
def get_interface_type(cls, name):
if name == "Ethernet0":
return "management"
if name.startswith("e0/"):
return "physical"
return cls.INTERFACE_TYPES.get(name[:4])
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