From cec47e76b23e8748b83283e95e7ed39a4845a327 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Thu, 5 Aug 2021 16:27:59 +0300 Subject: [PATCH] Update Vitesse.VSC profile --- sa/profiles/Vitesse/VSC/get_arp.py | 10 +++++---- sa/profiles/Vitesse/VSC/get_interfaces.py | 13 +++++++++--- sa/profiles/Vitesse/VSC/get_tech_support.py | 23 +++++++++++++++++++++ sa/profiles/Vitesse/VSC/get_version.py | 15 +++++++++++--- sa/profiles/Vitesse/VSC/profile.py | 8 +++++-- 5 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 sa/profiles/Vitesse/VSC/get_tech_support.py diff --git a/sa/profiles/Vitesse/VSC/get_arp.py b/sa/profiles/Vitesse/VSC/get_arp.py index 62a8cf9117..063e9a7650 100644 --- a/sa/profiles/Vitesse/VSC/get_arp.py +++ b/sa/profiles/Vitesse/VSC/get_arp.py @@ -1,25 +1,27 @@ # --------------------------------------------------------------------- # Vitesse.VSC.get_arp # --------------------------------------------------------------------- -# Copyright (C) 2007-2016 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- +# Python modules +import re +# NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.igetarp import IGetARP -import re class Script(BaseScript): name = "Vitesse.VSC.get_arp" interface = IGetARP rx_line = re.compile( - r"^(?P[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+via\s+(?P\S+):" r"(?P\S+)\s*$", + r"^(?P[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+via\s+(?P(VLAN )?\S+):(?P\S+)", re.MULTILINE, ) - def execute(self, interface=None): + def execute_cli(self, interface=None): r = [] v = self.cli("show ip arp") for match in self.rx_line.finditer(v): diff --git a/sa/profiles/Vitesse/VSC/get_interfaces.py b/sa/profiles/Vitesse/VSC/get_interfaces.py index 7256018ff7..757cdc655b 100644 --- a/sa/profiles/Vitesse/VSC/get_interfaces.py +++ b/sa/profiles/Vitesse/VSC/get_interfaces.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Vitesse.VSC.get_interfaces # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -26,6 +26,7 @@ class Script(BaseScript): rx_oam = re.compile( r"^(?P(?:Gi|2.5G|10G)\S+)\s+(?P\S+)\s+enabled", re.MULTILINE ) + rx_descr = re.compile("Description: (?P.+)") rx_switchport = re.compile( r"^Name: (?P(?:Gi|2.5G|10G)\S+ \S+)\s*\n" r"^Administrative mode: (?P\S+)\s*\n" @@ -87,7 +88,7 @@ class Script(BaseScript): return [] return [] - def execute(self): + def execute_cli(self): interfaces = [] gvrp = self.get_gvrp() stp = self.get_stp() @@ -103,9 +104,15 @@ class Script(BaseScript): "ifname": row[2].strip(), } ] - v = self.cli("show interface * status") + v = self.cli("show interface * status").replace("\n\n", "\n") for row in parse_table(v, max_width=85): ifname = row[0] + if ifname.startswith("Description:"): + descr = "".join(row) + match = self.rx_descr.search(descr) + if match and match.group("descr").strip() != "": + interfaces[-1]["description"] = match.group("descr").strip() + continue iface = { "name": ifname, "type": "physical", diff --git a/sa/profiles/Vitesse/VSC/get_tech_support.py b/sa/profiles/Vitesse/VSC/get_tech_support.py new file mode 100644 index 0000000000..e5d31dcab2 --- /dev/null +++ b/sa/profiles/Vitesse/VSC/get_tech_support.py @@ -0,0 +1,23 @@ +# --------------------------------------------------------------------- +# Vitesse.VSC.get_tech_support +# --------------------------------------------------------------------- +# Copyright (C) 2007-2021 The NOC Project +# See LICENSE for details +# --------------------------------------------------------------------- + +# NOC modules +from noc.core.script.base import BaseScript +from noc.sa.interfaces.igettechsupport import IGetTechSupport +from noc.core.comp import smart_bytes, smart_text + + +class Script(BaseScript): + name = "Vitesse.VSC.get_tech_support" + interface = IGetTechSupport + + def execute_cli(self): + try: + c = self.cli("show tech-support") + except self.CLISyntaxError: + raise self.NotSupportedError() + return smart_bytes(smart_text(c, errors="ignore")) diff --git a/sa/profiles/Vitesse/VSC/get_version.py b/sa/profiles/Vitesse/VSC/get_version.py index f1f4385f41..15f23d70c4 100644 --- a/sa/profiles/Vitesse/VSC/get_version.py +++ b/sa/profiles/Vitesse/VSC/get_version.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Vitesse.VSC.get_version # --------------------------------------------------------------------- -# Copyright (C) 2007-2018 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -19,15 +19,24 @@ class Script(BaseScript): interface = IGetVersion rx_platform = re.compile(r"^\s*Chipset ID\s+:\s+(?P\S+).*\n", re.MULTILINE) + rx_board = re.compile(r"^\s*Board Type\s+:\s+(?P\S+)\n", re.MULTILINE) rx_version = re.compile( r"^\s*Software Version\s+: \S+ \(standalone\)( dev-build by)? (?P.+)\n", re.MULTILINE, ) + rx_version2 = re.compile( + r"^\s*Software Version\s+: (?P.+)\n", + re.MULTILINE, + ) - def execute(self): + def execute_cli(self): v = self.cli("show version", cached=True) - match1 = self.rx_platform.search(v) + match1 = self.rx_board.search(v) + if not match1 or not match1.group("platform").startswith("NTS"): + match1 = self.rx_platform.search(v) match2 = self.rx_version.search(v) + if not match2: + match2 = self.rx_version2.search(v) return { "vendor": "Vitesse", "platform": match1.group("platform"), diff --git a/sa/profiles/Vitesse/VSC/profile.py b/sa/profiles/Vitesse/VSC/profile.py index d631a56c99..ae4e9f3133 100644 --- a/sa/profiles/Vitesse/VSC/profile.py +++ b/sa/profiles/Vitesse/VSC/profile.py @@ -3,7 +3,7 @@ # OS: VSC # URL: http://www.microsemi.com/products/ethernet-solutions/ethernet-switches # --------------------------------------------------------------------- -# Copyright (C) 2007-2016 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -20,7 +20,7 @@ class Profile(BaseProfile): command_disable_pager = "terminal length 0" command_submit = "\r" username_submit = "\r" - password_submit = "\r" + password_submit = "\r\n" pattern_more = [(r"-- more --, next page: Space, continue: g, quit:", "g\n")] command_enter_config = "configure terminal" command_leave_config = "end" @@ -35,6 +35,8 @@ class Profile(BaseProfile): '2.5GigabitEthernet 1/2' >>> Profile().convert_interface_name("10G 1/1") '10GigabitEthernet 1/1' + >>> Profile().convert_interface_name("VLAN 1") + 'VLAN1' """ s = s.strip() if s.startswith("Gi "): @@ -43,4 +45,6 @@ class Profile(BaseProfile): return "2.5GigabitEthernet %s" % s[5:].strip() if s.startswith("10G G "): return "10GigabitEthernet %s" % s[4:].strip() + if s.startswith("VLAN "): + return "VLAN%s" % s[5:].strip() return s -- GitLab