Commit 79db8a89 authored by bee26's avatar bee26
Browse files

Merge branch 'cherry-pick-5270d016' into 'release-19.2'

release-19.2:Backport!2158

See merge request noc/noc!2238
parents 2c29e51d 11f9ac3f
......@@ -27,9 +27,9 @@ class Profile(BaseProfile):
]
pattern_unprivileged_prompt = r"^(?P<hostname>\S+)>\s*"
pattern_syntax_error = \
r"^% (Unrecognized command|Incomplete command|" \
r"% (Unrecognized command|Incomplete command|" \
r"Wrong number of parameters or invalid range, size or " \
r"characters entered)$"
r"characters entered)"
command_disable_pager = "terminal datadump"
command_super = "enable"
command_enter_config = "configure"
......@@ -54,6 +54,47 @@ class Profile(BaseProfile):
("hints", "protocols", "loop-detect", "status", False)
]
matchers = {
"is_has_image": {
"image": {
"$regex": r"^\S+"
}
}
}
PLATFORMS = {
"24": "MES-3124",
"26": "MES-5148",
"30": "MES-3124F",
"35": "MES-3108",
"36": "MES-3108F",
"38": "MES-3116",
"39": "MES-3116F",
"40": "MES-3224",
"41": "MES-3224F",
"42": "MES-1024",
"43": "MES-2124",
"52": "MES-1124",
"54": "MES-5248",
"58": "MES-2208P",
"59": "MES-2124P",
"74": "MES-5324",
"75": "MES-2124F",
"76": "MES-2324",
"78": "MES-2324FB",
"80": "MES-3324",
"81": "MES-3324F",
"83": "MES-2324B",
"86": "MES-2348B",
"88": "MES-2308",
"89": "MES-2308P",
"92": "MES-2324P",
"98": "MES-3508P"
}
def get_platform(self, s):
return self.PLATFORMS.get(s)
INTERFACE_TYPES = {
"as": "physical", # Async
"at": "physical", # ATM
......
......@@ -70,7 +70,13 @@ class Script(BaseScript):
:return:
"""
r = self.cli("show version", cached=True)
return [e[0] for e in parse_table(r)]
s = [e[0] for e in parse_table(r)]
if not s: # MES3324
r = self.cli("show system", cached=True)
s = [e[0] for e in parse_table(r, footer=r"^Unit\s*Main Power")]
while s[-1] == "":
del s[-1]
return s
def execute_platform_cli(self, caps):
s = self.has_stack()
......
......@@ -36,21 +36,31 @@ class Script(BaseScript):
}
def execute_cli(self):
r = []
if self.has_capability("Stack | Members"):
c = self.cli("show system unit 1", cached=True)
match = self.rx_mac.search(c)
mac_begin = match.group("mac")
match = self.rx_mac2.search(c)
if match:
mac_end = match.group("mac")
else:
mac_end = mac_begin
for unit in self.capabilities["Stack | Member Ids"].split(" | "):
c = self.cli("show system unit %s" % unit, cached=True)
match = self.rx_mac.search(c)
if not match:
continue
mac_begin = match.group("mac")
match = self.rx_mac2.search(c)
if match:
mac_end = match.group("mac")
else:
mac_end = mac_begin
r += [{
"first_chassis_mac": mac_begin,
"last_chassis_mac": mac_end
}]
else:
c = self.cli("show system", cached=True)
match = self.rx_mac.search(c)
mac_begin = match.group("mac")
mac_end = match.group("mac")
return {
"first_chassis_mac": mac_begin,
"last_chassis_mac": mac_end
}
r = [{
"first_chassis_mac": mac_begin,
"last_chassis_mac": mac_end
}]
return r
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Eltex.MES.get_interfaces
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -361,7 +361,7 @@ class Script(BaseScript):
"subinterfaces": [sub]
}
if description:
sub["description"] = description
iface["description"] = description
if ifindex:
iface["snmp_ifindex"] = ifindex
if mac:
......
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Eltex.MES.get_inventory
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinventory import IGetInventory
from noc.lib.text import parse_table
class Script(BaseScript):
name = "Eltex.MES.get_inventory"
interface = IGetInventory
cache = True
rx_hardware = re.compile(
r"^HW version+\s+(?P<hardware>\S+)$", re.MULTILINE)
rx_serial1 = re.compile(
r"^Serial number :\s+(?P<serial>\S+)$", re.MULTILINE)
rx_serial2 = re.compile(
r"^\s+1\s+(?P<serial>\S+)\s*\n", re.MULTILINE)
rx_serial3 = re.compile(
r"^\s+1\s+(?P<mac>\S+)\s+(?P<hardware>\S+)\s+(?P<serial>\S+)\s*\n",
re.MULTILINE)
rx_platform = re.compile(
r"^System Object ID:\s+(?P<platform>\S+)$", re.MULTILINE)
rx_descr = re.compile(
r"^System (?:Description|Type):\s+(?P<descr>.+)$", re.MULTILINE)
rx_trans = re.compile(
r"^\s*Transceiver information:\s*\n"
r"^\s*Vendor name: (?P<vendor>.+?)\s*\n"
r"^\s*Serial number: (?P<serial>.+?)\s*\n"
r"(^\s*Part number: (?P<part_no>.+?)\s*\n)?"
r"(^\s*Vendor revision: (?P<revision>.+?)\s*\n)?"
r"^\s*Connector type: (?P<conn_type>.+?)\s*\n"
r"^\s*Type: (?P<type>.+?)\s*\n"
r"^\s*Compliance code: (?P<code>.+?)\s*\n"
r"^\s*Laser wavelength: (?P<wavelength>.+?)\s*\n"
r"^\s*Transfer distance: (?P<distance>.+?)\s*\n",
re.MULTILINE
)
def get_chassis(self, plat, ver, ser):
match = self.rx_descr.search(plat)
if match and match.group("descr").startswith("MES"):
descr = match.group("descr")
else:
descr = None
platform = None
match = self.rx_platform.search(plat)
if match:
platform = match.group("platform")
platform = platform.split(".")[8]
platform = self.profile.get_platform(platform)
elif self.has_capability("Stack | Members"):
# Try to obtain platform from description
if descr and descr.startswith("MES"):
platform = descr.split()[0] # MES-3124F
if not descr.startswith("MES-"): # MES2208P
platform = "MES-%s" % platform[3:]
hardware = self.rx_hardware.search(ver)
match = self.rx_serial1.search(ser)
match2 = self.rx_serial3.search(ser)
if match:
serial = self.rx_serial1.search(ser)
elif match2:
# Unit MAC address Hardware version Serial number
# ---- ----------------- ---------------- -------------
# 1 xx:xx:xx:xx:xx:xx 02.01.02 ESXXXXXXX
serial = self.rx_serial3.search(ser)
else:
serial = self.rx_serial2.search(ser)
r = {
"type": "CHASSIS",
"vendor": "ELTEX",
"part_no": [platform]
}
if serial:
r["serial"] = serial.group("serial")
if hardware:
r["revision"] = hardware.group("hardware")
if descr:
r["description"] = descr
return r
def get_trans(self, ifname):
v = self.cli("show fiber-ports optical-transceiver detailed interface %s" % ifname)
match = self.rx_trans.search(v)
r = {
"type": "XCVR",
"vendor": match.group("vendor"),
}
if match.group("serial"):
r["serial"] = match.group("serial")
if match.group("revision"):
r["revision"] = match.group("revision")
if ifname.startswith("gi"):
r["number"] = "gi%s" % ifname.split("/")[-1]
if ifname.startswith("te"):
r["number"] = "te%s" % ifname.split("/")[-1]
if match.group("part_no"):
part_no = match.group("part_no")
else:
r["vendor"] = "OEM"
code = match.group("code")
if code == "1000BASE-LX":
part_no = "NoName | Transceiver | 1G | SFP LX"
elif code == "BaseBX10":
wavelength = match.group("wavelength")
if wavelength == "1310 nm":
part_no = "NoName | Transceiver | 1G | SFP BX10D"
elif wavelength == "1490 nm":
part_no = "NoName | Transceiver | 1G | SFP BX10U"
else:
# raise self.NotSupportedError()
part_no = "NoName | Transceiver | 1G | SFP"
elif code == "10GBASE-LR":
part_no = "NoName | Transceiver | 10G | SFP+ LR"
elif code == "unknown":
part_no = "NoName | Transceiver | 1G | SFP"
else:
raise self.NotSupportedError()
r["part_no"] = part_no
return r
def execute_cli(self, **kwargs):
res = []
ports = []
try:
v = self.cli("show fiber-ports optical-transceiver")
for i in parse_table(v):
if i[1] == "OK":
ports += [i[0]]
except self.CLISyntaxError:
pass
if self.has_capability("Stack | Members"):
for unit in self.capabilities["Stack | Member Ids"].split(" | "):
plat = self.cli("show system unit %s" % unit, cached=True)
if not self.is_has_image:
ver = self.cli("show version unit %s" % unit, cached=True)
else:
ver = ""
ser = self.cli("show system id unit %s" % unit, cached=True)
r = self.get_chassis(plat, ver, ser)
res += [r]
for p in ports:
if p.startswith("gi") or p.startswith("te"):
if unit == p[2]:
res += [self.get_trans(p)]
else:
plat = self.cli("show system", cached=True)
ver = self.cli("show version", cached=True)
ser = self.cli("show system id", cached=True)
r = self.get_chassis(plat, ver, ser)
res = [r]
for p in ports:
res += [self.get_trans(p)]
return res
......@@ -22,7 +22,7 @@ class Script(BaseScript):
rx_version1 = re.compile(
r"^SW version+\s+(?P<version>\S+)", re.MULTILINE)
rx_version2 = re.compile(
r"^Active-image: \S+\s*\n"
r"^Active-image: (?P<image>\S+)\s*\n"
r"^\s+Version: (?P<version>\S+)", re.MULTILINE)
rx_bootprom = re.compile(
r"^Boot version+\s+(?P<bootprom>\S+)", re.MULTILINE)
......@@ -35,42 +35,15 @@ class Script(BaseScript):
rx_serial3 = re.compile(
r"^\s+1\s+(?P<mac>\S+)\s+(?P<hardware>\S+)\s+(?P<serial>\S+)\s*\n",
re.MULTILINE)
rx_master_unit = re.compile(r"^\s*(?P<unit>\d+)\s+.+\s+master\s*\n", re.MULTILINE)
rx_platform = re.compile(
r"^System Object ID:\s+(?P<platform>\S+)$", re.MULTILINE)
platforms = {
"24": "MES-3124",
"26": "MES-5148",
"30": "MES-3124F",
"35": "MES-3108",
"36": "MES-3108F",
"38": "MES-3116",
"39": "MES-3116F",
"40": "MES-3224",
"41": "MES-3224F",
"42": "MES-1024",
"43": "MES-2124",
"52": "MES-1124",
"54": "MES-5248",
"59": "MES-2124P",
"74": "MES-5324",
"75": "MES-2124F",
"76": "MES-2324",
"78": "MES-2324FB",
"81": "MES-3324F",
"83": "MES-2324B",
"86": "MES-2348B",
"88": "MES-2308",
"89": "MES-2308P",
"92": "MES-2324P",
"98": "MES-3508P"
}
def execute_snmp(self, **kwargs):
try:
platform = self.snmp.get(mib["SNMPv2-MIB::sysObjectID.0"], cached=True)
platform = platform.split('.')[8]
platform = self.platforms.get(platform.split(')')[0])
platform = self.profile.get_platform(platform.split(')')[0])
version = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.10.67108992",
cached=True)
bootprom = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.9.67108992",
......@@ -99,10 +72,19 @@ class Script(BaseScript):
raise self.UnexpectedResultError
def execute_cli(self, **kwargs):
if self.has_capability("Stack | Members"):
plat = self.cli("show system unit 1", cached=True)
ver = self.cli("show version unit 1", cached=True)
ser = self.cli("show system id unit 1", cached=True)
try:
v = self.cli("show unit", cached=True)
except self.CLISyntaxError:
v = self.cli("show stack", cached=True)
match = self.rx_master_unit.search(v)
if match:
master_unit = match.group("unit")
plat = self.cli("show system unit %s" % master_unit, cached=True)
try:
ver = self.cli("show version unit %s" % master_unit, cached=True)
except self.CLISyntaxError:
ver = self.cli("show version", cached=True)
ser = self.cli("show system id unit %s" % master_unit, cached=True)
else:
plat = self.cli("show system", cached=True)
ver = self.cli("show version", cached=True)
......@@ -111,17 +93,19 @@ class Script(BaseScript):
match = self.rx_platform.search(plat)
platform = match.group("platform")
platform = platform.split(".")[8]
platform = self.platforms.get(platform)
platform = self.profile.get_platform(platform)
match = self.rx_version1.search(ver)
if match:
version = self.rx_version1.search(ver)
bootprom = self.rx_bootprom.search(ver)
hardware = self.rx_hardware.search(ver)
image = None
else:
version = self.rx_version2.search(ver)
bootprom = None
hardware = None
image = version.group("image").split("/")[-1]
match = self.rx_serial1.search(ser)
match2 = self.rx_serial3.search(ser)
......@@ -138,9 +122,11 @@ class Script(BaseScript):
res = {
"vendor": "Eltex",
"platform": platform,
"version": version.group("version"),
"version": version.group("version").split("[")[0],
"attributes": {}}
if image:
res["image"] = image
if serial:
res["attributes"]["Serial Number"] = serial.group("serial")
if bootprom:
......
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