Skip to content

Commit

Permalink
add documentation and example
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-perByte committed Oct 5, 2024
1 parent 8dfcb66 commit a32cb52
Show file tree
Hide file tree
Showing 3 changed files with 913 additions and 35 deletions.
31 changes: 21 additions & 10 deletions plugins/module_utils/network/iosxr/config/route_maps/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _compare(self, want, have, policy_name):
"""
append_endif = False
append_nested_endif = False
append_else_once = True
order_list = [
"global",
"if_",
Expand All @@ -163,27 +164,37 @@ def _compare(self, want, have, policy_name):
if self.state in ["replaced", "overridden"]:
# cannot add commands on a adhoc manner it replaces the whole config
h_policy_config = {}

render_condition = {
"condition": w_policy_config.pop("condition", ""),
"condition_type": w_policy_config.pop("conf_type"),
}
} # required to generate conditional statements

begin_endif = len(self.commands) # handle elseif conditions

if check_cond.startswith("elseHas_"):
if append_else_once:
self.commands.append("else")
append_else_once = False

begin_endif = len(self.commands)
if render_condition.get("condition_type") != "global":
self.addcmd(render_condition, "condition", negate=False)
self.addcmd(
render_condition, "condition", negate=False
) # condition commands added here
if w_policy_config.get("apply"): # as apply is a list
w_apply_config = w_policy_config.pop("apply", {})
h_apply_config = h_policy_config.pop("apply", {})
for w_name, w_apply in w_apply_config.items():
h_apply = h_apply_config.pop(w_name, {})
# apply config added here
self.compare(
parsers=[
"apply",
],
want={"apply": w_apply},
have={"apply": h_apply},
)

# route-policy configs added here
self.compare(parsers=self.parsers, want=w_policy_config, have=h_policy_config)
if len(self.commands) != begin_endif and w_condition.startswith("if_"):
# if we want to add any condition we have to start with if
Expand Down Expand Up @@ -225,17 +236,17 @@ def process_apply(apply_conf):
if cond == "global":
temp_rmap[cond] = rm_conf
else:
temp_rmap[cond + "_" + (rm_conf.get("condition").replace(" ", "_"))] = (
rm_conf
)
temp_rmap[
cond + "_" + (rm_conf.get("condition").replace(" ", "_"))
] = rm_conf
elif cond == "elseif":
for elif_config in rm_conf:
if elif_config.get("apply"):
elif_config["apply"] = process_apply(elif_config.get("apply"))
elif_config["conf_type"] = cond
temp_rmap[cond + "_" + (elif_config.get("condition").replace(" ", "_"))] = (
elif_config
)
temp_rmap[
cond + "_" + (elif_config.get("condition").replace(" ", "_"))
] = elif_config
elif (
cond == "else"
): # wanted to do recursion but the overall performance is better this way
Expand Down
Loading

0 comments on commit a32cb52

Please sign in to comment.