From 47dc1f43915fc5f21d6b6aaa312056f6b2f2df61 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 12 Jul 2022 17:22:41 +0300 Subject: [PATCH 1/2] Update Brocade.IronWire profile --- sa/profiles/Brocade/IronWare/add_vlan.py | 8 ++--- sa/profiles/Brocade/IronWare/get_arp.py | 9 ++--- .../Brocade/IronWare/get_chassis_id.py | 12 +++---- sa/profiles/Brocade/IronWare/get_config.py | 6 +--- .../Brocade/IronWare/get_fdp_neighbors.py | 6 +--- sa/profiles/Brocade/IronWare/get_fqdn.py | 4 +-- .../Brocade/IronWare/get_interface_status.py | 27 ++++++-------- .../Brocade/IronWare/get_interfaces.py | 4 +-- sa/profiles/Brocade/IronWare/get_inventory.py | 20 +++++------ .../Brocade/IronWare/get_mac_address_table.py | 8 ++--- .../Brocade/IronWare/get_portchannel.py | 8 ++--- .../Brocade/IronWare/get_spanning_tree.py | 4 +-- sa/profiles/Brocade/IronWare/get_version.py | 35 ++++++++----------- sa/profiles/Brocade/IronWare/get_vlans.py | 25 +++++-------- sa/profiles/Brocade/IronWare/profile.py | 5 ++- 15 files changed, 69 insertions(+), 112 deletions(-) diff --git a/sa/profiles/Brocade/IronWare/add_vlan.py b/sa/profiles/Brocade/IronWare/add_vlan.py index bedc5c9496..4c738fe7c7 100644 --- a/sa/profiles/Brocade/IronWare/add_vlan.py +++ b/sa/profiles/Brocade/IronWare/add_vlan.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.add_vlan # --------------------------------------------------------------------- -# Copyright (C) 2007-2017 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -11,14 +11,10 @@ from noc.sa.interfaces.iaddvlan import IAddVlan class Script(BaseScript): - """ - Brocade.IronWare.add_vlan - """ - name = "Brocade.IronWare.add_vlan" interface = IAddVlan - def execute(self, vlan_id, name, tagged_ports): + def execute_cli(self, vlan_id, name, tagged_ports): with self.configure(): self.cli("vlan %d name %s" % (vlan_id, name)) if tagged_ports: diff --git a/sa/profiles/Brocade/IronWare/get_arp.py b/sa/profiles/Brocade/IronWare/get_arp.py index 83d753ae57..5a826d8467 100644 --- a/sa/profiles/Brocade/IronWare/get_arp.py +++ b/sa/profiles/Brocade/IronWare/get_arp.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_arp # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -20,13 +20,10 @@ class Script(BaseScript): r"^\d+\s+(?P\S+)\s+(?P\S+)\s+(?P\S+)\s+\d+\s+(?P\S+)" ) - def execute(self): + def execute_cli(self): s = self.cli("show arp") r = [] - for l in s.splitlines(): - match = self.rx_line.match(l.strip()) - if not match: - continue + for match in self.rx_line.finditer(s): type = match.group("type") mac = match.group("mac") if mac.lower() in ("incomplete" or "none") or type.lower() in ("pending", "invalid"): diff --git a/sa/profiles/Brocade/IronWare/get_chassis_id.py b/sa/profiles/Brocade/IronWare/get_chassis_id.py index f55727ab1d..4d313c2c6a 100644 --- a/sa/profiles/Brocade/IronWare/get_chassis_id.py +++ b/sa/profiles/Brocade/IronWare/get_chassis_id.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_chassis_id # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,18 +14,14 @@ from noc.sa.interfaces.igetchassisid import IGetChassisID class Script(BaseScript): - """ - Brocade.IronWare.get_chassis_id - """ - name = "Brocade.IronWare.get_chassis_id" interface = IGetChassisID rx_mac = re.compile( r"([0-9a-f]{4}.[0-9a-f]{4}.[0-9a-f]{4})", re.IGNORECASE | re.MULTILINE | re.DOTALL ) - def execute(self): - v = self.cli("show chassis") - match = self.re_search(self.rx_mac, v) + def execute_cli(self): + v = self.cli("show chassis", cached=True) + match = self.rx_mac.search(v) mac = match.group(1) return {"first_chassis_mac": mac, "last_chassis_mac": mac} diff --git a/sa/profiles/Brocade/IronWare/get_config.py b/sa/profiles/Brocade/IronWare/get_config.py index 12fcf39d9b..ed7c9ac56b 100644 --- a/sa/profiles/Brocade/IronWare/get_config.py +++ b/sa/profiles/Brocade/IronWare/get_config.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_config # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -11,10 +11,6 @@ from noc.sa.interfaces.igetconfig import IGetConfig class Script(BaseScript): - """ - Brocade.IronWare.get_config - """ - name = "Brocade.IronWare.get_config" interface = IGetConfig diff --git a/sa/profiles/Brocade/IronWare/get_fdp_neighbors.py b/sa/profiles/Brocade/IronWare/get_fdp_neighbors.py index 118b75fce3..da24c2cd95 100644 --- a/sa/profiles/Brocade/IronWare/get_fdp_neighbors.py +++ b/sa/profiles/Brocade/IronWare/get_fdp_neighbors.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_fdp_neighbors # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,10 +14,6 @@ from noc.sa.interfaces.igetfdpneighbors import IGetFDPNeighbors class Script(BaseScript): - """ - Brocade.IronWare.get_fdp_neighbors - """ - name = "Brocade.IronWare.get_fdp_neighbors" interface = IGetFDPNeighbors diff --git a/sa/profiles/Brocade/IronWare/get_fqdn.py b/sa/profiles/Brocade/IronWare/get_fqdn.py index 7d772f44fb..40d1e52007 100644 --- a/sa/profiles/Brocade/IronWare/get_fqdn.py +++ b/sa/profiles/Brocade/IronWare/get_fqdn.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_fqdn # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -25,7 +25,7 @@ class Script(BaseScript): rx_hostname = re.compile(r"^hostname\s+(?P\S+)", re.MULTILINE) rx_domain_name = re.compile(r"^ip domain-name\s+(?P\S+)", re.MULTILINE) - def execute(self): + def execute_cli(self): v = self.cli("show running-config | include ^(hostname|ip domain-name)") fqdn = [] match = self.rx_hostname.search(v) diff --git a/sa/profiles/Brocade/IronWare/get_interface_status.py b/sa/profiles/Brocade/IronWare/get_interface_status.py index a172c1cdc6..7d450b4b3b 100644 --- a/sa/profiles/Brocade/IronWare/get_interface_status.py +++ b/sa/profiles/Brocade/IronWare/get_interface_status.py @@ -12,26 +12,21 @@ import re from noc.core.script.base import BaseScript from noc.sa.interfaces.igetinterfacestatus import IGetInterfaceStatus -rx_interface_status = re.compile(r"^(?P\S+)\s+(?P\S+).+$", re.IGNORECASE) - class Script(BaseScript): name = "Brocade.IronWare.get_interface_status" interface = IGetInterfaceStatus + rx_interface_status = re.compile(r"^(?P\S+)\s+(?P\S+).+$", re.IGNORECASE) + + def execute_snmp(self, interface=None): + r = [] + # IF-MIB::ifName, IF-MIB::ifOperStatus + for i, n, s in self.snmp.join(["1.3.6.1.2.1.31.1.1.1.1", "1.3.6.1.2.1.2.2.1.8"]): + # ifOperStatus up(1) + r += [{"interface": n, "status": int(s) == 1}] + return r - def execute(self, interface=None): - if self.has_snmp(): - try: - # Get interface status - r = [] - # IF-MIB::ifName, IF-MIB::ifOperStatus - for i, n, s in self.snmp.join(["1.3.6.1.2.1.31.1.1.1.1", "1.3.6.1.2.1.2.2.1.8"]): - # ifOperStatus up(1) - r += [{"interface": n, "status": int(s) == 1}] - return r - except self.snmp.TimeOutError: - pass - # Fallback to CLI + def execute_cli(self, interface=None): r = [] if interface: cmd = "show interface brief | include ^%s" % interface @@ -42,7 +37,7 @@ class Script(BaseScript): ln = ln.replace("Disabled", " Disabled ") ln = ln.replace("Up", " Up ") ln = ln.replace("DisabN", " Disabled N") - match = rx_interface_status.match(ln) + match = self.rx_interface_status.match(ln) if match: r += [ { diff --git a/sa/profiles/Brocade/IronWare/get_interfaces.py b/sa/profiles/Brocade/IronWare/get_interfaces.py index 29d2e40aa9..3b2874bcdd 100644 --- a/sa/profiles/Brocade/IronWare/get_interfaces.py +++ b/sa/profiles/Brocade/IronWare/get_interfaces.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_interfaces # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -33,7 +33,7 @@ class Script(BaseScript): r"untagged|(?P\w+\s[0-9\.\/]+)(?P\sto\s[0-9\.\/]+)?", re.MULTILINE | re.IGNORECASE ) - def execute(self): + def execute_cli(self): rip = [] try: c = self.cli("show ip rip int | inc ^Interface") diff --git a/sa/profiles/Brocade/IronWare/get_inventory.py b/sa/profiles/Brocade/IronWare/get_inventory.py index 9c9190865f..f6d42380a4 100644 --- a/sa/profiles/Brocade/IronWare/get_inventory.py +++ b/sa/profiles/Brocade/IronWare/get_inventory.py @@ -76,9 +76,9 @@ class Script(BaseScript): "10G-ZR": "NoName | Transceiver | 10G | XenPak ZR", } - def execute(self): + def execute_cli(self): objects = [] - v = self.cli("show version") + v = self.cli("show version", cached=True) media = self.cli("show media") match = self.rx_hw.search(v) if match: @@ -152,7 +152,7 @@ class Script(BaseScript): elif "SX" in match.group("platform"): chserial = self.rx_chserial.search(v) objects[0].update({"serial": chserial.group("serial")}) - power = self.cli("show chassis") + power = self.cli("show chassis", cached=True) for line in self.sx_power.findall(power): pwn = line[0] descr = line[1] @@ -233,7 +233,7 @@ class Script(BaseScript): partno = match[2] objects[0].update({"serial": serial, "description": descr, "part_no": partno}) # Power for RX-chassis - power = self.cli("show chassis") + power = self.cli("show chassis", cached=True) for line in power.splitlines(): if "Power" in line and "Fail" not in line: if "Power" == line.split()[0]: @@ -254,12 +254,12 @@ class Script(BaseScript): "vendor": "BROCADE", } ] - for l in v.splitlines(): - if "Fabric" in l: - partno = l.split(":")[2][:-1].strip() + for line in v.splitlines(): + if "Fabric" in line: + partno = line.split(":")[2][:-1].strip() descr = "RX-BI-SFM3 Switch Fabric Module" - n = l.split()[4] - serial = l.split(":")[1].split(",")[0].strip() + n = line.split()[4] + serial = line.split(":")[1].split(",")[0].strip() objects += [ { "builtin": False, @@ -309,7 +309,7 @@ class Script(BaseScript): ] else: # Old FastIron/BigIron chassis/objects - serial = self.cli("show chassis").splitlines()[-1].split(":")[1].strip() + serial = self.cli("show chassis", cached=True).splitlines()[-1].split(":")[1].strip() objects[0].update({"serial": serial}) for match1 in self.rx_item_ch.findall(v): objects += [ diff --git a/sa/profiles/Brocade/IronWare/get_mac_address_table.py b/sa/profiles/Brocade/IronWare/get_mac_address_table.py index 0268e02d71..68424fa7ea 100644 --- a/sa/profiles/Brocade/IronWare/get_mac_address_table.py +++ b/sa/profiles/Brocade/IronWare/get_mac_address_table.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_mac_address_table # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,10 +14,6 @@ from noc.sa.interfaces.igetmacaddresstable import IGetMACAddressTable class Script(BaseScript): - """ - Brocade.IronWare.get_mac_address_table - """ - name = "Brocade.IronWare.get_mac_address_table" interface = IGetMACAddressTable @@ -36,7 +32,7 @@ class Script(BaseScript): r.append([parts[0], parts[1], parts[3]]) return r - def execute(self, interface=None, vlan=None, mac=None): + def execute_cli(self, interface=None, vlan=None, mac=None): if vlan: vlans = [vlan] else: diff --git a/sa/profiles/Brocade/IronWare/get_portchannel.py b/sa/profiles/Brocade/IronWare/get_portchannel.py index a31693d296..bb744f6fd6 100644 --- a/sa/profiles/Brocade/IronWare/get_portchannel.py +++ b/sa/profiles/Brocade/IronWare/get_portchannel.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_portchannel # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,10 +14,6 @@ from noc.sa.interfaces.igetportchannel import IGetPortchannel class Script(BaseScript): - """ - Brocade.IronWare.get_portchannel - """ - name = "Brocade.IronWare.get_portchannel" interface = IGetPortchannel @@ -25,7 +21,7 @@ class Script(BaseScript): r"Trunk\sID\:\s(\d+)\nType:\s(\S+)\n.*\n.*\n.*\nPorts((\s+\d\/\d)+)", re.MULTILINE ) - def execute(self): + def execute_cli(self): r = [] # Get trunks st = self.cli("show trunk") diff --git a/sa/profiles/Brocade/IronWare/get_spanning_tree.py b/sa/profiles/Brocade/IronWare/get_spanning_tree.py index a7d470d1dc..ee74d482f1 100644 --- a/sa/profiles/Brocade/IronWare/get_spanning_tree.py +++ b/sa/profiles/Brocade/IronWare/get_spanning_tree.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Cisco.IOS.get_spanning_tree # --------------------------------------------------------------------- -# Copyright (C) 2007-2019 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -74,6 +74,6 @@ class Script(BaseScript): ] return r - def execute(self): + def execute_cli(self): v = self.cli("show span") return self.process_pvst(v, proto="PVST+") diff --git a/sa/profiles/Brocade/IronWare/get_version.py b/sa/profiles/Brocade/IronWare/get_version.py index e3b48017ad..6e79be96ec 100644 --- a/sa/profiles/Brocade/IronWare/get_version.py +++ b/sa/profiles/Brocade/IronWare/get_version.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_version # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,12 +14,9 @@ from noc.sa.interfaces.igetversion import IGetVersion class Script(BaseScript): - """ - Brocade.IronWare.get_version - """ - name = "Brocade.IronWare.get_version" interface = IGetVersion + cache = True rx_sw_ver = re.compile(r"SW:\sVersion\s(?P\S+)", re.MULTILINE | re.DOTALL) rx_hw_ver = re.compile(r"HW:\s+(?P\S+\s+\S+\s+\S+),", re.MULTILINE | re.DOTALL) @@ -27,23 +24,19 @@ class Script(BaseScript): r"ProCurve\s+\S+\s+\S+\s(?P\S+)\,\s+\S+\s+Version\s+(?P\S+).+$" ) - def execute(self): - if self.has_snmp(): - try: - v = self.snmp.get("1.3.6.1.2.1.1.1.0") # sysDescr.0 - match = self.re_search(self.rx_snmp_ver, v) - return { - "vendor": "Brocade", - "platform": match.group("platform"), - "version": match.group("version"), - } - except self.snmp.TimeOutError: - pass + def execute_snmp(self): + v = self.snmp.get("1.3.6.1.2.1.1.1.0") # sysDescr.0 + match = self.self.rx_snmp_ver.search(v) + return { + "vendor": "Brocade", + "platform": match.group("platform"), + "version": match.group("version"), + } - # Get version - v = self.cli("show version") - match1 = self.re_search(self.rx_sw_ver, v) - match2 = self.re_search(self.rx_hw_ver, v) + def execute_cli(self): + v = self.cli("show version", cached=True) + match1 = self.rx_sw_ver.search(v) + match2 = self.rx_hw_ver.search(v) return { "vendor": "Brocade", "platform": match2.group("version"), diff --git a/sa/profiles/Brocade/IronWare/get_vlans.py b/sa/profiles/Brocade/IronWare/get_vlans.py index b38286afe7..9a0c7ee9de 100644 --- a/sa/profiles/Brocade/IronWare/get_vlans.py +++ b/sa/profiles/Brocade/IronWare/get_vlans.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Brocade.IronWare.get_vlans # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -14,26 +14,19 @@ from noc.sa.interfaces.igetvlans import IGetVlans class Script(BaseScript): - """ - Brocade.IronWare.get_vlans - """ - name = "Brocade.IronWare.get_vlans" interface = IGetVlans rx_vlan_line = re.compile(r"^\S+\s(?P\d+)\,\sName\s(?P[A-z0-9\-\_]+?),.+$") - def execute(self): + def execute_cli(self): vlans = self.cli("show vlans") r = [] - # Replace to findall - for l in vlans.splitlines(): - match = self.rx_vlan_line.match(l.strip()) - if match: - vlan_id = int(match.group("vlan_id")) - name = match.group("name") - if name == "[None]": - r += [{"vlan_id": vlan_id}] - else: - r += [{"vlan_id": vlan_id, "name": name}] + for match in self.rx_vlan_line.finditer(vlans): + vlan_id = int(match.group("vlan_id")) + name = match.group("name") + if name == "[None]": + r += [{"vlan_id": vlan_id}] + else: + r += [{"vlan_id": vlan_id, "name": name}] return r diff --git a/sa/profiles/Brocade/IronWare/profile.py b/sa/profiles/Brocade/IronWare/profile.py index c20b4f0a45..6df7e05e4c 100644 --- a/sa/profiles/Brocade/IronWare/profile.py +++ b/sa/profiles/Brocade/IronWare/profile.py @@ -2,7 +2,7 @@ # Vendor: Foundry # OS: IronWare # --------------------------------------------------------------------- -# Copyright (C) 2007-2011 The NOC Project +# Copyright (C) 2007-2022 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -21,3 +21,6 @@ class Profile(BaseProfile): command_leave_config = "exit" command_save_config = "write memory\n" command_super = b"enable" + pattern_more = [ + (rb"^--More--, next page: Space, next line: Return key, quit: Control-c'", b" "), + ] -- GitLab From ba661ce2d082558fbd8411efba364bb4632389f7 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Thu, 14 Jul 2022 13:02:59 +0300 Subject: [PATCH 2/2] Fix --- sa/profiles/Brocade/IronWare/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sa/profiles/Brocade/IronWare/profile.py b/sa/profiles/Brocade/IronWare/profile.py index 6df7e05e4c..f79ded2bc5 100644 --- a/sa/profiles/Brocade/IronWare/profile.py +++ b/sa/profiles/Brocade/IronWare/profile.py @@ -22,5 +22,5 @@ class Profile(BaseProfile): command_save_config = "write memory\n" command_super = b"enable" pattern_more = [ - (rb"^--More--, next page: Space, next line: Return key, quit: Control-c'", b" "), + (rb"^--More--, next page: Space, next line: Return key, quit: Control-c", b" "), ] -- GitLab