Skip to content

Commit

Permalink
feat(panos_snmp_v2c_server): 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 e1e799a commit 53fdbee
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions plugins/modules/panos_snmp_v2c_server.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_shared
- paloaltonetworks.panos.fragments.device_group
- paloaltonetworks.panos.fragments.state
- paloaltonetworks.panos.fragments.network_resource_module_state
options:
snmp_profile:
description:
Expand Down Expand Up @@ -81,11 +81,9 @@

try:
from panos.device import SnmpServerProfile, SnmpV2cServer
from panos.errors import PanDeviceError
except ImportError:
try:
from pandevice.device import SnmpServerProfile, SnmpV2cServer
from pandevice.errors import PanDeviceError
except ImportError:
pass

Expand All @@ -94,45 +92,26 @@ def main():
helper = get_connection(
vsys_shared=True,
device_group=True,
with_state=True,
with_network_resource_module_state=True,
with_classic_provider_spec=True,
min_pandevice_version=(0, 11, 1),
min_panos_version=(7, 1, 0),
argument_spec=dict(
snmp_profile=dict(required=True),
parents=((SnmpServerProfile, "snmp_profile"),),
sdk_cls=SnmpV2cServer,
sdk_params=dict(
name=dict(required=True),
manager=dict(),
community=dict(),
),
)

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)

sp = SnmpServerProfile(module.params["snmp_profile"])
parent.add(sp)
try:
sp.refresh()
except PanDeviceError as e:
module.fail_json(msg="Failed refresh: {0}".format(e))

listing = sp.findall(SnmpV2cServer)

spec = {
"name": module.params["name"],
"manager": module.params["manager"],
"community": module.params["community"],
}
obj = SnmpV2cServer(**spec)
sp.add(obj)

changed, diff = helper.apply_state(obj, listing, module)
module.exit_json(changed=changed, diff=diff, msg="Done")
helper.process(module)


if __name__ == "__main__":
Expand Down

0 comments on commit 53fdbee

Please sign in to comment.