Skip to content

Commit

Permalink
feat(panos_service_group): 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 dbd9bfd commit 5fffeee
Showing 1 changed file with 6 additions and 38 deletions.
44 changes: 6 additions & 38 deletions plugins/modules/panos_service_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- paloaltonetworks.panos.fragments.transitional_provider
- paloaltonetworks.panos.fragments.vsys
- paloaltonetworks.panos.fragments.device_group
- paloaltonetworks.panos.fragments.state
- paloaltonetworks.panos.fragments.network_resource_module_state
- paloaltonetworks.panos.fragments.deprecated_commit
options:
name:
Expand Down Expand Up @@ -82,11 +82,9 @@
)

try:
from panos.errors import PanDeviceError
from panos.objects import ServiceGroup
except ImportError:
try:
from pandevice.errors import PanDeviceError
from pandevice.objects import ServiceGroup
except ImportError:
pass
Expand All @@ -97,12 +95,13 @@ def main():
vsys=True,
device_group=True,
with_classic_provider_spec=True,
with_state=True,
argument_spec=dict(
with_network_resource_module_state=True,
with_commit=True,
sdk_cls=ServiceGroup,
sdk_params=dict(
name=dict(type="str", required=True),
value=dict(type="list", elements="str"),
tag=dict(type="list", elements="str"),
commit=dict(type="bool", default=False),
),
)

Expand All @@ -112,38 +111,7 @@ def main():
supports_check_mode=True,
)

# Verify libs are present, get parent object.
parent = helper.get_pandevice_parent(module)

# Object params.
spec = {
"name": module.params["name"],
"value": module.params["value"],
"tag": module.params["tag"],
}

# Other info.
commit = module.params["commit"]

# Retrieve current info.
try:
listing = ServiceGroup.refreshall(parent, add=False)
except PanDeviceError as e:
module.fail_json(msg="Failed refresh: {0}".format(e))

# Build the object based on the user spec.
obj = ServiceGroup(**spec)
parent.add(obj)

# Apply the state.
changed, diff = helper.apply_state(obj, listing, module)

# Commit.
if commit and changed:
helper.commit(module)

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


if __name__ == "__main__":
Expand Down

0 comments on commit 5fffeee

Please sign in to comment.