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 05f7063
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ 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 +1304,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,6 +1318,9 @@ 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:
Expand All @@ -1335,6 +1342,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 +1363,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 +1418,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 +1441,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 Expand Up @@ -2128,7 +2132,6 @@ def ping(
vrf=C.PING_VRF,
source_interface=C.PING_SOURCE_INTERFACE,
):

ping_dict = {}

source_str = ""
Expand Down Expand Up @@ -2458,7 +2461,6 @@ def get_config(self, retrieve="all", full=False, sanitized=False):
return rv

def get_network_instances(self, name=""):

network_instances = {}

ri_table = junos_views.junos_nw_instances_table(self.device)
Expand Down

0 comments on commit 05f7063

Please sign in to comment.