Skip to content

Commit

Permalink
[ignore] Rebased with latest master to include append_update_ops_data
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana committed Dec 4, 2024
1 parent 1315c6b commit a3d118b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 157 deletions.
12 changes: 1 addition & 11 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def recursive_replace(data, path, keys, new_value):
key = keys[0]
if len(keys) == 1:
# Update the existing configuration
if new_value is not None and data.get(key) != new_value and op == "replace":
if new_value is not None and data.get(key) != new_value:
data[key] = new_value
ops.append(
dict(
Expand All @@ -114,16 +114,6 @@ def recursive_replace(data, path, keys, new_value):
value=copy.deepcopy(new_value),
)
)
# Clear the existing configuration
elif op == "remove" and key in data:
data.pop(key)
ops.append(
dict(
op=op,
path="{}/{}".format(path, key),
)
)

elif key in data:
recursive_replace(data[key], "{}/{}".format(path, key), keys[1:], new_value)

Expand Down
184 changes: 38 additions & 146 deletions plugins/modules/ndo_l3out_interface_routing_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,178 +430,70 @@ def main():
if state == "present":
if mso.existing:
proposed_payload = copy.deepcopy(mso.existing)
replace_data = dict()
remove_data = list()

append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, name, "name")

append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, description, "description")
replace_data["name"] = name
replace_data["description"] = description

# BFD MultiHop Settings
if bfd_multi_hop_settings is not None:
if bfd_multi_hop_settings.get("state") == "disabled" and proposed_payload.get("bfdMultiHopPol"):
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, None, "bfdMultiHopPol", op="remove")
remove_data.append("bfdMultiHopPol")

elif bfd_multi_hop_settings.get("state") != "disabled":
if not proposed_payload.get("bfdMultiHopPol"):
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, dict(), "bfdMultiHopPol")

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, bfd_multi_hop_settings.get("admin_state"), "bfdMultiHopPol", "adminState"
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
bfd_multi_hop_settings.get("detection_multiplier"),
"bfdMultiHopPol",
"detectionMultiplier",
)
replace_data["bfdMultiHopPol"] = dict()

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
bfd_multi_hop_settings.get("min_receive_interval"),
"bfdMultiHopPol",
"minRxInterval",
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
bfd_multi_hop_settings.get("min_transmit_interval"),
"bfdMultiHopPol",
"minTxInterval",
)
replace_data[("bfdMultiHopPol", "adminState")] = bfd_multi_hop_settings.get("admin_state")
replace_data[("bfdMultiHopPol", "detectionMultiplier")] = bfd_multi_hop_settings.get("detection_multiplier")
replace_data[("bfdMultiHopPol", "minRxInterval")] = bfd_multi_hop_settings.get("min_receive_interval")
replace_data[("bfdMultiHopPol", "minTxInterval")] = bfd_multi_hop_settings.get("min_transmit_interval")

# BFD Settings
if bfd_settings is not None:
if bfd_settings.get("state") == "disabled" and proposed_payload.get("bfdPol"):
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, None, "bfdPol", op="remove")
remove_data.append("bfdPol")

elif bfd_settings.get("state") != "disabled":
if not proposed_payload.get("bfdPol"):
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, dict(), "bfdPol")

append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, bfd_settings.get("admin_state"), "bfdPol", "adminState")

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, bfd_settings.get("detection_multiplier"), "bfdPol", "detectionMultiplier"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, bfd_settings.get("min_receive_interval"), "bfdPol", "minRxInterval"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, bfd_settings.get("min_transmit_interval"), "bfdPol", "minTxInterval"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, bfd_settings.get("echo_receive_interval"), "bfdPol", "echoRxInterval"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, bfd_settings.get("echo_admin_state"), "bfdPol", "echoAdminState"
)
replace_data["bfdPol"] = dict()

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
ENABLED_DISABLED_BOOLEAN_MAP.get(bfd_settings.get("interface_control")),
"bfdPol",
"ifControl",
)
replace_data[("bfdPol", "adminState")] = bfd_settings.get("admin_state")
replace_data[("bfdPol", "detectionMultiplier")] = bfd_settings.get("detection_multiplier")
replace_data[("bfdPol", "minRxInterval")] = bfd_settings.get("min_receive_interval")
replace_data[("bfdPol", "minTxInterval")] = bfd_settings.get("min_transmit_interval")
replace_data[("bfdPol", "echoRxInterval")] = bfd_settings.get("echo_receive_interval")
replace_data[("bfdPol", "echoAdminState")] = bfd_settings.get("echo_admin_state")
replace_data[("bfdPol", "ifControl")] = ENABLED_DISABLED_BOOLEAN_MAP.get(bfd_settings.get("interface_control"))

