Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_nat_section.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Ansible module to manage CheckPoint Firewall (c) 2019
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 from __future__ import absolute_import, division, print_function
21
22 __metaclass__ = type
23
24 ANSIBLE_METADATA = {
25 "metadata_version": "1.1",
26 "status": ["preview"],
27 "supported_by": "community",
28 }
29
30 DOCUMENTATION = """
31 ---
32 module: cp_mgmt_nat_section
33 short_description: Manages nat-section objects on Checkpoint over Web Services API
34 description:
35 - Manages nat-section objects on Checkpoint devices including creating, updating and removing objects.
36 - All operations are performed over Web Services API.
37 - Available from R80 management version.
38 version_added: "2.0.0"
39 author: "Or Soffer (@chkp-orso)"
40 options:
41 package:
42 description:
43 - Name of the package.
44 type: str
45 position:
46 description:
47 - Position in the rulebase.
48 type: str
49 relative_position:
50 description:
51 - Position in the rulebase.
52 - Use of this field is relevant only for "add" operation.
53 type: dict
54 version_added: "6.0.0"
55 suboptions:
56 below:
57 description:
58 - Add section below specific rule/section identified by name.
59 type: str
60 above:
61 description:
62 - Add section above specific rule/section identified by name.
63 type: str
64 top:
65 description:
66 - Add section to the top of a specific section identified by name.
67 type: str
68 bottom:
69 description:
70 - Add section to the bottom of a specific section identified by name.
71 type: str
72 name:
73 description:
74 - Object name.
75 type: str
76 required: True
77 details_level:
78 description:
79 - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
80 representation of the object.
81 type: str
82 choices: ['uid', 'standard', 'full']
83 ignore_warnings:
84 description:
85 - Apply changes ignoring warnings.
86 type: bool
87 ignore_errors:
88 description:
89 - Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored.
90 type: bool
91 extends_documentation_fragment: check_point.mgmt.checkpoint_objects
92 """
93
94 EXAMPLES = """
95 - name: add-nat-section
96 cp_mgmt_nat_section:
97 name: New Section 1
98 package: standard
99 position: 1
100 state: present
101
102 - name: set-nat-section
103 cp_mgmt_nat_section:
104 name: New Section 1
105 package: standard
106 state: present
107
108 - name: delete-nat-section
109 cp_mgmt_nat_section:
110 name: New Section 1
111 package: standard
112 state: absent
113 """
114
115 RETURN = """
116 cp_mgmt_nat_section:
117 description: The checkpoint object created or updated.
118 returned: always, except when deleting the object.
119 type: dict
120 """
121
122 from ansible.module_utils.basic import AnsibleModule
123 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
124 checkpoint_argument_spec_for_objects,
125 api_call,
126 )
127
128
129 def main():
130 argument_spec = dict(
131 package=dict(type="str"),
132 position=dict(type="str"),
133 relative_position=dict(
134 type="dict",
135 options=dict(
136 below=dict(type="str"),
137 above=dict(type="str"),
138 top=dict(type="str"),
139 bottom=dict(type="str"),
140 ),
141 ),
142 name=dict(type="str", required=True),
143 details_level=dict(type="str", choices=["uid", "standard", "full"]),
144 ignore_warnings=dict(type="bool"),
145 ignore_errors=dict(type="bool"),
146 )
147 argument_spec.update(checkpoint_argument_spec_for_objects)
148
149 module = AnsibleModule(
150 argument_spec=argument_spec, supports_check_mode=True
151 )
152 api_call_object = "nat-section"
153
154 if module.params["relative_position"] is not None:
155 if module.params["position"] is not None:
156 raise AssertionError(
157 "The use of both 'relative_position' and 'position' arguments isn't allowed"
158 )
159 module.params["position"] = module.params["relative_position"]
160 module.params.pop("relative_position")
161
162 result = api_call(module, api_call_object)
163 module.exit_json(**result)
164
165
166 if __name__ == "__main__":
167 main()