diff --git a/sa/profiles/Raisecom/ROS/get_interfaces.py b/sa/profiles/Raisecom/ROS/get_interfaces.py index d1bc7dd28d93947ec44fe17827ce8c4fa1db52e9..a457a94fa5ba7031348624574c07d46174c4c829 100644 --- a/sa/profiles/Raisecom/ROS/get_interfaces.py +++ b/sa/profiles/Raisecom/ROS/get_interfaces.py @@ -75,7 +75,7 @@ class Script(BaseScript): rx_iface_iscom2624g = re.compile( r"^\s*(?P\S+) is (?PUP|DOWN), " r"administrative status is (?PUP|DOWN)\s*\n" - r"(^\s*Description is \"(?P.+)\",\s*\n)?" + r"(^\s*Description is \"(?P.+)\",?\s*\n)?" r"(^\s*Hardware is (?P\S+), MAC address is (?P\S+)\s*\n)?" r"(^\s*Internet Address is (?P\S+)\s+primary\s*\n)?" r"(^\s*Internet v6 Address is (?P\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}] diff --git a/sa/profiles/Raisecom/ROS/profile.py b/sa/profiles/Raisecom/ROS/profile.py index 1542b79ce7ee9bcab176831598af78900dbe2725..cc04a7468bb88f7d9b1cc0245b3e0a71f73476b2 100644 --- a/sa/profiles/Raisecom/ROS/profile.py +++ b/sa/profiles/Raisecom/ROS/profile.py @@ -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())