Commit de3beefc authored by MaksimSmile13's avatar MaksimSmile13
Browse files

Fix get_intefaces script

parent 981c9ee4
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# NSN.TIMOS.get_interfaces # NSN.TIMOS.get_interfaces
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project # Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Python modules # Python modules
import re import re
...@@ -133,12 +132,11 @@ class Script(BaseScript): ...@@ -133,12 +132,11 @@ class Script(BaseScript):
) )
re_port_info = re.compile( re_port_info = re.compile(
r""" r"""
^(?P<name>\d+/\d+/\d+)\s+ ^(?P<name>((esat-|)\d+/\d+/(c\d+|\d+)(/\d+|/u\d+|)|\w+\/\d+))\s+
(?P<admin_status>\S*)\s+ (?P<admin_status>\S*)\s+
(?P<bad_stat>\S*)\s+ (?P<bad_stat>\S*)\s+
(?:Link\s)?(?P<oper_status>\S*)\s+ (?:Link\s)?(?P<oper_status>\S*)\s+
(?P<mtu>\d*)\s+ (?P<mtu>\d*)\s+(?P<oper_mtu>\d*)\s+
(?P<oper_mtu>\d*)\s+
(?P<aggregated_interface>\d*)\s (?P<aggregated_interface>\d*)\s
""", """,
re.VERBOSE | re.MULTILINE | re.DOTALL, re.VERBOSE | re.MULTILINE | re.DOTALL,
...@@ -160,6 +158,16 @@ class Script(BaseScript): ...@@ -160,6 +158,16 @@ class Script(BaseScript):
""", """,
re.VERBOSE | re.MULTILINE | re.DOTALL, re.VERBOSE | re.MULTILINE | re.DOTALL,
) )
re_port_detail_info_sr = re.compile(
r"""
Description\s*?:\s(?P<description>.*?)\n
Interface\s*?:\s(?P<name>((esat-|)\d+/\d+/(c\d+|\d+)(/\d+|/u\d+|)|\w+\/\d+))\s*[\S\s]+
Admin\sState\s*?:\s(?P<admin_status>.*?)\s.*?
Oper\sState\s*?:\s(?P<oper_status>.*?)\s.*?
IfIndex\s*?:\s(?P<snmp_ifindex>\d*)\s.*?
""",
re.VERBOSE | re.MULTILINE | re.DOTALL,
)
re_lag_detail = re.compile( re_lag_detail = re.compile(
r""" r"""
Description\s*?:\s(?P<description>.+?)\n-{79} Description\s*?:\s(?P<description>.+?)\n-{79}
...@@ -500,14 +508,15 @@ class Script(BaseScript): ...@@ -500,14 +508,15 @@ class Script(BaseScript):
def get_base_router(self): def get_base_router(self):
fi = {"forwarding_instance": "default", "type": "ip", "interfaces": []} fi = {"forwarding_instance": "default", "type": "ip", "interfaces": []}
port_info = self.cli("show port") port_info = self.cli("show port")
for line in port_info.splitlines(): for line in port_info.splitlines():
match = self.re_port_info.search(line) match = self.re_port_info.search(line)
if match: if match:
port_detail = self.cli("show port %s detail" % match.group("name")) port_detail = self.cli("show port %s detail" % match.group("name"))
print(port_detail)
match_detail = self.re_port_detail_info.search(port_detail) match_detail = self.re_port_detail_info.search(port_detail)
if not match_detail:
match_detail = self.re_port_detail_info_sr.search(port_detail)
my_dict = match.groupdict() my_dict = match.groupdict()
my_dict.update(match_detail.groupdict()) my_dict.update(match_detail.groupdict())
if "aggregated_interface" in my_dict: if "aggregated_interface" in my_dict:
......
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