Skip to content

Commit 0770843

Browse files
authored
Use the as_number helper function to ensure correct ASN format (#1191)
1 parent 5003cfc commit 0770843

File tree

3 files changed

+115
-5
lines changed

3 files changed

+115
-5
lines changed

napalm/eos/eos.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,11 @@ def get_re_group(res, key, default=None):
530530
v6_stats = re.match(self._RE_BGP_PREFIX, lines.pop(0))
531531
local_as = re.match(self._RE_BGP_LOCAL, lines.pop(0))
532532
data = {
533-
"remote_as": int(neighbor_info.group("as")),
533+
"remote_as": napalm.base.helpers.as_number(neighbor_info.group("as")),
534534
"remote_id": napalm.base.helpers.ip(
535535
get_re_group(rid_info, "rid", "0.0.0.0")
536536
),
537-
"local_as": int(local_as.group("as")),
537+
"local_as": napalm.base.helpers.as_number(local_as.group("as")),
538538
"description": str(desc),
539539
"address_family": {
540540
"ipv4": {
@@ -871,7 +871,9 @@ def parse_options(options, default_value=False):
871871
default_value = False
872872
bgp_conf_line = bgp_conf_line.strip()
873873
if bgp_conf_line.startswith("router bgp"):
874-
local_as = int(bgp_conf_line.replace("router bgp", "").strip())
874+
local_as = napalm.base.helpers.as_number(
875+
(bgp_conf_line.replace("router bgp", "").strip())
876+
)
875877
continue
876878
if not (
877879
bgp_conf_line.startswith("neighbor")
@@ -1262,7 +1264,7 @@ def get_route_to(self, destination="", protocol="", longer=False):
12621264
)
12631265

12641266
vrf_details = vrf_cache.get(_vrf)
1265-
local_as = vrf_details.get("asn")
1267+
local_as = napalm.base.helpers.as_number(vrf_details.get("asn"))
12661268
bgp_routes = (
12671269
vrf_details.get("bgpRouteEntries", {})
12681270
.get(prefix, {})
@@ -1279,7 +1281,9 @@ def get_route_to(self, destination="", protocol="", longer=False):
12791281
if as_path_type in ["Internal", "Local"]:
12801282
remote_as = local_as
12811283
else:
1282-
remote_as = int(as_path.strip("()").split()[-1])
1284+
remote_as = napalm.base.helpers.as_number(
1285+
as_path.strip("()").split()[-1]
1286+
)
12831287
remote_address = napalm.base.helpers.ip(
12841288
bgp_route_details.get("routeDetail", {})
12851289
.get("peerEntry", {})
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"IPv4-PEERS-GROUP-NAME": {
3+
"type": "",
4+
"multipath": false,
5+
"apply_groups": [],
6+
"remove_private_as": true,
7+
"multihop_ttl": 0,
8+
"remote_as": 0,
9+
"local_address": "",
10+
"local_as": 4266524237,
11+
"description": "",
12+
"import_policy": "reject-all",
13+
"export_policy": "4-public-peer-anycast-out",
14+
"prefix_limit": {},
15+
"neighbors": {
16+
"192.168.0.1": {
17+
"description": "",
18+
"remote_as": 32934,
19+
"local_address": "",
20+
"local_as": 4266524237,
21+
"nhs": false,
22+
"route_reflector_client": false,
23+
"import_policy": "",
24+
"export_policy": "",
25+
"authentication_key": "",
26+
"prefix_limit": {}
27+
},
28+
"172.17.17.1": {
29+
"description": "",
30+
"remote_as": 13414,
31+
"local_address": "",
32+
"local_as": 4266524237,
33+
"nhs": false,
34+
"route_reflector_client": false,
35+
"import_policy": "",
36+
"export_policy": "",
37+
"authentication_key": "",
38+
"prefix_limit": {}
39+
}
40+
}
41+
},
42+
"IPv6-PEERS-GROUP-NAME": {
43+
"type": "",
44+
"multipath": false,
45+
"apply_groups": [],
46+
"remove_private_as": true,
47+
"multihop_ttl": 0,
48+
"remote_as": 0,
49+
"local_address": "",
50+
"local_as": 4266524237,
51+
"description": "",
52+
"import_policy": "reject-all",
53+
"export_policy": "reject-all",
54+
"prefix_limit": {},
55+
"neighbors": {
56+
"2001:db8::0:1": {
57+
"description": "",
58+
"remote_as": 8403,
59+
"local_address": "",
60+
"local_as": 4266524237,
61+
"nhs": false,
62+
"route_reflector_client": false,
63+
"import_policy": "",
64+
"export_policy": "",
65+
"authentication_key": "",
66+
"prefix_limit": {}
67+
},
68+
"2001:db8::0:2": {
69+
"description": "",
70+
"remote_as": 54113,
71+
"local_address": "",
72+
"local_as": 4266524237,
73+
"nhs": false,
74+
"route_reflector_client": false,
75+
"import_policy": "",
76+
"export_policy": "",
77+
"authentication_key": "",
78+
"prefix_limit": {}
79+
}
80+
}
81+
}
82+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
router bgp 65101.65101
2+
maximum-paths 32
3+
neighbor IPv4-PEERS-GROUP-NAME peer-group
4+
neighbor IPv4-PEERS-GROUP-NAME remove-private-as
5+
neighbor IPv4-PEERS-GROUP-NAME route-map reject-all in
6+
neighbor IPv4-PEERS-GROUP-NAME route-map 4-public-peer-anycast-out out
7+
neighbor IPv4-PEERS-GROUP-NAME maximum-routes 500
8+
neighbor IPv6-PEERS-GROUP-NAME peer-group
9+
neighbor IPv6-PEERS-GROUP-NAME remove-private-as
10+
neighbor IPv6-PEERS-GROUP-NAME route-map reject-all in
11+
neighbor IPv6-PEERS-GROUP-NAME route-map reject-all out
12+
neighbor IPv6-PEERS-GROUP-NAME maximum-routes 100
13+
neighbor 192.168.0.1 peer-group IPv4-PEERS-GROUP-NAME
14+
neighbor 192.168.0.1 remote-as 32934
15+
neighbor 192.168.0.1 maximum-routes 100
16+
neighbor 172.17.17.1 peer-group IPv4-PEERS-GROUP-NAME
17+
neighbor 172.17.17.1 remote-as 13414
18+
neighbor 172.17.17.1 maximum-routes 500
19+
neighbor 2001:db8::0:1 peer-group IPv6-PEERS-GROUP-NAME
20+
neighbor 2001:db8::0:1 remote-as 8403
21+
neighbor 2001:db8::0:1 maximum-routes 500
22+
neighbor 2001:db8::0:2 peer-group IPv6-PEERS-GROUP-NAME
23+
neighbor 2001:db8::0:2 remote-as 54113
24+
!

0 commit comments

Comments
 (0)