Commit 37f3d3ca authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'fix-avs-iscom2624-ifacetype' into 'master'

Raisecom.ROS.get_interfaces. Fix getting iface_type.

See merge request !2581
parents e24cd88c 839aeb7a
Pipeline #15901 passed with stages
in 58 minutes and 19 seconds
......@@ -75,7 +75,7 @@ class Script(BaseScript):
rx_iface_iscom2624g = re.compile(
r"^\s*(?P<ifname>\S+) is (?P<oper_status>UP|DOWN), "
r"administrative status is (?P<admin_status>UP|DOWN)\s*\n"
r"(^\s*Description is \"(?P<descr>.+)\",\s*\n)?"
r"(^\s*Description is \"(?P<descr>.+)\",?\s*\n)?"
r"(^\s*Hardware is (?P<hw_type>\S+), MAC address is (?P<mac>\S+)\s*\n)?"
r"(^\s*Internet Address is (?P<ip>\S+)\s+primary\s*\n)?"
r"(^\s*Internet v6 Address is (?P<ipv6>\S+)\s+Link\s*\n)?"
......@@ -123,7 +123,7 @@ class Script(BaseScript):
hw_type = "loopback"
i = {
"name": ifname,
"type": self.IFTYPES[hw_type],
"type": self.profile.get_interface_type(ifname),
"admin_status": match.group("admin_status") == "UP",
"oper_status": match.group("oper_status") == "UP",
}
......@@ -134,8 +134,8 @@ class Script(BaseScript):
"enabled_afi": [],
}
if match.group("descr"):
i["description"] = match.group("descr")
sub["description"] = match.group("descr")
i["description"] = match.group("descr").strip('"')
sub["description"] = match.group("descr").strip('"')
if match.group("mac") and match.group("mac") != "0000.0000.0000":
i["mac"] = match.group("mac")
sub["mac"] = match.group("mac")
......@@ -169,7 +169,6 @@ class Script(BaseScript):
sub["vlan_ids"] = [int(ifunit)]
i["subinterfaces"] = [sub]
ifaces += [i]
return [{"interfaces": ifaces}]
def execute_cli(self):
......@@ -194,7 +193,6 @@ class Script(BaseScript):
if i["name"] in lldp_ifaces:
i["enabled_protocols"] = ["LLDP"]
ifaces.append(i)
statuses = []
v = self.cli("show interface port")
for line in v.splitlines()[5:]:
......@@ -204,14 +202,12 @@ class Script(BaseScript):
"oper_status": "up" in line[14:29],
}
statuses.append(i)
vlans = []
v = self.cli("show interface port switchport")
for section in v.split("Port"):
if not section:
continue
vlans.append(self.parse_vlans(section))
d = defaultdict(dict)
for l in (statuses, ifaces):
......@@ -238,13 +234,11 @@ class Script(BaseScript):
tvl = [vlan["op_trunk_allowed_vlan"] for vlan in vlans if int(vlan["name"]) == name][0]
if "n/a" not in tvl:
port["subinterfaces"][0]["tagged_vlans"] = ranges_to_list(tvl)
if_descr = []
v = self.cli("show interface ip description")
for line in v.splitlines()[2:-1]:
i = {"name": int(line[:9]), "description": str(line[9:])}
if_descr.append(i)
if not l3:
v = self.cli("show interface description")
for match in self.rx_descr.finditer(v):
......@@ -276,7 +270,6 @@ class Script(BaseScript):
i["subinterfaces"][0]["tagged_vlans"] = [vlan_id]
else:
i["subinterfaces"][0]["untagged_vlan"] = vlan_id
v = self.profile.get_version(self)
mac = v["mac"]
# XXX: This is a dirty hack !!!
......@@ -314,12 +307,10 @@ class Script(BaseScript):
i["description"] = q["description"]
i["subinterfaces"][0]["description"] = q["description"]
l3 += [i]
try:
v = self.cli("show ip interface brief")
except self.CLISyntaxError:
return [{"interfaces": l3}]
for match in self.rx_iface2.finditer(v):
ifname = match.group("iface")
i = {
......@@ -344,5 +335,4 @@ class Script(BaseScript):
if i["name"] == ifname:
i["subinterfaces"][0]["vlan_ids"] = vlan_id
break
return [{"interfaces": l3}]
......@@ -182,3 +182,21 @@ class Profile(BaseProfile):
return match.group("port")
else:
return interface
INTERFACE_TYPES = {
"nu": "null", # NULL
"fa": "physical", # fastethernet
"fe": "physical", # fastethernet
"gi": "physical", # gigaethernet
"ge": "physical", # gigaethernet
"lo": "loopback", # Loopback
"tr": "aggregated", #
"mn": "management", # Stack-port
# "te": "physical", # TenGigabitEthernet
"vl": "SVI", # vlan
"un": "unknown",
}
@classmethod
def get_interface_type(cls, name):
return cls.INTERFACE_TYPES.get((name[:2]).lower())
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