Commit c0d171ce authored by MaksimSmile13's avatar MaksimSmile13
Browse files

Fix Qtech.QSW profile

parent 7b0ea61b
Pipeline #2848 passed with stage
in 16 seconds
......@@ -3,7 +3,7 @@
# Vendor: Qtech
# OS: QSW
# ---------------------------------------------------------------------
# Copyright (C) 2007-2013 The NOC Project
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -42,17 +42,17 @@ class Profile(BaseProfile):
command_save_config = "copy running-config startup-config"
pattern_prompt = r"^\S+#"
rogue_chars = [re.compile(r"\s*\x1b\[74D\s+\x1b\[74D"), "\r"]
rx_ifname = re.compile(r"^(?:1/)?(?P<number>\d+)$")
rx_ifname = re.compile(r"^(?P<number>[\d/]+)$")
def convert_interface_name(self, s):
"""
>>> Profile().convert_interface_name("Ethernet1/1")
'Ethernet1/1'
>>> Profile().convert_interface_name("1")
'Ethernet1/1'
>>> Profile().convert_interface_name("1/1")
'e1/1'
>>> Profile().convert_interface_name("e1/1")
'e1/1'
"""
match = self.rx_ifname.match(s)
match = self.rx_ifname.search(s)
if match:
return "Ethernet1/%d" % int(match.group("number"))
return "e%s" % s
else:
return s
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Qtech.QSW.get_interface_status
# ---------------------------------------------------------------------
# Copyright (C) 2007-2012 The NOC Project
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -36,14 +36,14 @@ class Script(BaseScript):
if interface:
if n == interface:
r.append({
"interface": self.profile.convert_interface_name(n),
"interface": n,
"status": int(s) == 1
})
})
else:
r.append({
"interface": self.profile.convert_interface_name(n),
"interface": n,
"status": int(s) == 1
})
})
return r
except self.snmp.TimeOutError:
pass
......@@ -59,7 +59,7 @@ class Script(BaseScript):
iface = match.group("interface")
if iface[:1] == 'e' or iface[:1] == 'g' or iface[:1] == 't':
r.append({
"interface": self.profile.convert_interface_name(iface),
"interface": iface,
"status": match.group("status") == "up"
})
except self.CLISyntaxError:
......@@ -71,7 +71,7 @@ class Script(BaseScript):
for match in self.rx_interface_status1.finditer(c):
iface = match.group("interface")
r.append({
"interface": self.profile.convert_interface_name(iface),
"interface": iface,
"status": match.group("status") == "UP"
})
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Qtech.QSW.get_lldp_neighbors
# ---------------------------------------------------------------------
# Copyright (C) 2007-2012 The NOC Project
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -11,7 +11,6 @@ import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors
from noc.sa.interfaces.base import MACAddressParameter
from noc.lib.validators import is_int, is_ipv4, is_mac
......@@ -90,8 +89,6 @@ class Script(BaseScript):
raise self.NotSupportedError()
for match in self.rx_line.finditer(lldp):
local_interface = match.group("interface")
local_interface = \
self.profile.convert_interface_name(local_interface)
remote_chassis_id = match.group("chassis_id")
remote_port = match.group("port_id")
remote_system_name = match.group("name")
......@@ -101,7 +98,8 @@ class Script(BaseScript):
# Build neighbor data
# Get capability
cap = 0
# for c in match.group("capabilities").split(","):
"""
for c in match.group("capabilities").split(","):
if cap:
c = c.strip()
if c:
......@@ -111,7 +109,7 @@ class Script(BaseScript):
"C": 64, "S": 128, "D": 256,
"H": 512, "TP": 1024,
}[c]
"""
# Get remote port subtype
remote_port_subtype = 5
if is_ipv4(remote_port):
......@@ -130,7 +128,7 @@ class Script(BaseScript):
"remote_port": remote_port,
"remote_capabilities": cap,
"remote_port_subtype": remote_port_subtype,
}
}
if remote_system_name and remote_system_name != "NULL":
n["remote_system_name"] = remote_system_name
if system_description and system_description != "NULL":
......@@ -139,7 +137,7 @@ class Script(BaseScript):
n["remote_port_description"] = port_description
# TODO:
# n["remote_chassis_id_subtype"] = 4
# n["remote_chassis_id_subtype"] = 4
i["neighbors"].append(n)
r.append(i)
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Qtech.QSW.get_mac_address_table
# ---------------------------------------------------------------------
# Copyright (C) 2007-2012 The NOC Project
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -100,16 +100,14 @@ class Script(BaseScript):
# Not supported at all
raise self.NotSupportedError()
for match in self.rx_line.finditer(v):
interfaces = "e" + match.group("interfaces")
interfaces = match.group("interfaces")
if interfaces == '0' \
or interfaces.lower() == 'cpu':
continue
r.append({
"vlan_id": match.group("vlan_id"),
"mac": match.group("mac"),
"interfaces": [
self.profile.convert_interface_name(interfaces)
],
"interfaces": [interfaces],
"type": {
"dynamic": "D",
"static": "S",
......@@ -125,9 +123,7 @@ class Script(BaseScript):
r.append({
"vlan_id": match.group("vlan_id"),
"mac": match.group("mac"),
"interfaces": [
self.profile.convert_interface_name(interfaces)
],
"interfaces": [interfaces],
"type": {
"dynamic": "D",
"static": "S",
......
......@@ -23,24 +23,20 @@ class Script(BaseScript):
rx_vlan_t = re.compile(r"^\s*Vlan\s+allowed\s*:\s*(?P<vlans>\S+)$")
rx_vlan_at = re.compile(r"^\s*Tagged\s+VLAN\s+ID\s*:\s*(?P<vlans>\S+)$")
rx_vlan_au = re.compile(r"^\s*Untagged\s+VLAN\s+ID\s*:\s*(?P<vlans>\S+)$")
rx_description = re.compile(r"^\s*(?P<interface>e\S+)(?P<description>.*)\n", re.MULTILINE)
rx_description = re.compile(
r"^\s*(?P<interface>e\S+)(?P<description>.*)\n", re.MULTILINE)
# rx_channel_description = re.compile(
# r"^(?P<interface>Po\d+)\s+((?P<description>\S+)|)$", re.MULTILINE)
# rx_vlan_stack = re.compile(
# r"^(?P<interface>\S+)\s+(?P<role>\S+)\s*$", re.IGNORECASE) # TODO
"""
rx_channel_description = re.compile(r"^(?P<interface>Po\d+)\s+((?P<description>\S+)|)$", re.MULTILINE)
rx_vlan_stack = re.compile(r"^(?P<interface>\S+)\s+(?P<role>\S+)\s*$", re.IGNORECASE) # TODO
"""
def execute(self):
#TODO
# TODO
# Get portchannels
# portchannels = self.scripts.get_portchannel()
# portchannels = self.scripts.get_portchannel()
portchannels = []
portchannel_members = []
# for p in portchannels:
# portchannel_members += p["members"]
# for p in portchannels:
# portchannel_members += p["members"]
# Get interafces status
interface_status = {}
......@@ -48,7 +44,7 @@ class Script(BaseScript):
for s in self.scripts.get_interface_status():
interface_status[s["interface"]] = s["status"]
#TODO
# TODO
# Get 802.1ad status if supported
vlan_stack_status = {}
"""
......@@ -184,10 +180,10 @@ class Script(BaseScript):
port_vlans = {}
port_channels = portchannels
iface_conf = self.cli("show interface")
# Correct Qtech BUG:
iface_conf = iface_conf.replace("\n\n ", "\n")
iface_conf = iface_conf.replace(
"\n\n ", "\n")
iface_conf = iface_conf.splitlines()
i = 0
L = len(iface_conf) - 2
......@@ -207,10 +203,10 @@ class Script(BaseScript):
break
if interface not in port_vlans:
port_vlans.update({interface: {
"tagged": [],
"untagged": '',
}
})
"tagged": [],
"untagged": '',
}
})
i += 1
match_mod = self.rx_mode.match(iface_conf[i])
......@@ -243,11 +239,10 @@ class Script(BaseScript):
vlans = vlans.split("-")[0]
port_vlans[interface]["untagged"] = vlans
iface_conf = []
# Why portchannels=[] ???????
# Get portchannels onse more!!!
# portchannels = self.scripts.get_portchannel()
# portchannels = self.scripts.get_portchannel()
portchannels = []
# Get switchport data and overall result
r = []
......@@ -293,16 +288,16 @@ class Script(BaseScript):
else:
tagged = port_vlans[name]["tagged"]
swp = {
"status": status,
"description": description.strip(),
"802.1Q Enabled": len(port_vlans.get(name, [])) > 0,
"802.1ad Tunnel": vlan_stack_status.get(name, False),
"tagged": tagged,
}
"status": status,
"description": description.strip(),
"802.1Q Enabled": len(port_vlans.get(name, [])) > 0,
"802.1ad Tunnel": vlan_stack_status.get(name, False),
"tagged": tagged,
}
if name in port_vlans:
if port_vlans[name]["untagged"]:
swp["untagged"] = port_vlans[name]["untagged"]
swp["interface"] = self.profile.convert_interface_name(name)
swp["interface"] = name
swp["members"] = members
r.append(swp)
write = False
......
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