Commit 877bc2cf authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'cherry-pick-df706c5c' into 'release-19.4'

release-19.4:Backport!3240

See merge request noc/noc!3301
parents 9278a2d5 97f4b1cb
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
import re import re
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.sa.profiles.Generic.get_chassis_id import Script as BaseScript
from noc.sa.interfaces.igetchassisid import IGetChassisID from noc.sa.interfaces.igetchassisid import IGetChassisID
from noc.core.mac import MAC from noc.core.mac import MAC
...@@ -19,10 +19,10 @@ class Script(BaseScript): ...@@ -19,10 +19,10 @@ class Script(BaseScript):
name = "H3C.VRP.get_chassis_id" name = "H3C.VRP.get_chassis_id"
cache = True cache = True
interface = IGetChassisID interface = IGetChassisID
always_prefer = "S"
rx_mac_old = re.compile(r"MAC address[^:]*?:\s*(?P<id>\S+)", re.IGNORECASE | re.MULTILINE) rx_mac_old = re.compile(r"MAC address[^:]*?:\s*(?P<id>\S+)", re.IGNORECASE | re.MULTILINE)
@BaseScript.match(version__startswith="3.02")
def execute_old(self): def execute_old(self):
v = self.cli("display stp") v = self.cli("display stp")
match = self.rx_mac_old.search(v) match = self.rx_mac_old.search(v)
...@@ -33,20 +33,24 @@ class Script(BaseScript): ...@@ -33,20 +33,24 @@ class Script(BaseScript):
rx_mac1 = re.compile(r"^\s*MAC(_|\s)ADDRESS[^:]*?:\s(?P<id>\S+)", re.IGNORECASE | re.MULTILINE) rx_mac1 = re.compile(r"^\s*MAC(_|\s)ADDRESS[^:]*?:\s(?P<id>\S+)", re.IGNORECASE | re.MULTILINE)
@BaseScript.match() def execute_cli(self, **kwargs):
def execute_new(self): if self.is_old_version:
return self.execute_old()
shift = 0 shift = 0
if self.match_version(platform__contains="S3600"): if self.is_S3600_platform:
# S3600 platform has additional MAC address for L3 # S3600 platform has additional MAC address for L3
shift = 1 shift = 1
v = self.cli("display stp") try:
match = self.rx_mac.search(v) v = self.cli("display stp")
if match is not None: match = self.rx_mac.search(v)
mac = match.group("id")
else:
v = self.cli("display device manuinfo")
match = self.rx_mac1.search(v)
mac = match.group("id") mac = match.group("id")
except self.CLISyntaxError:
try:
v = self.cli("display device manuinfo")
match = self.rx_mac1.search(v)
mac = match.group("id")
except self.CLISyntaxError:
raise NotImplementedError
if shift: if shift:
last_mac = str(MAC(mac).shift(shift)) last_mac = str(MAC(mac).shift(shift))
else: else:
......
...@@ -91,18 +91,21 @@ class Script(BaseScript): ...@@ -91,18 +91,21 @@ class Script(BaseScript):
# Get IPv4 interfaces # Get IPv4 interfaces
ipv4_interfaces = defaultdict(list) # interface -> [ipv4 addresses] ipv4_interfaces = defaultdict(list) # interface -> [ipv4 addresses]
c_iface = None c_iface = None
for l in self.cli("display ip interface").splitlines(): try:
match = self.rx_dis_ip_int.search(l) v = self.cli("display ip interface")
if match: for l in v.splitlines():
c_iface = self.profile.convert_interface_name(match.group("interface")) match = self.rx_dis_ip_int.search(l)
continue if match:
# Primary ip c_iface = self.profile.convert_interface_name(match.group("interface"))
match = self.rx_ip.search(l) continue
if not match: # Primary ip
continue match = self.rx_ip.search(l)
ip = match.group("ip") if not match:
ipv4_interfaces[c_iface] += [ip] continue
ip = match.group("ip")
ipv4_interfaces[c_iface] += [ip]
except self.CLISyntaxError:
pass
interfaces = [] interfaces = []
# Get OSPF interfaces # Get OSPF interfaces
ospfs = self.get_ospfint() ospfs = self.get_ospfint()
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
import re import re
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.sa.profiles.Generic.get_lldp_neighbors import Script as BaseScript
from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors, MACAddressParameter from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors, MACAddressParameter
...@@ -19,13 +19,6 @@ class Script(BaseScript): ...@@ -19,13 +19,6 @@ class Script(BaseScript):
name = "H3C.VRP.get_lldp_neighbors" name = "H3C.VRP.get_lldp_neighbors"
interface = IGetLLDPNeighbors interface = IGetLLDPNeighbors
#
# No lldp on 3.02 and older
#
@BaseScript.match(version__startswith="3.02")
def execute_old(self):
raise self.NotSupportedError()
# #
# Other (3.03 and newer) # Other (3.03 and newer)
# #
...@@ -34,14 +27,16 @@ class Script(BaseScript): ...@@ -34,14 +27,16 @@ class Script(BaseScript):
re.MULTILINE | re.DOTALL | re.IGNORECASE, re.MULTILINE | re.DOTALL | re.IGNORECASE,
) )
@BaseScript.match() def execute_cli(self, **kwargs):
def execute_other(self): if self.is_old_version:
# No lldp on 3.02 and older
raise self.NotSupportedError()
r = [] r = []
i = {} i = {}
try: try:
lldp = self.cli("display lldp neighbor") lldp = self.cli("display lldp neighbor")
except self.CLISyntaxError: except self.CLISyntaxError:
return [] raise NotImplementedError
while True: while True:
match = self.rx_ifc_line.search(lldp) match = self.rx_ifc_line.search(lldp)
if not match: if not match:
...@@ -65,7 +60,11 @@ def parse_neighbor(text): ...@@ -65,7 +60,11 @@ def parse_neighbor(text):
re.MULTILINE | re.DOTALL | re.IGNORECASE, re.MULTILINE | re.DOTALL | re.IGNORECASE,
) )
rx_neigh = re.compile( rx_neigh = re.compile(
r"\s+Chassis\s*ID\s*:\s*(?P<id>\S+).*?Port\s*ID\s*(sub)*type\s*:\s*(?P<p_type>[\w\s]+)\n\s+Port\s*ID\s*:\s*(?P<p_id>.+?)\n.+?Sys.*?name\s*:\s*(?P<name>[^\n]+)\n.*?Sys.*?cap.*?enabled\s*:\s*(?P<capability>[^\n]+)", r"\s+Chassis\s*ID\s*:\s*(?P<id>\S+).*?"
r"Port\s*ID\s*(sub)*type\s*:\s*(?P<p_type>[\w\s]+)\n\s+"
r"Port\s*ID\s*:\s*(?P<p_id>.+?)\n.+?"
r"Sys.*?name\s*:\s*(?P<name>[^\n]+)\n.*?"
r"Sys.*?cap.*?enabled\s*:\s*(?P<capability>[^\n]+)",
re.MULTILINE | re.IGNORECASE | re.DOTALL, re.MULTILINE | re.IGNORECASE | re.DOTALL,
) )
n = [] n = []
......
...@@ -16,7 +16,10 @@ class Script(BaseScript): ...@@ -16,7 +16,10 @@ class Script(BaseScript):
interface = IGetPortchannel interface = IGetPortchannel
def execute(self): def execute(self):
r = self.cli("display link-aggregation summary") try:
if "No link-aggregation" in r: r = self.cli("display link-aggregation summary")
if "No link-aggregation" in r:
return []
except self.CLISyntaxError:
return [] return []
raise self.NotSupportedError() raise self.NotSupportedError()
...@@ -62,9 +62,9 @@ class Script(BaseScript): ...@@ -62,9 +62,9 @@ class Script(BaseScript):
# Get ports in vlans # Get ports in vlans
r = [] r = []
if self.match_version(version__startswith="5.3"): if self.is_53_version:
v = self.cli("display port allow-vlan") v = self.cli("display port allow-vlan")
elif self.match_version(version__startswith="3.10"): elif self.is_310_version:
rx_line = re.compile( rx_line = re.compile(
r""" r"""
(?P<interface>\S+)\scurrent\sstate (?P<interface>\S+)\scurrent\sstate
......
...@@ -25,7 +25,7 @@ class Script(BaseScript): ...@@ -25,7 +25,7 @@ class Script(BaseScript):
re.MULTILINE | re.DOTALL | re.IGNORECASE, re.MULTILINE | re.DOTALL | re.IGNORECASE,
) )
rx_ver1 = re.compile( rx_ver1 = re.compile(
r"^\s*Comware\sSoftware,\s\\Version\s(?P<version>.+?),\s" r"^\s*Comware\sSoftware,\s(\\|)Version\s(?P<version>.+?),\s"
r"(Release)?(?P<release>\w+(\s)?\w+).*(H3C )(?P<platform>[a-zA-Z0-9\-]+) uptime is", r"(Release)?(?P<release>\w+(\s)?\w+).*(H3C )(?P<platform>[a-zA-Z0-9\-]+) uptime is",
re.MULTILINE | re.DOTALL | re.IGNORECASE, re.MULTILINE | re.DOTALL | re.IGNORECASE,
) )
......
...@@ -5,13 +5,12 @@ ...@@ -5,13 +5,12 @@
# Copyright (C) 2007-2011 The NOC Project # Copyright (C) 2007-2011 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
"""
"""
# Python modules # Python modules
import re import re
# NOC Modules # NOC Modules
from noc.core.script.base import BaseScript from noc.sa.profiles.Generic.get_vlans import Script as BaseScript
from noc.sa.interfaces.igetvlans import IGetVlans from noc.sa.interfaces.igetvlans import IGetVlans
...@@ -24,8 +23,7 @@ class Script(BaseScript): ...@@ -24,8 +23,7 @@ class Script(BaseScript):
re.IGNORECASE | re.DOTALL | re.MULTILINE, re.IGNORECASE | re.DOTALL | re.MULTILINE,
) )
@BaseScript.match() def execute_cli(self, **kwargs):
def execute_vrp3(self):
vlans = self.cli("display vlan all") vlans = self.cli("display vlan all")
return [ return [
{"vlan_id": int(match.group("vlan_id")), "name": match.group("name")} {"vlan_id": int(match.group("vlan_id")), "name": match.group("name")}
......
...@@ -24,6 +24,13 @@ class Profile(BaseProfile): ...@@ -24,6 +24,13 @@ class Profile(BaseProfile):
command_disable_pager = "" command_disable_pager = ""
pattern_syntax_error = r"% Wrong parameter|% Unrecognized command found at" pattern_syntax_error = r"% Wrong parameter|% Unrecognized command found at"
matchers = {
"is_old_version": {"version": {"$regex": r"3.02.*"}},
"is_310_version": {"version": {"$regex": r"3.10.*"}},
"is_53_version": {"version": {"$regex": r"5.3\S+"}},
"is_S3600_platform": {"platform": {"$regex": r".*S3600.*"}},
}
def generate_prefix_list(self, name, pl, strict=True): def generate_prefix_list(self, name, pl, strict=True):
p = "ip ip-prefix %s permit %%s" % name p = "ip ip-prefix %s permit %%s" % name
if not strict: if not strict:
......
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