Skip to content

Commit

Permalink
feat(panos_ipsec_ipv4_proxyid): 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 0c6e2ac commit 120d26c
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions plugins/modules/panos_ipsec_ipv4_proxyid.py
Expand Up @@ -35,7 +35,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.deprecated_commit
options:
Expand Down Expand Up @@ -106,11 +106,9 @@
)

try:
from panos.errors import PanDeviceError
from panos.network import IpsecTunnel, IpsecTunnelIpv4ProxyId
except ImportError:
try:
from pandevice.errors import PanDeviceError
from pandevice.network import IpsecTunnel, IpsecTunnelIpv4ProxyId
except ImportError:
pass
Expand All @@ -121,10 +119,12 @@ def main():
template=True,
template_stack=True,
with_classic_provider_spec=True,
with_state=True,
argument_spec=dict(
with_network_resource_module_state=True,
with_commit=True,
parents=((IpsecTunnel, "tunnel_name"),),
sdk_cls=IpsecTunnelIpv4ProxyId,
sdk_params=dict(
name=dict(type="str", required=True),
tunnel_name=dict(default="default"),
local=dict(default="192.168.2.0/24"),
remote=dict(default="192.168.1.0/24"),
any_protocol=dict(type="bool", default=True),
Expand All @@ -133,7 +133,6 @@ def main():
tcp_remote_port=dict(type="int"),
udp_local_port=dict(type="int"),
udp_remote_port=dict(type="int"),
commit=dict(type="bool", default=False),
),
)

Expand All @@ -143,48 +142,7 @@ def main():
required_one_of=helper.required_one_of,
)

# Object specifications
spec = {
"name": module.params["name"],
"local": module.params["local"],
"remote": module.params["remote"],
"any_protocol": module.params["any_protocol"],
"number_protocol": module.params["number_proto"],
"tcp_local_port": module.params["tcp_local_port"],
"tcp_remote_port": module.params["tcp_remote_port"],
"udp_local_port": module.params["udp_local_port"],
"udp_remote_port": module.params["udp_remote_port"],
}

# Additional infos
commit = module.params["commit"]

# Verify libs are present, get parent object.
parent = helper.get_pandevice_parent(module)
tunnel_name = module.params["tunnel_name"]

# get the tunnel object
tunnel = IpsecTunnel(tunnel_name)
parent.add(tunnel)
try:
tunnel.refresh()
except PanDeviceError as e:
module.fail_json(msg="Failed refresh: {0}".format(e))

# get the listing
listing = tunnel.findall(IpsecTunnelIpv4ProxyId)
obj = IpsecTunnelIpv4ProxyId(**spec)
tunnel.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 120d26c

Please sign in to comment.