Skip to content

Commit

Permalink
Merge branch 'fix11'
Browse files Browse the repository at this point in the history
  • Loading branch information
pierky committed Oct 14, 2017
2 parents d4f7239 + e935aaf commit a58e9b4
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions pierky/arouteserver/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,6 @@ def enrich_config(self):
if errors:
raise BuilderError()

@staticmethod
def community_is_set(comm):
"""Helper filter used by Jinja2 templates.
It's defined at class-level because different BGP-speaker-specific
builder classes may have a diffent way to treat communities:
OpenBGPD 6.0, for example, does not implement large communities, so
a community defined with only large values must have a return value
False.
"""
if not comm:
return False
if not comm["std"] and not comm["lrg"] and not comm["ext"]:
return False
return True

def _include_local_file(self, local_file_id):
raise NotImplementedError()

Expand Down Expand Up @@ -589,14 +573,21 @@ def get_normalized_rtt(v):
return 60000
return int(round(v))

def community_is_set(comm):
if not comm:
return False
if not comm["std"] and not comm["lrg"] and not comm["ext"]:
return False
return True

env = Environment(
loader=FileSystemLoader(self.template_dir),
trim_blocks=True,
lstrip_blocks=True,
undefined=StrictUndefined
)
env.tests["current_ipver"] = current_ipver
env.filters["community_is_set"] = self.community_is_set
env.filters["community_is_set"] = community_is_set
env.filters["ipaddr_ver"] = ipaddr_ver
env.filters["include_local_file"] = include_local_file
env.filters["target_version_ge"] = target_version_ge
Expand Down Expand Up @@ -713,14 +704,6 @@ class OpenBGPDConfigBuilder(ConfigBuilder):
"large_communities", "extended_communities",
"graceful_shutdown"]

@staticmethod
def community_is_set(comm):
if not comm:
return False
if not comm["std"] and not comm["ext"]:
return False
return True

def _include_local_file(self, local_file_id):
return 'include "{}"\n\n'.format(
os.path.join(
Expand Down Expand Up @@ -961,7 +944,21 @@ def at_least_one_client_uses_tag_reject_policy():
return True
return False

def community_is_set(comm):
if not comm:
return False
# OpenBGPD <= 6.0 does not implement large BGP communities,
# so only standard and extended ones are considered.
if version.parse(self.target_version or "6.0") < version.parse("6.1"):
if not comm["std"] and not comm["ext"]:
return False
else:
if not comm["std"] and not comm["ext"] and not comm["lrg"]:
return False
return True

env.filters["convert_ext_comm"] = convert_ext_comm
env.filters["community_is_set"] = community_is_set
self.data["at_least_one_client_uses_tag_reject_policy"] = \
at_least_one_client_uses_tag_reject_policy()

Expand Down

0 comments on commit a58e9b4

Please sign in to comment.