Commit b11dca86 authored by bee26's avatar bee26
Browse files

Merge branch 'eltex_lte' into 'master'

Update Eltex.LTE profile

See merge request !5400
parents 56eae3b7 380e0771
Pipeline #32216 passed with stages
in 53 minutes and 10 seconds
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Eltex.LTE.get_arp # Eltex.LTE.get_arp
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -21,14 +21,25 @@ class Script(BaseScript): ...@@ -21,14 +21,25 @@ class Script(BaseScript):
rx_line = re.compile( rx_line = re.compile(
r"^\s*\d+\s+port\s+(?P<interface>\d+)\s+" r"(?P<mac>\S+)\s+(?P<ip>\d+\S+)", re.MULTILINE r"^\s*\d+\s+port\s+(?P<interface>\d+)\s+" r"(?P<mac>\S+)\s+(?P<ip>\d+\S+)", re.MULTILINE
) )
rx_line2 = re.compile(
r"^\s*(?P<vlan>\d+)\s+(?P<ip>\d+\S+)\s+(?P<mac>\S+)\s+(?P<interface>\S+\s\d+)\s+", re.MULTILINE
)
def execute(self): def execute(self):
r = [] r = []
with self.profile.switch(self): with self.profile.switch(self):
arp = self.cli("show arp", cached=True) try:
for match in self.rx_line.finditer(arp): arp = self.cli("show arp", cached=True)
if match.group("mac") == "00:00:00:00:00:00": for match in self.rx_line.finditer(arp):
r += [{"ip": match.group("ip"), "mac": None, "interface": None}] if match.group("mac") == "00:00:00:00:00:00":
else: r += [{"ip": match.group("ip"), "mac": None, "interface": None}]
r += [match.groupdict()] else:
r += [match.groupdict()]
except self.CLISyntaxError:
arp = self.cli("show ip arp table", cached=True)
for match in self.rx_line2.finditer(arp):
if match.group("mac") == "00:00:00:00:00:00":
r += [{"ip": match.group("ip"), "mac": None, "interface": None}]
else:
r += [match.groupdict()]
return r return r
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Eltex.LTE.get_chassis_id # Eltex.LTE.get_chassis_id
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -24,12 +24,15 @@ class Script(BaseScript): ...@@ -24,12 +24,15 @@ class Script(BaseScript):
def execute(self): def execute(self):
macs = [] macs = []
with self.profile.switch(self): with self.profile.switch(self):
cmd = self.cli("show version") try:
match = self.rx_mac1.search(cmd) cmd = self.cli("show version")
if match: match = self.rx_mac1.search(cmd)
macs += [match.group("mac")] if match:
cmd = self.cli("show interfaces mac-address") macs += [match.group("mac")]
macs += self.rx_mac2.findall(cmd) cmd = self.cli("show interfaces mac-address")
macs += self.rx_mac2.findall(cmd)
except self.CLISyntaxError:
pass
if not macs: if not macs:
mac_table = self.scripts.get_mac_address_table() mac_table = self.scripts.get_mac_address_table()
for m in mac_table: for m in mac_table:
......
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Eltex.LTE.get_interfaces # Eltex.LTE.get_interfaces
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -11,6 +11,7 @@ import re ...@@ -11,6 +11,7 @@ import re
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.core.text import parse_table
class Script(BaseScript): class Script(BaseScript):
...@@ -32,59 +33,165 @@ class Script(BaseScript): ...@@ -32,59 +33,165 @@ class Script(BaseScript):
rx_ip = re.compile(r"\n\nIP address:\s+(?P<ip>\d+\S+)") rx_ip = re.compile(r"\n\nIP address:\s+(?P<ip>\d+\S+)")
rx_mgmt_ip = re.compile( rx_mgmt_ip = re.compile(
r"^Management interface: \((?P<state>\S+)\)\s*\n" r"^Management interface:( \((?P<state>\S+)\))?\s*\n"
r"^IP address:\s+(?P<ip>\d+\S+)\s*\n" r"^IP address:\s+(?P<ip>\d+\S+)\s*\n"
r"(^Default gateway:.+\n)?"
r"^VID:\s+(?P<vlan_id>\d+|none)", r"^VID:\s+(?P<vlan_id>\d+|none)",
re.MULTILINE, re.MULTILINE,
) )
rx_mac = re.compile(r"^\s+MAC address: (?P<mac>\S+)", re.MULTILINE)
rx_status = re.compile(r"^.+\d\s+(?P<oper_status>up|down|off)", re.MULTILINE)
def normalize_ifname(self, port):
port = port.strip()
while port.find(" ") != -1:
port = port.replace(" ", " ")
while port.find("- ") != -1:
port = port.replace("- ", "-")
return port
def create_iface(self, i, iftype):
ifname = " ".join(i[0].split())
if not ifname.startswith(iftype):
return None
pvid = i[1]
if i[4] not in ["none", "N/S"]:
tagged = self.expand_rangelist(i[4])
else:
tagged = []
untagged = i[5]
if untagged in ["none", "N/S"]:
untagged = pvid
iface = {
"name": ifname,
"type": "physical",
"subinterfaces": [{"name": ifname, "enabled_afi": ["BRIDGE"]}],
}
if untagged != "N/S":
iface["subinterfaces"][0]["untagged_vlan"] = int(untagged)
if tagged:
iface["subinterfaces"][0]["tagged_vlans"] = tagged
return iface
def execute(self): def execute(self):
interfaces = [] interfaces = []
macs = {} macs = {}
tagged_vlans = {} tagged_vlans = {}
untagged_vlans = {} untagged_vlans = {}
with self.profile.switch(self): try:
cmd = self.cli("show interfaces mac-address") with self.profile.switch(self):
for match in self.rx_mac1.finditer(cmd): cmd = self.cli("show interfaces mac-address")
macs[match.group("port")] = match.group("mac") for match in self.rx_mac1.finditer(cmd):
for l in self.cli("show interfaces vlans").split("\n\n"): macs[match.group("port")] = match.group("mac")
match = self.rx_vlan.search(l) for line in self.cli("show interfaces vlans").split("\n\n"):
match = self.rx_vlan.search(line)
if match:
if match.group("tagged") != "none":
tagged_vlans[match.group("port")] = self.expand_rangelist(
match.group("tagged")
)
if match.group("untagged") != "none":
untagged_vlans[match.group("port")] = match.group("untagged")
cmd = self.cli("show version")
match = self.rx_mac2.search(cmd)
if match: if match:
if match.group("tagged") != "none": ip_mac = match.group("mac")
tagged_vlans[match.group("port")] = self.expand_rangelist( else:
match.group("tagged") ip_mac = ""
) ports = self.scripts.get_interface_status()
if match.group("untagged") != "none": for i in ports:
untagged_vlans[match.group("port")] = match.group("untagged") iface = {
cmd = self.cli("show version") "name": i["interface"],
match = self.rx_mac2.search(cmd) "type": "physical",
if match: "oper_status": i["status"],
ip_mac = match.group("mac") "mac": macs[i["interface"]],
else: "subinterfaces": [
ip_mac = "" {
ports = self.scripts.get_interface_status() "name": i["interface"],
for i in ports: "oper_status": i["status"],
iface = { "enabled_afi": ["BRIDGE"],
"name": i["interface"], "mac": macs[i["interface"]],
"type": "physical", }
"oper_status": i["status"], ],
"mac": macs[i["interface"]], }
"subinterfaces": [ t = tagged_vlans.get(i["interface"])
{ if t:
"name": i["interface"], iface["subinterfaces"][0]["tagged_vlans"] = t
"oper_status": i["status"], u = untagged_vlans.get(i["interface"])
"enabled_afi": ["BRIDGE"], if u:
"mac": macs[i["interface"]], iface["subinterfaces"][0]["untagged_vlan"] = u
} interfaces += [iface]
], except self.CLISyntaxError:
} # We are already in `switch` context
t = tagged_vlans.get(i["interface"]) c = self.cli("show vlan", cached=True)
if t: t = parse_table(c, allow_wrap=True, footer="dummy footer")
iface["subinterfaces"][0]["tagged_vlans"] = t for i in t:
u = untagged_vlans.get(i["interface"]) vlan_id = i[0]
if u: if i[2] != "none":
iface["subinterfaces"][0]["untagged_vlan"] = u tagged = i[2].split(", ")
interfaces += [iface] for port in tagged:
ifname = self.normalize_ifname(port)
found = False
for iface in interfaces:
if iface["name"] == ifname:
if "tagged_vlans" in iface["subinterfaces"][0]:
iface["subinterfaces"][0]["tagged_vlans"] += [vlan_id]
else:
iface["subinterfaces"][0]["tagged_vlans"] = [vlan_id]
found = True
break
if not found:
iface = {
"name": ifname,
"type": "physical",
"subinterfaces": [
{
"name": ifname,
"enabled_afi": ["BRIDGE"],
"tagged_vlans": [vlan_id],
}
],
}
interfaces += [iface]
if i[3] != "none":
untagged = i[3].split(", ")
for port in untagged:
ifname = self.normalize_ifname(port)
found = False
for iface in interfaces:
if iface["name"] == ifname:
iface["subinterfaces"][0]["untagged_vlan"] = vlan_id
found = True
break
if not found:
iface = {
"name": ifname,
"type": "physical",
"subinterfaces": [
{
"name": ifname,
"enabled_afi": ["BRIDGE"],
"untagged_vlan": vlan_id,
}
],
}
interfaces += [iface]
for i in interfaces:
c = self.cli("show interfaces mac-address %s" % i["name"])
match = self.rx_mac.search(c)
if match:
i["mac"] = match.group("mac")
i["subinterfaces"][0]["mac"] = match.group("mac")
try:
c = self.cli("show interfaces status %s" % i["name"])
match = self.rx_status.search(c)
i["oper_status"] = match.group("oper_status") == "up"
i["subinterfaces"][0]["oper_status"] = match.group("oper_status") == "up"
i["admin_status"] = match.group("oper_status") != "off"
i["subinterfaces"][0]["admin_status"] = match.group("oper_status") != "off"
except self.CLISyntaxError:
pass
c = self.cli("exit") # manually exit from `switch` context
cmd = self.cli("show system information") cmd = self.cli("show system information")
match = self.rx_ip.search(cmd) match = self.rx_ip.search(cmd)
if match: if match:
......
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Eltex.LTE.get_vlans # Eltex.LTE.get_vlans
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -11,6 +11,7 @@ import re ...@@ -11,6 +11,7 @@ import re
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetvlans import IGetVlans from noc.sa.interfaces.igetvlans import IGetVlans
from noc.core.text import parse_table
class Script(BaseScript): class Script(BaseScript):
...@@ -22,6 +23,11 @@ class Script(BaseScript): ...@@ -22,6 +23,11 @@ class Script(BaseScript):
def execute(self): def execute(self):
r = [] r = []
with self.profile.switch(self): with self.profile.switch(self):
for match in self.rx_vlan.finditer(self.cli("show vlan")): c = self.cli("show vlan", cached=True)
for match in self.rx_vlan.finditer(c):
r += [match.groupdict()] r += [match.groupdict()]
if not r:
t = parse_table(c, allow_wrap=True, footer="dummy footer")
for i in t:
r += [{"vlan_id": i[0], "name": i[1]}]
return r return r
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Vendor: Eltex # Vendor: Eltex
# OS: LTE # OS: LTE
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -15,7 +15,7 @@ class Profile(BaseProfile): ...@@ -15,7 +15,7 @@ class Profile(BaseProfile):
pattern_username = r"(?<!Last )login: " pattern_username = r"(?<!Last )login: "
pattern_more = [(r"\[Yes/press any key for no\]", "Y")] pattern_more = [(r"\[Yes/press any key for no\]", "Y")]
# pattern_unprivileged_prompt = r"^\S+>" # pattern_unprivileged_prompt = r"^\S+>"
pattern_syntax_error = r"^(Command not found|Incomplete command|Invalid argument)" pattern_syntax_error = r"\n(Command not found|Incomplete command|Invalid argument)"
pattern_operation_error = r"Data verify failed, bad MAC!" pattern_operation_error = r"Data verify failed, bad MAC!"
username_submit = "\r" username_submit = "\r"
password_submit = "\r" password_submit = "\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