Skip to content

Commit

Permalink
fix: restrict group names inside the bgp config
Browse files Browse the repository at this point in the history
  • Loading branch information
talves committed May 23, 2023
1 parent f1ce50e commit 4eb0dea
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,11 @@ def build_prefix_limit(**args):
}
_GROUP_FIELDS_DATATYPE_MAP_.update(_COMMON_FIELDS_DATATYPE_)

_UNWANTED_GROUP_FIELDS = [
"multihop",
"cluster"
]

_DATATYPE_DEFAULT_ = {str: "", int: 0, bool: False, list: []}

bgp_config = {}
Expand Down Expand Up @@ -1302,6 +1307,8 @@ def build_prefix_limit(**args):
is_nhs, boolean = is_nhs_list[0]
nhs_policies[policy_name] = boolean if boolean is not None else False

unwanted_group_fields = dict()

for bgp_group in bgp_items:
bgp_group_name = bgp_group[0]
bgp_group_details = bgp_group[1]
Expand All @@ -1314,7 +1321,8 @@ def build_prefix_limit(**args):
# Always overwrite with the system local_as (this will either be
# valid or will be zero i.e. the same as the default value).
bgp_config[bgp_group_name]["local_as"] = system_bgp_asn

unwanted_group_fields[bgp_group_name] = dict({key: False for key in _UNWANTED_GROUP_FIELDS})

for key, value in bgp_group_details:
if "_prefix_limit" in key or value is None:
continue
Expand All @@ -1335,6 +1343,9 @@ def build_prefix_limit(**args):
if key == "neighbors":
bgp_group_peers = value
continue
if key in _UNWANTED_GROUP_FIELDS:
unwanted_group_fields[bgp_group_name][key] = True
continue
bgp_config[bgp_group_name].update(
{key: napalm.base.helpers.convert(datatype, value, default)}
)
Expand All @@ -1353,9 +1364,7 @@ def build_prefix_limit(**args):
bgp_config[bgp_group_name]["prefix_limit"] = build_prefix_limit(
**prefix_limit_fields
)
if "multihop" in bgp_config[bgp_group_name].keys():
# Delete 'multihop' key from the output
del bgp_config[bgp_group_name]["multihop"]
if unwanted_group_fields[bgp_group_name]["multihop"]:
if bgp_config[bgp_group_name]["multihop_ttl"] == 0:
# Set ttl to default value 64
bgp_config[bgp_group_name]["multihop_ttl"] = 64
Expand Down Expand Up @@ -1410,7 +1419,7 @@ def build_prefix_limit(**args):
# we do not want cluster in the output
del bgp_peer_details["cluster"]

if "cluster" in bgp_config[bgp_group_name].keys():
if unwanted_group_fields[bgp_group_name]["cluster"]:
bgp_peer_details["route_reflector_client"] = True
prefix_limit_fields = {}
for key, value in bgp_group_details:
Expand All @@ -1433,10 +1442,6 @@ def build_prefix_limit(**args):
if neighbor and bgp_peer_address == neighbor_ip:
break # found the desired neighbor

if "cluster" in bgp_config[bgp_group_name].keys():
# we do not want cluster in the output
del bgp_config[bgp_group_name]["cluster"]

return bgp_config

def get_bgp_neighbors_detail(self, neighbor_address=""):
Expand Down

0 comments on commit 4eb0dea

Please sign in to comment.