Verified Commit 1573e827 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Huawei.VRP3. Fix scripts for MA5303 version.

parent 92777d2f
......@@ -5,10 +5,12 @@
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
from noc.core.script.base import BaseScript
# NOC modules
from noc.sa.profiles.Generic.get_chassis_id import Script as BaseScript
from noc.sa.interfaces.igetchassisid import IGetChassisID
import re
class Script(BaseScript):
......@@ -16,7 +18,10 @@ class Script(BaseScript):
interface = IGetChassisID
rx_mac = re.compile(r"^\s*MAC address:\s+(?P<mac>\S+)")
def execute(self):
match = self.re_search(self.rx_mac, self.cli("show atmlan mac-address"))
def execute_cli(self, **kwargs):
try:
match = self.re_search(self.rx_mac, self.cli("show atmlan mac-address"))
except self.CLISyntaxError:
raise NotImplementedError
mac = match.group("mac")
return {"first_chassis_mac": mac, "last_chassis_mac": mac}
......@@ -13,6 +13,7 @@ import re
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.core.ip import IPv4
from noc.core.mac import MAC
class Script(BaseScript):
......@@ -49,13 +50,58 @@ class Script(BaseScript):
re.MULTILINE,
)
def execute(self):
rx_ma5103_mac = re.compile(r"^\s*Current MAC address of active mainboard:\s+(?P<mac>\S+)")
rx_ma5103_ip = re.compile(r"^\s*\d+\s+Ethernet\s+(?P<ip>\S+)\s+(?P<mask>\S+)\s+", re.MULTILINE)
def get_ma5103(self):
interfaces = []
v = self.cli("show mac-address")
match = self.rx_ma5103_mac.search(v)
mac = MAC(match.group("mac"))
v = self.cli("show atmlan ip-address 1")
match = self.rx_ma5103_ip.search(v)
ip_address = f"{match.group('ip')}/{IPv4.netmask_to_len(match.group('mask'))}"
iface = {
"name": "mgmt",
"type": "SVI",
"admin_status": True, # always True, since inactive
"oper_status": True, # SVIs aren't shown at all
"mac": mac,
"subinterfaces": [
{
"name": "mgmt",
"admin_status": True,
"oper_status": True,
"mac": mac,
"enabled_afi": ["IPv4"],
"ipv4_addresses": [ip_address],
"vlan_ids": [1],
}
],
}
interfaces += [iface]
interfaces += [
{
"name": "FE:0/0/1",
"type": "physical",
"mac": mac,
"hints": ["uplink"],
"subinterfaces": [],
}
]
return [{"interfaces": interfaces}]
def execute_cli(self, **kwargs):
interfaces = []
if self.is_ma5103:
return self.get_ma5103()
vlans = []
for v in self.scripts.get_vlans():
vlans += [v["vlan_id"]]
iface = {
"name": "FE:0/0/1",
"hints": ["nni"],
"type": "physical",
"subinterfaces": [
{"name": "FE:0/0/1", "enabled_afi": ["BRIDGE"], "tagged_vlans": vlans}
......@@ -64,6 +110,7 @@ class Script(BaseScript):
interfaces += [iface]
iface = {
"name": "FE:0/0/2",
"hints": ["nni"],
"type": "physical",
"subinterfaces": [
{"name": "FE:0/0/2", "enabled_afi": ["BRIDGE"], "tagged_vlans": vlans}
......
......@@ -24,12 +24,15 @@ class Script(BaseScript):
re.MULTILINE,
)
def execute(self):
def execute_cli(self, **kwargs):
r = []
v = self.scripts.get_version()
platform = v["platform"]
r += [{"type": "CHASSIS", "vendor": "HUAWEI", "part_no": platform}]
v = self.cli("show version 0")
if self.is_ma5103:
v = self.cli("show version 0/7")
else:
v = self.cli("show version 0")
for match in self.rx_slot.finditer(v):
r += [
{
......
......@@ -22,7 +22,7 @@ class Script(BaseScript):
re.MULTILINE,
)
def execute(self, interface=None, vlan=None, mac=None):
def execute_cli(self, interface=None, vlan=None, mac=None, **kwargs):
with self.configure():
self.cli("interface lan 0/0")
cmd = "show mac-table"
......@@ -40,7 +40,7 @@ class Script(BaseScript):
macs = self.cli(cmd)
except self.CLISyntaxError:
# Not supported at all
raise self.NotSupportedError()
raise NotImplementedError
r = []
for match in self.rx_line.finditer(macs):
r += [
......
......@@ -14,18 +14,27 @@ import re
class Script(BaseScript):
name = "Huawei.VRP3.get_version"
cache = True
interface = IGetVersion
cache = True
rx_ver = re.compile(r"\S+\s+(?P<version>\S+)\((?P<platform>\S+)\) Version , RELEASE SOFTWARE")
rx_5103_old = re.compile(r"\s+MA5100(?P<version>\S+)\sRELEASE SOFTWARE")
rx_bios = re.compile(r"\s+BIOS Version is\s+(?P<bios>\S+)")
def execute(self):
v = self.cli("show version")
match = self.re_search(self.rx_ver, v)
try:
match = self.re_search(self.rx_ver, v)
platform = match.group("platform")
version = match.group("version")
except self.UnexpectedResultError:
match = self.rx_5103_old.search(v)
version = match.group("version")
platform = "MA5103"
r = {
"vendor": "Huawei",
"platform": match.group("platform"),
"version": match.group("version"),
"platform": platform,
"version": version,
}
bios = self.rx_bios.search(v)
if bios:
......
......@@ -19,8 +19,10 @@ class Script(BaseScript):
rx_vlan2 = re.compile(r"^\s+\d+\s+(?P<vlanid>\d+)\s+\d+\s+\d+", re.MULTILINE | re.DOTALL)
rx_vlan3 = re.compile(r"^\s+Inband VLAN is\s+(?P<vlanid>\d+)")
def execute(self):
def execute_cli(self, **kwargs):
r = []
if self.is_ma5103:
return r
try:
c = self.cli("show vlan all")
for match in self.rx_vlan1.finditer(c):
......
......@@ -21,14 +21,17 @@ class Profile(BaseProfile):
pattern_more = [
(r"^--More\(Enter: next line, spacebar: next page, " r"any other key: quit\)--", " "),
(r"\[<frameId/slotId>\]", "\n"),
(r"\{ <cr>(\|\S+\<K\>|frameid/slotid\<S\>\<1,15\>|spm\<K\>)+ \}:", "\n"),
(r"\{ ((groupindex|vlan)\<K\>\|)+<cr> \}:", "\n"),
(r"\(y/n\) \[n\]", "y\n"),
(r"\(y/n\) \[y\]", "y\n"),
(r"\[to\]\:", "\n"),
(r"{\s+ifNo.<U><1,4>\s+}:", "\n"),
]
# Do not match this line: "\r\n>>User name: "
pattern_unprivileged_prompt = r"^[^>]\S+?>"
pattern_prompt = r"^(?P<hostname>\S+?)(?:-\d+)?(?:\(config\S*[^\)]*\))?#"
pattern_syntax_error = r"Invalid parameter|Incorrect command"
pattern_syntax_error = r"Invalid parameter|Incorrect command|\%\s*Unknown command"
command_more = " "
config_volatile = ["^%.*?$"]
command_disable_pager = "length 0"
......@@ -36,7 +39,11 @@ class Profile(BaseProfile):
command_enter_config = "configure terminal"
command_leave_config = "exit"
command_save_config = "save\ny\n"
matchers = {
"is_ma5103": {
"platform": {"$in": ["MA5103"]},
}
}
rx_interface_name = re.compile(r"^(?P<type>\S+)\s+(?P<number>\S.*)", re.MULTILINE)
def convert_interface_name(self, s):
......
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