diff --git a/sa/profiles/Brocade/IronWare/add_vlan.py b/sa/profiles/Brocade/IronWare/add_vlan.py index bedc5c9496498a3f263efcc905086778c06a61e5..4c738fe7c7a51649dc504e7c27794f38ab19e649 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 83d753ae57acf9ab181196608eeb19f2fffe5d3a..5a826d84674f572a832ecdbc2d7cf409c5fd327d 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 f55727ab1d1fd252449ca3ed4053b4f88a3bd81e..4d313c2c6a48212118d4be147dceb752729e3b3d 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 12fcf39d9b12bb5f09217b16906fb759db7847ff..ed7c9ac56b8bbbd77f3033f9c9777aa892a4c86f 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 118b75fce35b891df56785ea6c795fe135849b41..da24c2cd95868e4bbcd1afc29a51f92a19f2c495 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 7d772f44fb5645aedb88bae1922b8c5675c8ad98..40d1e520076daee36cb5430207be8cb476c0fbdd 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 a172c1cdc693e21928c47e8a520c4a1f3eea2106..7d450b4b3bf0b5511a3a5e4294b8267bc03c210c 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 29d2e40aa9cb8bb3aa74e6c9d34d296548f1ca35..3b2874bcdd16ef0cc9a0725de5c026e14e6b3ae5 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 9c9190865f34971d0c51f6cb2adf8fa772311852..f6d42380a4739299ef73cfe97963391c96a56617 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 0268e02d713f764032be00a1fbdacef5867f508f..68424fa7ea6feffcee77e99e9a8a700eae11e3e9 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 a31693d296fec14ffd37d5dd740b909050d74366..bb744f6fd633df6f5e7152255dccce7806fcc59e 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 a7d470d1dcf5359986c2ff26464f9fdd215c7b2a..ee74d482f186c623986486e6187ad0207a869450 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 e3b48017ad45c302933392fa0a42a836b7248c49..6e79be96eced9b4711519d4be46a8a143392ebeb 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 b38286afe77c7fe913a6aa1b6b232f733d983e3b..9a0c7ee9de737691953bccd6317d22a023a3306b 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 c20b4f0a45f0b8c38172243c43b580a1cd41a34d..f79ded2bc5604643982bb3a17256316c956610f6 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" "), + ]