# OSPF Interface Settings
if ospf_interface_settings is not None:
if ospf_interface_settings.get("state") == "disabled" and proposed_payload.get("ospfIntfPol"):
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, None, "ospfIntfPol", op="remove")
remove_data.append(("ospfIntfPol",))

elif ospf_interface_settings.get("state") != "disabled":
if not proposed_payload.get("ospfIntfPol"):
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, dict(), "ospfIntfPol")
append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, dict(), "ospfIntfPol", "ifControl")

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
get_ospf_network_type(ospf_interface_settings.get("network_type")),
"ospfIntfPol",
"networkType",
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, ospf_interface_settings.get("priority"), "ospfIntfPol", "prio"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, ospf_interface_settings.get("cost_of_interface"), "ospfIntfPol", "cost"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, ospf_interface_settings.get("hello_interval"), "ospfIntfPol", "helloInterval"
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, ospf_interface_settings.get("dead_interval"), "ospfIntfPol", "deadInterval"
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
ospf_interface_settings.get("retransmit_interval"),
"ospfIntfPol",
"retransmitInterval",
)

append_update_ops_data(
ops, proposed_payload, interface_routing_policy_path, ospf_interface_settings.get("transmit_delay"), "ospfIntfPol", "transmitDelay"
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
ENABLED_DISABLED_BOOLEAN_MAP.get(ospf_interface_settings.get("advertise_subnet")),
"ospfIntfPol",
"ifControl",
"advertiseSubnet",
replace_data[("ospfIntfPol")] = dict()
replace_data[("ospfIntfPol", "ifControl")] = dict()

replace_data[("ospfIntfPol", "networkType")] = get_ospf_network_type(ospf_interface_settings.get("network_type"))
replace_data[("ospfIntfPol", "prio")] = ospf_interface_settings.get("priority")
replace_data[("ospfIntfPol", "cost")] = ospf_interface_settings.get("cost_of_interface")
replace_data[("ospfIntfPol", "helloInterval")] = ospf_interface_settings.get("hello_interval")
replace_data[("ospfIntfPol", "deadInterval")] = ospf_interface_settings.get("dead_interval")
replace_data[("ospfIntfPol", "retransmitInterval")] = ospf_interface_settings.get("retransmit_interval")
replace_data[("ospfIntfPol", "transmitDelay")] = ospf_interface_settings.get("transmit_delay")
replace_data[("ospfIntfPol", "ifControl", "advertiseSubnet")] = ENABLED_DISABLED_BOOLEAN_MAP.get(
ospf_interface_settings.get("advertise_subnet")
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
ENABLED_DISABLED_BOOLEAN_MAP.get(ospf_interface_settings.get("bfd")),
"ospfIntfPol",
"ifControl",
"bfd",
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
ENABLED_DISABLED_BOOLEAN_MAP.get(ospf_interface_settings.get("mtu_ignore")),
"ospfIntfPol",
"ifControl",
"ignoreMtu",
)

append_update_ops_data(
ops,
proposed_payload,
interface_routing_policy_path,
ENABLED_DISABLED_BOOLEAN_MAP.get(ospf_interface_settings.get("passive_participation")),
"ospfIntfPol",
"ifControl",
"passiveParticipation",
replace_data[("ospfIntfPol", "ifControl", "bfd")] = ENABLED_DISABLED_BOOLEAN_MAP.get(ospf_interface_settings.get("bfd"))
replace_data[("ospfIntfPol", "ifControl", "ignoreMtu")] = ENABLED_DISABLED_BOOLEAN_MAP.get(ospf_interface_settings.get("mtu_ignore"))
replace_data[("ospfIntfPol", "ifControl", "passiveParticipation")] = ENABLED_DISABLED_BOOLEAN_MAP.get(
ospf_interface_settings.get("passive_participation")
)

append_update_ops_data(ops, proposed_payload, interface_routing_policy_path, replace_data, remove_data)
mso.sanitize(proposed_payload)
else:
payload = dict(name=name, description=description)
Expand Down

0 comments on commit a3d118b

Please sign in to comment.