Skip to content

Commit

Permalink
fix(panos_static_route): invalid nexthop for none value
Browse files Browse the repository at this point in the history
This change also requires an update on pan-os-python to accept 'none'
value for the nexthop type.
  • Loading branch information
alperenkose committed Oct 10, 2024
1 parent 91d873d commit d067d91
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions plugins/modules/panos_static_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,30 @@

class Helper(ConnectionHelper):
def spec_handling(self, spec, module):
if module.params["state"] == "present" and spec["nexthop_type"] is None:
# need this because we dont have the default assignment in sdk-params and
# `None` value params are being removed in ParamPath.element method (called via VersionedPanObject.element)
spec["nexthop_type"] = "ip-address"

# default to ip-address when nexthop is set in merged state
# we dont know if object exists or not in merged state, and we dont set default values in module invocation
# in order to avoid unintended updates to non-provided params, but if nexthop is given, type must be ip-address
if module.params["state"] == "merged" and spec["nexthop_type"] is None and spec["nexthop"] is not None:
spec["nexthop_type"] = "ip-address"

# NOTE merged state have a lot of API issues for updating nexthop we will let the API return it..
# from None to IP address - "Failed update nexthop_type: Edit breaks config validity"
# from IP address to next-vr - "Failed update nexthop_type: Edit breaks config validity"

# applies for updating existing routes from IP/next-vr/discard to none
# however it works for new objects, we ignore this as this is the existing implementation
if module.params["state"] == "merged" and spec["nexthop_type"] == "none":
msg = [
"Nexthop cannot be set to None with state='merged'.",
"You will need to use either state='present' or state='replaced'.",
]
module.fail_json(msg=" ".join(msg))

if spec["nexthop_type"] == "none":
spec["nexthop_type"] = None


def main():
Expand All @@ -182,7 +197,6 @@ def main():
name=dict(required=True),
destination=dict(),
nexthop_type=dict(
default="ip-address",
choices=["ip-address", "discard", "none", "next-vr"],
),
nexthop=dict(),
Expand All @@ -193,6 +207,9 @@ def main():
failure_condition=dict(choices=["any", "all"]),
preemptive_hold_time=dict(type="int"),
),
default_values=dict(
nexthop_type="ip-address",
),
)

module = AnsibleModule(
Expand Down

0 comments on commit d067d91

Please sign in to comment.