Skip to content

Commit e085d4e

Browse files
author
Jamie Reid
committed
Adjusts parser for "show ap cdp neighbor"
Resolves #723 Adjust regex to include the ap neighbor IP as it is output on 9800 platform v17.x
1 parent 2864ef4 commit e085d4e

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--------------------------------------------------------------------------------
2+
Fix
3+
--------------------------------------------------------------------------------
4+
* IOSXE
5+
* Modified ShowApCdpNeighbor:
6+
* Updated regex pattern neighbor_info_capture to optionally capture the Neighbors IP if it exists

src/genie/libs/parser/iosxe/show_ap.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

33
from genie.metaparser import MetaParser
4-
from genie.metaparser.util.schemaengine import Any, Optional, Or
4+
from genie.metaparser.util.schemaengine import Any, Optional, Or, ListOf
55

66

77
# ====================
@@ -1149,7 +1149,7 @@ class ShowApCdpNeighborSchema(MetaParser):
11491149
Optional("neighbor_name"): str,
11501150
Optional("neighbor_port"): str,
11511151
Optional("neighbor_ip_count"): int,
1152-
Optional("neighbor_ip_addresses"): list
1152+
Optional("neighbor_ip_addresses"): ListOf(str)
11531153
}
11541154
}
11551155
}
@@ -1199,8 +1199,9 @@ def cli(self, output=None):
11991199

12001200
neighbor_count_capture = re.compile(r"^Number\s+of\s+neighbors:\s+(?P<neighbor_count>\d+)$")
12011201
# 0221-cap22 10.8.33.106 a02-21-sd-sw1.cisco.com TenGigabitEthernet3/0/47
1202+
# 0221-cap22 10.8.33.106 a02-21-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet3/0/47
12021203
neighbor_info_capture = re.compile(
1203-
r"^(?P<ap_name>\S+)\s+(?P<ap_ip>\d+\.\d+\.\d+\.\d+)\s+(?P<neighbor_name>\S+)\s+(?P<neighbor_port>\S+)$")
1204+
r"^(?P<ap_name>\S+)\s+(?P<ap_ip>\d+\.\d+\.\d+\.\d+)\s+(?P<neighbor_name>\S+)(\s+(?P<neighbor_ip>\S+))?\s+(?P<neighbor_port>\S+)$")
12041205
# Neighbor IP Count: 1
12051206
neighbor_ip_count_capture = re.compile(r"^Neighbor\s+IP\s+Count:\s+(?P<neighbor_ip_count>\d+)$")
12061207
# 10.8.32.1
@@ -1222,6 +1223,7 @@ def cli(self, output=None):
12221223
elif line.startswith('-----'):
12231224
continue
12241225
# 0221-cap22 10.8.33.106 a02-21-sd-sw1.cisco.com TenGigabitEthernet3/0/47
1226+
# 0221-cap22 10.8.33.106 a02-21-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet3/0/47
12251227
elif neighbor_info_capture.match(line):
12261228
neighbor_info_capture_match = neighbor_info_capture.match(line)
12271229
groups = neighbor_info_capture_match.groupdict()
@@ -1235,6 +1237,11 @@ def cli(self, output=None):
12351237
ap_cdp_neighbor_dict['ap_name'][ap_name]['ap_ip'] = ap_ip
12361238
ap_cdp_neighbor_dict['ap_name'][ap_name]['neighbor_name'] = neighbor_name
12371239
ap_cdp_neighbor_dict['ap_name'][ap_name]['neighbor_port'] = neighbor_port
1240+
if groups['neighbor_ip']:
1241+
neighbor_ip = groups['neighbor_ip']
1242+
address_list = ap_cdp_neighbor_dict['ap_name'][ap_name].setdefault('neighbor_ip_addresses', [])
1243+
address_list.append(neighbor_ip)
1244+
12381245
# Neighbor IP Count: 1
12391246
elif neighbor_ip_count_capture.match(line):
12401247
neighbor_ip_count_match = neighbor_ip_count_capture.match(line)
@@ -3198,4 +3205,4 @@ def filter_lines(raw_output, remove_lines):
31983205
ap_image_data = {}
31993206
continue
32003207

