Skip to content

Commit

Permalink
Enhance interface parsing in 'show vrf all detail' parser
Browse files Browse the repository at this point in the history
- 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<intf>[A-Za-z][-A-Za-z0-9/.:]+)$'`
- Introduced `in_interfaces_section` flag for accurate section tracking
  • Loading branch information
Kani999 committed Dec 2, 2024
1 parent aaf4022 commit e7760fb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/genie/libs/parser/iosxr/show_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ' ')
Expand Down Expand Up @@ -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<intf>([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<intf>[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<af>[\w\s]+)$')
Expand Down

0 comments on commit e7760fb

Please sign in to comment.