Commit 97f4b1cb authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'fix-avs-h3c-version' into 'master'

H3C.VRP. Fix get_version and add SNMP scripts.

See merge request noc/noc!3240

(cherry picked from commit df706c5c)

6f07b114 H3C.VRP. Fix get_version and add SNMP scripts.
b782e928 Fix typo.
parent 9278a2d5
......@@ -10,7 +10,7 @@
import re
# 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.core.mac import MAC
......@@ -19,10 +19,10 @@ class Script(BaseScript):
name = "H3C.VRP.get_chassis_id"
cache = True
interface = IGetChassisID
always_prefer = "S"
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):
v = self.cli("display stp")
match = self.rx_mac_old.search(v)
......@@ -33,20 +33,24 @@ class Script(BaseScript):
rx_mac1 = re.compile(r"^\s*MAC(_|\s)ADDRESS[^:]*?:\s(?P<id>\S+)", re.IGNORECASE | re.MULTILINE)
@BaseScript.match()
def execute_new(self):
def execute_cli(self, **kwargs):
if self.is_old_version:
return self.execute_old()
shift = 0
if self.match_version(platform__contains="S3600"):
if self.is_S3600_platform:
# S3600 platform has additional MAC address for L3
shift = 1
v = self.cli("display stp")
match = self.rx_mac.search(v)
if match is not None:
mac = match.group("id")
else:
v = self.cli("display device manuinfo")
match = self.rx_mac1.search(v)
try:
v = self.cli("display stp")
match = self.rx_mac.search(v)
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:
last_mac = str(MAC(mac).shift(shift))
else:
......
......@@ -91,18 +91,21 @@ class Script(BaseScript):
# Get IPv4 interfaces
ipv4_interfaces = defaultdict(list) # interface -> [ipv4 addresses]
c_iface = None
for l in self.cli("display ip interface").splitlines():
match = self.rx_dis_ip_int.search(l)
if match:
c_iface = self.profile.convert_interface_name(match.group("interface"))
continue
# Primary ip
match = self.rx_ip.search(l)
if not match:
continue
ip = match.group("ip")
ipv4_interfaces[c_iface] += [ip]
try:
v = self.cli("display ip interface")
for l in v.splitlines():
match = self.rx_dis_ip_int.search(l)
if match:
c_iface = self.profile.convert_interface_name(match.group("interface"))
continue
# Primary ip
match = self.rx_ip.search(l)
if not match:
continue
ip = match.group("ip")
ipv4_interfaces[c_iface] += [ip]
except self.CLISyntaxError:
pass
interfaces = []
# Get OSPF interfaces
ospfs = self.get_ospfint()
......
......@@ -11,7 +11,7 @@
import re
# 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
......@@ -19,13 +19,6 @@ class Script(BaseScript):
name = "H3C.VRP.get_lldp_neighbors"
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)
#
......@@ -34,14 +27,16 @@ class Script(BaseScript):
re.MULTILINE | re.DOTALL | re.IGNORECASE,
)
@BaseScript.match()
def execute_other(self):
def execute_cli(self, **kwargs):
if self.is_old_version:
# No lldp on 3.02 and older
raise self.NotSupportedError()
r = []
i = {}
try:
lldp = self.cli("display lldp neighbor")
except self.CLISyntaxError:
return []
raise NotImplementedError
while True:
match = self.rx_ifc_line.search(lldp)
if not match:
......@@ -65,7 +60,11 @@ def parse_neighbor(text):
re.MULTILINE | re.DOTALL | re.IGNORECASE,
)
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,
)
n = []
......
......@@ -16,7 +16,10 @@ class Script(BaseScript):
interface = IGetPortchannel
def execute(self):
r = self.cli("display link-aggregation summary")
if "No link-aggregation" in r:
try:
r = self.cli("display link-aggregation summary")
if "No link-aggregation" in r:
return []
except self.CLISyntaxError:
return []
raise self.NotSupportedError()
......@@ -62,9 +62,9 @@ class Script(BaseScript):
# Get ports in vlans
r = []
if self.match_version(version__startswith="5.3"):
if self.is_53_version:
v = self.cli("display port allow-vlan")
elif self.match_version(version__startswith="3.10"):
elif self.is_310_version:
rx_line = re.compile(
r"""
(?P<interface>\S+)\scurrent\sstate
......
......@@ -25,7 +25,7 @@ class Script(BaseScript):
re.MULTILINE | re.DOTALL | re.IGNORECASE,
)
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",
re.MULTILINE | re.DOTALL | re.IGNORECASE,
)
......
......@@ -5,13 +5,12 @@
# Copyright (C) 2007-2011 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
"""
"""
# Python modules
import re
# 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
......@@ -24,8 +23,7 @@ class Script(BaseScript):
re.IGNORECASE | re.DOTALL | re.MULTILINE,
)
@BaseScript.match()
def execute_vrp3(self):
def execute_cli(self, **kwargs):
vlans = self.cli("display vlan all")
return [
{"vlan_id": int(match.group("vlan_id")), "name": match.group("name")}
......
......@@ -24,6 +24,13 @@ class Profile(BaseProfile):
command_disable_pager = ""
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):
p = "ip ip-prefix %s permit %%s" % name
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