3201-
return ap_image_dict
3208+
return ap_image_dict
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
expected_output = {
2+
"ap_cdp_neighbor_count": 149,
3+
"ap_name": {
4+
"0221-cap22": {
5+
"ap_ip": "10.8.33.106",
6+
"neighbor_name": "a02-21-sd-sw1.cisco.com",
7+
"neighbor_port": "TenGigabitEthernet3/0/47",
8+
"neighbor_ip_addresses": ["10.8.32.1"],
9+
},
10+
"0232-cap15": {
11+
"ap_ip": "10.8.32.46",
12+
"neighbor_name": "a02-32-sd-sw1.cisco.com",
13+
"neighbor_port": "TenGigabitEthernet9/0/47",
14+
"neighbor_ip_addresses": ["10.8.32.1"],
15+
},
16+
"0211-cap27": {
17+
"ap_ip": "10.8.32.188",
18+
"neighbor_name": "a02-11-sd-sw1.cisco.com",
19+
"neighbor_port": "TenGigabitEthernet4/0/46",
20+
"neighbor_ip_addresses": ["10.8.32.1"],
21+
},
22+
"0212-cap11": {
23+
"ap_ip": "10.8.33.160",
24+
"neighbor_name": "a02-12-sd-sw2.cisco.com",
25+
"neighbor_port": "TenGigabitEthernet1/0/40",
26+
"neighbor_ip_addresses": ["10.8.32.1"],
27+
},
28+
"0212-cap10": {
29+
"ap_ip": "10.8.33.102",
30+
"neighbor_name": "a02-12-sd-sw1.cisco.com",
31+
"neighbor_port": "TenGigabitEthernet1/0/43",
32+
"neighbor_ip_addresses": ["10.8.32.1"],
33+
},
34+
"0212-cap17": {
35+
"ap_ip": "10.8.32.203",
36+
"neighbor_name": "a02-12-sd-sw2.cisco.com",
37+
"neighbor_port": "TenGigabitEthernet1/0/47",
38+
"neighbor_ip_addresses": ["10.8.32.1"],
39+
},
40+
"0212-ca.4": {
41+
"ap_ip": "10.8.32.202",
42+
"neighbor_name": "a02-12-sd-sw1.cisco.com",
43+
"neighbor_port": "TenGigabitEthernet1/0/48",
44+
"neighbor_ip_addresses": ["10.8.32.1"],
45+
},
46+
"0222-cap09": {
47+
"ap_ip": "10.8.33.33",
48+
"neighbor_name": "a02-22-sd-sw2.cisco.com",
49+
"neighbor_port": "TenGigabitEthernet8/0/48",
50+
"neighbor_ip_addresses": ["10.8.32.1"],
51+
},
52+
"0231-cap43": {
53+
"ap_ip": "10.8.33.93",
54+
"neighbor_name": "a02-31-sd-sw1.cisco.com",
55+
"neighbor_port": "TenGigabitEthernet4/0/47",
56+
"neighbor_ip_addresses": ["10.8.32.1"],
57+
},
58+
"0222-cap08": {
59+
"ap_ip": "10.8.32.166",
60+
"neighbor_name": "a02-22-sd-sw2.cisco.com",
61+
"neighbor_port": "TenGigabitEthernet4/0/47",
62+
"neighbor_ip_addresses": ["10.8.32.1"],
63+
},
64+
},
65+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Number of neighbors: 149
2+
3+
AP Name AP IP Neighbor Name Neighbor IP Neighbor Port
4+
-------------------------------------------------------------------------------------------------------------------------------------------------------------
5+
0221-cap22 10.8.33.106 a02-21-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet3/0/47
6+
0232-cap15 10.8.32.46 a02-32-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet9/0/47
7+
0211-cap27 10.8.32.188 a02-11-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet4/0/46
8+
0212-cap11 10.8.33.160 a02-12-sd-sw2.cisco.com 10.8.32.1 TenGigabitEthernet1/0/40
9+
0212-cap10 10.8.33.102 a02-12-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet1/0/43
10+
0212-cap17 10.8.32.203 a02-12-sd-sw2.cisco.com 10.8.32.1 TenGigabitEthernet1/0/47
11+
0212-ca.4 10.8.32.202 a02-12-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet1/0/48
12+
0222-cap09 10.8.33.33 a02-22-sd-sw2.cisco.com 10.8.32.1 TenGigabitEthernet8/0/48
13+
0231-cap43 10.8.33.93 a02-31-sd-sw1.cisco.com 10.8.32.1 TenGigabitEthernet4/0/47
14+
0222-cap08 10.8.32.166 a02-22-sd-sw2.cisco.com 10.8.32.1 TenGigabitEthernet4/0/47

0 commit comments

Comments
 (0)