Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_pkg_header_shapingpolicy.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_pkg_header_shapingpolicy
15 short_description: Configure shaping policies.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 pkg:
25 description: The parameter (pkg) in requested url.
26 type: str
27 required: true
28 pkg_header_shapingpolicy:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 app_category:
34 aliases: ['app-category']
35 type: raw
36 description: (list or str) App category.
37 app_group:
38 aliases: ['app-group']
39 type: raw
40 description: (list or str) App group.
41 application:
42 type: raw
43 description: (list) Application.
44 class_id:
45 aliases: ['class-id']
46 type: raw
47 description: (int or str) Class id.
48 comment:
49 type: str
50 description: Comment.
51 diffserv_forward:
52 aliases: ['diffserv-forward']
53 type: str
54 description: Diffserv forward.
55 choices: ['disable', 'enable']
56 diffserv_reverse:
57 aliases: ['diffserv-reverse']
58 type: str
59 description: Diffserv reverse.
60 choices: ['disable', 'enable']
61 diffservcode_forward:
62 aliases: ['diffservcode-forward']
63 type: str
64 description: Diffservcode forward.
65 diffservcode_rev:
66 aliases: ['diffservcode-rev']
67 type: str
68 description: Diffservcode rev.
69 dstaddr:
70 type: raw
71 description: (list or str) Dstaddr.
72 dstaddr6:
73 type: raw
74 description: (list or str) Dstaddr6.
75 dstintf:
76 type: raw
77 description: (list or str) Dstintf.
78 groups:
79 type: raw
80 description: (list or str) Groups.
81 id:
82 type: int
83 description: Id.
84 required: true
85 internet_service:
86 aliases: ['internet-service']
87 type: str
88 description: Internet service.
89 choices: ['disable', 'enable']
90 internet_service_custom:
91 aliases: ['internet-service-custom']
92 type: raw
93 description: (list or str) Internet service custom.
94 internet_service_custom_group:
95 aliases: ['internet-service-custom-group']
96 type: raw
97 description: (list or str) Internet service custom group.
98 internet_service_group:
99 aliases: ['internet-service-group']
100 type: raw
101 description: (list or str) Internet service group.
102 internet_service_id:
103 aliases: ['internet-service-id']
104 type: raw
105 description: (list or str) Internet service id.
106 internet_service_src:
107 aliases: ['internet-service-src']
108 type: str
109 description: Internet service src.
110 choices: ['disable', 'enable']
111 internet_service_src_custom:
112 aliases: ['internet-service-src-custom']
113 type: raw
114 description: (list or str) Internet service src custom.
115 internet_service_src_custom_group:
116 aliases: ['internet-service-src-custom-group']
117 type: raw
118 description: (list or str) Internet service src custom group.
119 internet_service_src_group:
120 aliases: ['internet-service-src-group']
121 type: raw
122 description: (list or str) Internet service src group.
123 internet_service_src_id:
124 aliases: ['internet-service-src-id']
125 type: raw
126 description: (list or str) Internet service src id.
127 ip_version:
128 aliases: ['ip-version']
129 type: str
130 description: Ip version.
131 choices: ['4', '6']
132 per_ip_shaper:
133 aliases: ['per-ip-shaper']
134 type: str
135 description: Per ip shaper.
136 schedule:
137 type: str
138 description: Schedule.
139 service:
140 type: raw
141 description: (list or str) Service.
142 srcaddr:
143 type: raw
144 description: (list or str) Srcaddr.
145 srcaddr6:
146 type: raw
147 description: (list or str) Srcaddr6.
148 srcintf:
149 type: raw
150 description: (list or str) Srcintf.
151 status:
152 type: str
153 description: Status.
154 choices: ['disable', 'enable']
155 tos:
156 type: str
157 description: Tos.
158 tos_mask:
159 aliases: ['tos-mask']
160 type: str
161 description: Tos mask.
162 tos_negate:
163 aliases: ['tos-negate']
164 type: str
165 description: Tos negate.
166 choices: ['disable', 'enable']
167 traffic_shaper:
168 aliases: ['traffic-shaper']
169 type: str
170 description: Traffic shaper.
171 traffic_shaper_reverse:
172 aliases: ['traffic-shaper-reverse']
173 type: str
174 description: Traffic shaper reverse.
175 url_category:
176 aliases: ['url-category']
177 type: raw
178 description: (list or str) Url category.
179 users:
180 type: raw
181 description: (list or str) Users.
182 uuid:
183 type: str
184 description: Uuid.
185 internet_service_name:
186 aliases: ['internet-service-name']
187 type: raw
188 description: (list or str) Internet service name.
189 internet_service_src_name:
190 aliases: ['internet-service-src-name']
191 type: raw
192 description: (list or str) Internet service src name.
193 class_id_reverse:
194 aliases: ['class-id-reverse']
195 type: int
196 description: Class id reverse.
197 service_type:
198 aliases: ['service-type']
199 type: str
200 description: Service type.
201 choices: ['service', 'internet-service']
202 uuid_idx:
203 aliases: ['uuid-idx']
204 type: int
205 description: Uuid idx.
206 cos:
207 type: str
208 description: VLAN CoS bit pattern.
209 cos_mask:
210 aliases: ['cos-mask']
211 type: str
212 description: VLAN CoS evaluated bits.
213 traffic_type:
214 aliases: ['traffic-type']
215 type: str
216 description: Traffic type.
217 choices: ['forwarding', 'local-in', 'local-out']
218 http_response_match:
219 aliases: ['http-response-match']
220 type: str
221 description: Http response match.
222 choices: ['disable', 'enable']
223 internet_service_fortiguard:
224 aliases: ['internet-service-fortiguard']
225 type: raw
226 description: (list) FortiGuard Internet Service name.
227 internet_service_src_fortiguard:
228 aliases: ['internet-service-src-fortiguard']
229 type: raw
230 description: (list) FortiGuard Internet Service source name.
231 '''
232
233 EXAMPLES = '''
234 - name: Example playbook (generated based on argument schema)
235 hosts: fortimanagers
236 connection: httpapi
237 gather_facts: false
238 tasks:
239 - name: Configure shaping policies.
240 fortinet.fortimanager.fmgr_pkg_header_shapingpolicy:
241 # workspace_locking_adom: <global or your adom name>
242 pkg: <your own value>
243 state: present # <value in [present, absent]>
244 pkg_header_shapingpolicy:
245 id: 0 # Required variable, integer
246 # app_category: <list or string>
247 # app_group: <list or string>
248 # application: <list or integer>
249 # class_id: <integer or string>
250 # comment: <string>
251 # diffserv_forward: <value in [disable, enable]>
252 # diffserv_reverse: <value in [disable, enable]>
253 # diffservcode_forward: <string>
254 # diffservcode_rev: <string>
255 # dstaddr: <list or string>
256 # dstaddr6: <list or string>
257 # dstintf: <list or string>
258 # groups: <list or string>
259 # internet_service: <value in [disable, enable]>
260 # internet_service_custom: <list or string>
261 # internet_service_custom_group: <list or string>
262 # internet_service_group: <list or string>
263 # internet_service_id: <list or string>
264 # internet_service_src: <value in [disable, enable]>
265 # internet_service_src_custom: <list or string>
266 # internet_service_src_custom_group: <list or string>
267 # internet_service_src_group: <list or string>
268 # internet_service_src_id: <list or string>
269 # ip_version: <value in [4, 6]>
270 # per_ip_shaper: <string>
271 # schedule: <string>
272 # service: <list or string>
273 # srcaddr: <list or string>
274 # srcaddr6: <list or string>
275 # srcintf: <list or string>
276 # status: <value in [disable, enable]>
277 # tos: <string>
278 # tos_mask: <string>
279 # tos_negate: <value in [disable, enable]>
280 # traffic_shaper: <string>
281 # traffic_shaper_reverse: <string>
282 # url_category: <list or string>
283 # users: <list or string>
284 # uuid: <string>
285 # internet_service_name: <list or string>
286 # internet_service_src_name: <list or string>
287 # class_id_reverse: <integer>
288 # service_type: <value in [service, internet-service]>
289 # uuid_idx: <integer>
290 # cos: <string>
291 # cos_mask: <string>
292 # traffic_type: <value in [forwarding, local-in, local-out]>
293 # http_response_match: <value in [disable, enable]>
294 # internet_service_fortiguard: <list or string>
295 # internet_service_src_fortiguard: <list or string>
296 '''
297
298 RETURN = '''
299 meta:
300 description: The result of the request.
301 type: dict
302 returned: always
303 contains:
304 request_url:
305 description: The full url requested.
306 returned: always
307 type: str
308 sample: /sys/login/user
309 response_code:
310 description: The status of api request.
311 returned: always
312 type: int
313 sample: 0
314 response_data:
315 description: The api response.
316 type: list
317 returned: always
318 response_message:
319 description: The descriptive message of the api response.
320 type: str
321 returned: always
322 sample: OK.
323 system_information:
324 description: The information of the target system.
325 type: dict
326 returned: always
327 rc:
328 description: The status the request.
329 type: int
330 returned: always
331 sample: 0
332 version_check_warning:
333 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
334 type: list
335 returned: complex
336 '''
337 from ansible.module_utils.basic import AnsibleModule
338 from ansible.module_utils.connection import Connection
339 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
340 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
341
342
343 def main():
344 urls_list = [
345 '/pm/config/global/pkg/{pkg}/global/header/shaping-policy'
346 ]
347 module_arg_spec = {
348 'pkg': {'required': True, 'type': 'str'},
349 'revision_note': {'type': 'str'},
350 'pkg_header_shapingpolicy': {
351 'type': 'dict', 'v_range': [['6.0.0', '']],
352 'options': {
353 'app-category': {'type': 'raw'},
354 'app-group': {'type': 'raw'},
355 'application': {'type': 'raw'},
356 'class-id': {'type': 'raw'},
357 'comment': {'type': 'str'},
358 'diffserv-forward': {'choices': ['disable', 'enable'], 'type': 'str'},
359 'diffserv-reverse': {'choices': ['disable', 'enable'], 'type': 'str'},
360 'diffservcode-forward': {'type': 'str'},
361 'diffservcode-rev': {'type': 'str'},
362 'dstaddr': {'type': 'raw'},
363 'dstaddr6': {'type': 'raw'},
364 'dstintf': {'type': 'raw'},
365 'groups': {'type': 'raw'},
366 'id': {'required': True, 'type': 'int'},
367 'internet-service': {'choices': ['disable', 'enable'], 'type': 'str'},
368 'internet-service-custom': {'type': 'raw'},
369 'internet-service-custom-group': {'type': 'raw'},
370 'internet-service-group': {'type': 'raw'},
371 'internet-service-id': {'type': 'raw'},
372 'internet-service-src': {'choices': ['disable', 'enable'], 'type': 'str'},
373 'internet-service-src-custom': {'type': 'raw'},
374 'internet-service-src-custom-group': {'type': 'raw'},
375 'internet-service-src-group': {'type': 'raw'},
376 'internet-service-src-id': {'type': 'raw'},
377 'ip-version': {'choices': ['4', '6'], 'type': 'str'},
378 'per-ip-shaper': {'type': 'str'},
379 'schedule': {'type': 'str'},
380 'service': {'type': 'raw'},
381 'srcaddr': {'type': 'raw'},
382 'srcaddr6': {'type': 'raw'},
383 'srcintf': {'type': 'raw'},
384 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
385 'tos': {'type': 'str'},
386 'tos-mask': {'type': 'str'},
387 'tos-negate': {'choices': ['disable', 'enable'], 'type': 'str'},
388 'traffic-shaper': {'type': 'str'},
389 'traffic-shaper-reverse': {'type': 'str'},
390 'url-category': {'type': 'raw'},
391 'users': {'type': 'raw'},
392 'uuid': {'v_range': [['6.2.1', '']], 'type': 'str'},
393 'internet-service-name': {'v_range': [['6.4.0', '']], 'type': 'raw'},
394 'internet-service-src-name': {'v_range': [['6.4.0', '']], 'type': 'raw'},
395 'class-id-reverse': {'v_range': [['7.0.3', '']], 'type': 'int'},
396 'service-type': {'v_range': [['7.0.3', '']], 'choices': ['service', 'internet-service'], 'type': 'str'},
397 'uuid-idx': {'v_range': [['7.2.1', '']], 'type': 'int'},
398 'cos': {'v_range': [['7.4.0', '']], 'type': 'str'},
399 'cos-mask': {'v_range': [['7.4.0', '']], 'type': 'str'},
400 'traffic-type': {'v_range': [['7.4.0', '']], 'choices': ['forwarding', 'local-in', 'local-out'], 'type': 'str'},
401 'http-response-match': {'v_range': [['7.4.7', '7.4.10'], ['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
402 'internet-service-fortiguard': {'v_range': [['7.6.4', '']], 'type': 'raw'},
403 'internet-service-src-fortiguard': {'v_range': [['7.6.4', '']], 'type': 'raw'}
404 }
405 }
406 }
407
408 module_option_spec = get_module_arg_spec('full crud')
409 module_arg_spec.update(module_option_spec)
410 check_galaxy_version(module_arg_spec)
411 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'pkg_header_shapingpolicy'),
412 supports_check_mode=True)
413 if not module._socket_path:
414 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
415 connection = Connection(module._socket_path)
416 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
417 'id', 'data', module, connection)
418 params_validation_blob = [
419 {
420 'attribute_path': ['pkg_header_shapingpolicy', 'id'],
421 'lambda': 'int($) >= 1073741824',
422 'fail_action': 'warn',
423 'hint_message': 'id should be larger than 2^30, i.e. 1073741824, otherwise it will be ignored.'
424 }
425 ]
426
427 fmgr.validate_parameters(params_validation_blob)
428 fmgr.process_crud()
429 module.exit_json(meta=module.params)
430
431
432 if __name__ == '__main__':
433 main()