Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Ansible module to manage Check Point 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_network
33 short_description: Manages network objects on Check Point over Web Services API
34 description:
35 - Manages network objects on Check Point 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: "1.0.0"
39 author: "Or Soffer (@chkp-orso)"
40 options:
41 name:
42 description:
43 - Object name.
44 type: str
45 required: True
46 subnet:
47 description:
48 - IPv4 or IPv6 network address. If both addresses are required use subnet4 and subnet6 fields explicitly.
49 type: str
50 subnet4:
51 description:
52 - IPv4 network address.
53 type: str
54 subnet6:
55 description:
56 - IPv6 network address.
57 type: str
58 mask_length:
59 description:
60 - IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and mask-length6 fields explicitly. Instead of IPv4 mask length
61 it is possible to specify IPv4 mask itself in subnet-mask field.
62 type: int
63 mask_length4:
64 description:
65 - IPv4 network mask length.
66 type: int
67 mask_length6:
68 description:
69 - IPv6 network mask length.
70 type: int
71 subnet_mask:
72 description:
73 - IPv4 network mask.
74 type: str
75 nat_settings:
76 description:
77 - NAT settings.
78 type: dict
79 suboptions:
80 auto_rule:
81 description:
82 - Whether to add automatic address translation rules.
83 type: bool
84 ip_address:
85 description:
86 - IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly. This parameter is not
87 required in case "method" parameter is "hide" and "hide-behind" parameter is "gateway".
88 type: str
89 ipv4_address:
90 description:
91 - IPv4 address.
92 type: str
93 ipv6_address:
94 description:
95 - IPv6 address.
96 type: str
97 hide_behind:
98 description:
99 - Hide behind method. This parameter is not required in case "method" parameter is "static".
100 type: str
101 choices: ['gateway', 'ip-address']
102 install_on:
103 description:
104 - Which gateway should apply the NAT translation.
105 type: str
106 method:
107 description:
108 - NAT translation method.
109 type: str
110 choices: ['hide', 'static']
111 tags:
112 description:
113 - Collection of tag identifiers.
114 type: list
115 elements: str
116 broadcast:
117 description:
118 - Allow broadcast address inclusion.
119 type: str
120 choices: ['disallow', 'allow']
121 color:
122 description:
123 - Color of the object. Should be one of existing colors.
124 type: str
125 choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green',
126 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon',
127 'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow']
128 comments:
129 description:
130 - Comments string.
131 type: str
132 details_level:
133 description:
134 - 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
135 representation of the object.
136 type: str
137 choices: ['uid', 'standard', 'full']
138 groups:
139 description:
140 - Collection of group identifiers.
141 type: list
142 elements: str
143 ignore_warnings:
144 description:
145 - Apply changes ignoring warnings.
146 type: bool
147 ignore_errors:
148 description:
149 - 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.
150 type: bool
151 extends_documentation_fragment: check_point.mgmt.checkpoint_objects
152 """
153
154 EXAMPLES = """
155 - name: add-network
156 cp_mgmt_network:
157 name: New Network 1
158 state: present
159 subnet: 192.0.2.0
160 subnet_mask: 255.255.255.0
161
162 - name: set-network
163 cp_mgmt_network:
164 color: green
165 mask_length: 16
166 name: New Network 1
167 new_name: New Network 2
168 state: present
169 subnet: 192.0.0.0
170
171 - name: delete-network
172 cp_mgmt_network:
173 name: New Network 2
174 state: absent
175 """
176
177 RETURN = """
178 cp_mgmt_network:
179 description: The checkpoint object created or updated.
180 returned: always, except when deleting the object.
181 type: dict
182 """
183
184 from ansible.module_utils.basic import AnsibleModule
185 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
186 checkpoint_argument_spec_for_objects,
187 api_call,
188 )
189
190
191 def main():
192 argument_spec = dict(
193 name=dict(type="str", required=True),
194 subnet=dict(type="str"),
195 subnet4=dict(type="str"),
196 subnet6=dict(type="str"),
197 mask_length=dict(type="int"),
198 mask_length4=dict(type="int"),
199 mask_length6=dict(type="int"),
200 subnet_mask=dict(type="str"),
201 nat_settings=dict(
202 type="dict",
203 options=dict(
204 auto_rule=dict(type="bool"),
205 ip_address=dict(type="str"),
206 ipv4_address=dict(type="str"),
207 ipv6_address=dict(type="str"),
208 hide_behind=dict(
209 type="str", choices=["gateway", "ip-address"]
210 ),
211 install_on=dict(type="str"),
212 method=dict(type="str", choices=["hide", "static"]),
213 ),
214 ),
215 tags=dict(type="list", elements="str"),
216 broadcast=dict(type="str", choices=["disallow", "allow"]),
217 color=dict(
218 type="str",
219 choices=[
220 "aquamarine",
221 "black",
222 "blue",
223 "crete blue",
224 "burlywood",
225 "cyan",
226 "dark green",
227 "khaki",
228 "orchid",
229 "dark orange",
230 "dark sea green",
231 "pink",
232 "turquoise",
233 "dark blue",
234 "firebrick",
235 "brown",
236 "forest green",
237 "gold",
238 "dark gold",
239 "gray",
240 "dark gray",
241 "light green",
242 "lemon chiffon",
243 "coral",
244 "sea green",
245 "sky blue",
246 "magenta",
247 "purple",
248 "slate blue",
249 "violet red",
250 "navy blue",
251 "olive",
252 "orange",
253 "red",
254 "sienna",
255 "yellow",
256 ],
257 ),
258 comments=dict(type="str"),
259 details_level=dict(type="str", choices=["uid", "standard", "full"]),
260 groups=dict(type="list", elements="str"),
261 ignore_warnings=dict(type="bool"),
262 ignore_errors=dict(type="bool"),
263 )
264 argument_spec.update(checkpoint_argument_spec_for_objects)
265
266 module = AnsibleModule(
267 argument_spec=argument_spec, supports_check_mode=True
268 )
269 api_call_object = "network"
270
271 result = api_call(module, api_call_object)
272 module.exit_json(**result)
273
274
275 if __name__ == "__main__":
276 main()