Skip to content

Commit

Permalink
feat(panos_zone): Add network resource module states
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Jul 26, 2022
1 parent 85f1042 commit 419f2f2
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions plugins/modules/panos_zone.py
Expand Up @@ -38,7 +38,7 @@
- Check mode is supported.
extends_documentation_fragment:
- paloaltonetworks.panos.fragments.transitional_provider
- paloaltonetworks.panos.fragments.state
- paloaltonetworks.panos.fragments.network_resource_module_state
- paloaltonetworks.panos.fragments.full_template_support
- paloaltonetworks.panos.fragments.vsys
options:
Expand Down Expand Up @@ -135,11 +135,9 @@
)

try:
from panos.errors import PanDeviceError
from panos.network import Zone
except ImportError:
try:
from pandevice.errors import PanDeviceError
from pandevice.network import Zone
except ImportError:
pass
Expand All @@ -150,58 +148,33 @@ def main():
vsys=True,
template=True,
template_stack=True,
with_state=True,
with_network_resource_module_state=True,
with_classic_provider_spec=True,
argument_spec=dict(
zone=dict(required=True),
sdk_cls=Zone,
sdk_params=dict(
zone=dict(required=True, sdk_param="name"),
mode=dict(
choices=["tap", "virtual-wire", "layer2", "layer3", "external"],
default="layer3",
),
interface=dict(type="list", elements="str"),
zone_profile=dict(),
log_setting=dict(),
enable_userid=dict(type="bool", default=False),
enable_userid=dict(
type="bool", default=False, sdk_param="enable_user_identification"
),
include_acl=dict(type="list", elements="str"),
exclude_acl=dict(type="list", elements="str"),
),
)

module = AnsibleModule(
argument_spec=helper.argument_spec,
supports_check_mode=True,
required_one_of=helper.required_one_of,
)

# Verify imports, build pandevice object tree.
parent = helper.get_pandevice_parent(module)

# Set the Zone object params
zone_spec = {
"name": module.params["zone"],
"mode": module.params["mode"],
"interface": module.params["interface"],
"zone_profile": module.params["zone_profile"],
"log_setting": module.params["log_setting"],
"enable_user_identification": module.params["enable_userid"],
"include_acl": module.params["include_acl"],
"exclude_acl": module.params["exclude_acl"],
}

# Retrieve the current list of zones
try:
zones = Zone.refreshall(parent, add=False)
except PanDeviceError as e:
module.fail_json(msg="Failed refresh: {0}".format(e))

# Build the zone and attach to the parent
new_zone = Zone(**zone_spec)
parent.add(new_zone)

# Perform the requeseted action.
changed, diff = helper.apply_state(new_zone, zones, module)

# Done!
module.exit_json(changed=changed, diff=diff, msg="Done!")
helper.process(module)


if __name__ == "__main__":
Expand Down

0 comments on commit 419f2f2

Please sign in to comment.