From e7760fbc9eb81aa3701f9a8f195dafb771a698a2 Mon Sep 17 00:00:00 2001 From: Jan Krupa Date: Fri, 8 Nov 2024 10:32:55 +0100 Subject: [PATCH] Enhance interface parsing in 'show vrf all detail' parser - Implemented a general regex pattern to capture all interface names - Replaced the previous regex that relied on specific interface prefixes (e.g., Gi, Bun, Ten, etc.) with a more general pattern `r'^(?P[A-Za-z][-A-Za-z0-9/.:]+)$'` - Introduced `in_interfaces_section` flag for accurate section tracking --- src/genie/libs/parser/iosxr/show_vrf.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/genie/libs/parser/iosxr/show_vrf.py b/src/genie/libs/parser/iosxr/show_vrf.py index 6853531210..6f012bf2e8 100755 --- a/src/genie/libs/parser/iosxr/show_vrf.py +++ b/src/genie/libs/parser/iosxr/show_vrf.py @@ -61,6 +61,7 @@ def cli(self, vrf='', output=None): vrf_dict = {} af_dict = {} rt_type = None + in_interfaces_section = False # Initialize here for line in out.splitlines(): line = line.replace('\t', ' ') @@ -107,18 +108,22 @@ def cli(self, vrf='', output=None): m = p4.match(line) if m: vrf_dict[vrf]['interfaces'] = [] + in_interfaces_section = True continue - # GigabitEthernet0/0/0/0.390 - # Bundle-Ether15.514 - p4_1 = re.compile(r'^(?P([G|g]i.*|[B|b]un.*|' - r'[T|t]en.*|[P|p]o.*|[V|v]lan.*|' - r'[L|l]o.*))$') - m = p4_1.match(line) - if m: - intf = m.groupdict()['intf'] - vrf_dict[vrf]['interfaces'].append(intf) - continue + if in_interfaces_section: + # Match interface lines + # GigabitEthernet0/0/0/0.390 + # Bundle-Ether15.514 + p4_1 = re.compile(r'^(?P[A-Za-z][-A-Za-z0-9/.:]+)$') + m = p4_1.match(line) + if m: + intf = m.groupdict()['intf'] + vrf_dict[vrf]['interfaces'].append(intf) + continue + else: + # Exit the Interfaces section when a non-interface line is encountered + in_interfaces_section = False # Address family IPV4 Unicast p5 = re.compile(r'^Address +family +(?P[\w\s]+)$')