Skip to content

Commit e7760fb

Browse files
committed
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<intf>[A-Za-z][-A-Za-z0-9/.:]+)$'` - Introduced `in_interfaces_section` flag for accurate section tracking
1 parent aaf4022 commit e7760fb

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/genie/libs/parser/iosxr/show_vrf.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def cli(self, vrf='', output=None):
6161
vrf_dict = {}
6262
af_dict = {}
6363
rt_type = None
64+
in_interfaces_section = False # Initialize here
6465

6566
for line in out.splitlines():
6667
line = line.replace('\t', ' ')
@@ -107,18 +108,22 @@ def cli(self, vrf='', output=None):
107108
m = p4.match(line)
108109
if m:
109110
vrf_dict[vrf]['interfaces'] = []
111+
in_interfaces_section = True
110112
continue
111-
# GigabitEthernet0/0/0/0.390
112-
# Bundle-Ether15.514
113-
p4_1 = re.compile(r'^(?P<intf>([G|g]i.*|[B|b]un.*|'
114-
r'[T|t]en.*|[P|p]o.*|[V|v]lan.*|'
115-
r'[L|l]o.*))$')
116113

117-
m = p4_1.match(line)
118-
if m:
119-
intf = m.groupdict()['intf']
120-
vrf_dict[vrf]['interfaces'].append(intf)
121-
continue
114+
if in_interfaces_section:
115+
# Match interface lines
116+
# GigabitEthernet0/0/0/0.390
117+
# Bundle-Ether15.514
118+
p4_1 = re.compile(r'^(?P<intf>[A-Za-z][-A-Za-z0-9/.:]+)$')
119+
m = p4_1.match(line)
120+
if m:
121+
intf = m.groupdict()['intf']
122+
vrf_dict[vrf]['interfaces'].append(intf)
123+
continue
124+
else:
125+
# Exit the Interfaces section when a non-interface line is encountered
126+
in_interfaces_section = False
122127

123128
# Address family IPV4 Unicast
124129
p5 = re.compile(r'^Address +family +(?P<af>[\w\s]+)$')

0 commit comments

Comments
 (0)