Commit b05fd8df authored by bee26's avatar bee26
Browse files

Merge branch 'eltex_dslam' into 'master'

Update Eltex.DSLAM profile

See merge request noc/noc!2298
parents f0fd4715 c8974c4b
......@@ -18,8 +18,10 @@ class Profile(BaseProfile):
name = "Eltex.DSLAM"
pattern_username = r"(?<!Last )[Ll]ogin: "
pattern_more = [(r"--More-- ", " "), (r"\[Yes/press any key for no\]", "Y")]
pattern_prompt = r"(?P<hostname>\S[A-Za-z0-9-_ \:\.\*\'\,\(\)\/\@]+)> "
pattern_syntax_error = r"Command not found"
pattern_prompt = (
r"(?P<hostname>\S[A-Za-z0-9-_ \:\.\*\'\,\(\)\/\@]+)> (?!Command not found|fail to run,)"
)
pattern_syntax_error = r"Command not found|fail to run,"
pattern_operation_error = (
r"ERROR: Can't stat show result|ALARM: Board temperature mount to limit"
)
......
......@@ -2,12 +2,13 @@
# ---------------------------------------------------------------------
# Eltex.DSLAM.get_chassis_id
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# 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.igetchassisid import IGetChassisID
......@@ -18,26 +19,26 @@ class Script(BaseScript):
interface = IGetChassisID
cache = True
rx_mac1 = re.compile(
r"^Unicast MAC table: port cpu\s*\n"
r"^(?P<mac>\S+)", re.MULTILINE)
rx_mac2 = re.compile("(?P<mac>\S{17}) \[(?P<interface>.{4})\]")
rx_mac1 = re.compile(r"^Unicast MAC table: port cpu\s*\n" r"^(?P<mac>\S+)", re.MULTILINE)
rx_mac2 = re.compile(r"(?P<mac>\S{17}) \[(?P<interface>.{4})\]")
rx_mac3 = re.compile(r"MAC address: (?P<mac>\S{17})")
def execute(self):
cmd = self.cli("switch show mac table cpu", cached=True)
try:
cmd = self.cli("switch show mac table cpu", cached=True)
except self.CLISyntaxError:
cmd = self.cli("cpu show net settings", cached=True)
match = self.rx_mac1.search(cmd)
if match:
mac = match.group("mac")
return {
"first_chassis_mac": mac,
"last_chassis_mac": mac
}
return {"first_chassis_mac": mac, "last_chassis_mac": mac}
for match in self.rx_mac2.finditer(cmd):
interface = match.group("interface").strip()
if interface == "cpu":
mac = match.group("mac")
return {
"first_chassis_mac": mac,
"last_chassis_mac": mac
}
return {"first_chassis_mac": mac, "last_chassis_mac": mac}
match = self.rx_mac3.search(cmd)
if match:
mac = match.group("mac")
return {"first_chassis_mac": mac, "last_chassis_mac": mac}
return []
......@@ -2,12 +2,14 @@
# ---------------------------------------------------------------------
# Eltex.DSLAM.get_interfaces
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# 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.igetinterfaces import IGetInterfaces
from noc.lib.validators import is_int
......@@ -18,23 +20,35 @@ class Script(BaseScript):
name = "Eltex.DSLAM.get_interfaces"
interface = IGetInterfaces
rx_port = re.compile("(?P<port>cpu|sfp\d*|dsl\d+)")
rx_adsl_port = re.compile("(?P<port>p\d+)")
rx_adsl_sub = re.compile(
"(?P<port>p\d+)\s+(?P<vpi>\d+)\s+(?P<vci>\d+)\s+\S+\s+\S+\s+"
r"(?P<vlan_id>(?:\d+|\-+))")
rx_port = re.compile(r"(?P<port>cpu|sfp\d*|dsl\d+)")
rx_adsl_port = re.compile(r"(?P<port>p\d+)")
rx_adsl_sub1 = re.compile(
r"(?P<port>p\d+)\s+(?P<vpi>\d+)\s+(?P<vci>\d+)\s+\S+\s+\S+\s+(?P<vlan_id>(?:\d+|\-+))"
)
rx_adsl_sub2 = re.compile(
r"\d+\s+(?P<port>p\d+)\s+(?P<vlan_id>\d+)\s+\d+\s+\S+\s+\S+\s+\d+\s+(?P<vpi>\d+)\s+(?P<vci>\d+)"
)
rx_ip = re.compile(
"^\s+Control vid:\s+(?P<vlan_id>\d+)\s*\n"
"^\s+IP address:\s+(?P<ip_address>\d+\S+)\s*\n"
"^\s+Server IP:\s+\S+(?:\n\S+.*?)?\n"
"^\s+MAC address:\s+(?P<mac>\S+)\s*\n"
"^\s+Netmask:\s+(?P<ip_subnet>\d+\S+)\s*\n", re.MULTILINE)
r"^\s+(?:Control vid|Mgmt vlan):\s+(?P<vlan_id>\d+)\s*\n"
r"^\s+IP address:\s+(?P<ip_address>\d+\S+)\s*\n"
r"^\s+Server IP:\s+\S+(?:\n\S+.*?)?\n"
r"^\s+MAC address:\s+(?P<mac>\S+)\s*\n"
r"^\s+Netmask:\s+(?P<ip_subnet>\d+\S+)\s*.*\n",
re.MULTILINE,
)
def execute_cli(self):
interfaces = []
cmd = self.cli("switch show port state")
try:
cmd = self.cli("switch show port state")
except self.CLISyntaxError:
cmd = self.cli("switch port status")
items = self.profile.iter_items(cmd)
cmd = self.cli("switch show vlan table all")
try:
cmd = self.cli("switch show vlan table all")
except self.CLISyntaxError:
cmd = self.cli("switch show vlan all")
items1 = self.profile.iter_items(cmd)
for i in items[0]:
if i in ["STATE", "Port"]:
......@@ -45,34 +59,28 @@ class Script(BaseScript):
"name": i,
"type": "SVI",
"oper_status": oper_status,
"subinterfaces": [{
"name": i,
"oper_status": oper_status,
"enabled_afi": ["IPv4"]
}]
"subinterfaces": [
{"name": i, "oper_status": oper_status, "enabled_afi": ["IPv4"]}
],
}
match = self.rx_ip.search(self.cli("system show net settings"))
try:
v = self.cli("system show net settings")
except self.CLISyntaxError:
v = self.cli("cpu show net settings")
match = self.rx_ip.search(v)
ip_address = match.group("ip_address")
ip_subnet = match.group("ip_subnet")
ip_address = "%s/%s" % (ip_address, IPv4.netmask_to_len(ip_subnet))
iface['subinterfaces'][0]["ipv4_addresses"] = [ip_address]
iface['subinterfaces'][0]["vlan_ids"] = [match.group("vlan_id")]
iface['mac'] = match.group("mac")
iface['subinterfaces'][0]["mac"] = match.group("mac")
iface["subinterfaces"][0]["ipv4_addresses"] = [ip_address]
iface["subinterfaces"][0]["vlan_ids"] = [match.group("vlan_id")]
iface["mac"] = match.group("mac")
iface["subinterfaces"][0]["mac"] = match.group("mac")
interfaces += [iface]
else:
column = items1[0].index(i)
ifname = "s%s" % i if i.startswith("p") else i
iface = {
"name": ifname,
"type": "physical",
"oper_status": oper_status,
}
sub = {
"name": ifname,
"oper_status": oper_status,
"enabled_afi": ["BRIDGE"]
}
iface = {"name": ifname, "type": "physical", "oper_status": oper_status}
sub = {"name": ifname, "oper_status": oper_status, "enabled_afi": ["BRIDGE"]}
for ii in range(1, len(items1)):
vlan_id = int(items1[ii][0])
vlan_type = items1[ii][column].upper()
......@@ -86,26 +94,31 @@ class Script(BaseScript):
iface["subinterfaces"] = [sub]
interfaces += [iface]
cmd = self.cli("adsl show port oper status")
has_show_entry = True
for match in self.rx_adsl_port.finditer(cmd):
ifname = match.group("port")
ifname = ifname.replace("p0", "p")
iface = {
"name": ifname,
"type": "physical",
"subinterfaces": []
}
ifnumber = 0
v = self.cli("enpu show entry %s" % ifname)
for match1 in self.rx_adsl_sub.finditer(v):
ifnumber += 1
sub = {
"name": "%s.%s" % (ifname, ifnumber),
"enabled_afi": ["BRIDGE", "ATM"],
"vpi": match1.group("vpi"),
"vci": match1.group("vci")
}
if is_int(match1.group("vlan_id")):
sub["vlan_ids"] = [match1.group("vlan_id")]
iface["subinterfaces"] += [sub]
iface = {"name": ifname, "type": "physical", "subinterfaces": []}
if has_show_entry:
try:
v = self.cli("enpu show entry %s" % ifname)
rx_adsl_sub = self.rx_adsl_sub1
except self.CLISyntaxError:
has_show_entry = False
if not has_show_entry:
v = self.cli("enpu show upstream entry %s" % ifname)
rx_adsl_sub = self.rx_adsl_sub2
ifnumber = 0
for match1 in rx_adsl_sub.finditer(v):
ifnumber += 1
sub = {
"name": "%s.%s" % (ifname, ifnumber),
"enabled_afi": ["BRIDGE", "ATM"],
"vpi": match1.group("vpi"),
"vci": match1.group("vci"),
}
if is_int(match1.group("vlan_id")):
sub["vlan_ids"] = [match1.group("vlan_id")]
iface["subinterfaces"] += [sub]
interfaces += [iface]
return [{"interfaces": interfaces}]
......@@ -2,12 +2,13 @@
# ---------------------------------------------------------------------
# Eltex.DSLAM.get_mac_address_table
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# 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.igetmacaddresstable import IGetMACAddressTable
......@@ -17,21 +18,21 @@ class Script(BaseScript):
name = "Eltex.DSLAM.get_mac_address_table"
interface = IGetMACAddressTable
rx_mac = re.compile("(?P<mac>\S{17}) \[(?P<interface>.{4})\]")
rx_mac = re.compile(r"(?P<mac>\S{17}) \[(?P<interface>.{4})\]")
def execute(self, interface=None, vlan=None, mac=None):
r = []
cmd = self.cli("switch show mac table all")
try:
cmd = self.cli("switch show mac table all")
except self.CLISyntaxError:
return []
for match in self.rx_mac.finditer(cmd):
interface = match.group("interface").strip()
if interface == "cpu":
mtype = "C"
else:
mtype = "D"
r += [{
"vlan_id": 1,
"mac": match.group("mac"),
"interfaces": [interface],
"type": mtype
}]
r += [
{"vlan_id": 1, "mac": match.group("mac"), "interfaces": [interface], "type": mtype}
]
return r
......@@ -2,12 +2,13 @@
# ---------------------------------------------------------------------
# Eltex.DSLAM.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# 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.igetversion import IGetVersion
......@@ -24,7 +25,7 @@ class Script(BaseScript):
try:
ver = self.cli("system show software info", cached=True)
except self.CLISyntaxError:
ver = self.cli("system show software version", cached=True)
ver = self.cli("system show software version", cached=True, ignore_errors=True)
match = self.rx_version.search(ver)
if match:
version = match.group("version")
......@@ -34,14 +35,6 @@ class Script(BaseScript):
platform = "MXA64"
else:
platform = "DSLAM"
return {
"vendor": "Eltex",
"platform": platform,
"version": version
}
return {"vendor": "Eltex", "platform": platform, "version": version}
else:
return {
"vendor": "Eltex",
"platform": "MXA24",
"version": "mxa24"
}
return {"vendor": "Eltex", "platform": "MXA24", "version": "mxa24"}
......@@ -2,12 +2,13 @@
# ---------------------------------------------------------------------
# Eltex.DSLAM.get_vlans
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# 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.igetvlans import IGetVlans
......@@ -18,13 +19,14 @@ class Script(BaseScript):
interface = IGetVlans
cache = True
rx_vlan = re.compile("^(?P<vlan_id>\d+)", re.MULTILINE)
rx_vlan = re.compile(r"^(?P<vlan_id>\d+)", re.MULTILINE)
def execute(self):
r = []
cmd = self.cli("switch show vlan table all", cached=True)
try:
cmd = self.cli("switch show vlan table all", cached=True)
except self.CLISyntaxError:
cmd = self.cli("switch show vlan all")
for match in self.rx_vlan.finditer(cmd):
r += [{
"vlan_id": match.group("vlan_id")
}]
r += [{"vlan_id": match.group("vlan_id")}]
return r
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