Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_dvmdb_device.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_dvmdb_device
15 short_description: Device table, most attributes are read-only and can only be changed internally.
16 version_added: "1.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.partial_crud
20 options:
21 adom:
22 description: The parameter (adom) in requested url.
23 type: str
24 required: true
25 device:
26 description: The parameter (device) in requested url.
27 type: str
28 required: true
29 dvmdb_device:
30 description: The top level parameters set.
31 required: false
32 type: dict
33 suboptions:
34 adm_pass:
35 type: raw
36 description: (list) Adm pass.
37 adm_usr:
38 type: str
39 description: Adm usr.
40 app_ver:
41 type: str
42 description: App ver.
43 av_ver:
44 type: str
45 description: Av ver.
46 beta:
47 type: int
48 description: Beta.
49 branch_pt:
50 type: int
51 description: Branch pt.
52 build:
53 type: int
54 description: Build.
55 checksum:
56 type: str
57 description: Checksum.
58 conf_status:
59 type: str
60 description: Conf status.
61 choices: ['unknown', 'insync', 'outofsync']
62 conn_mode:
63 type: str
64 description: Conn mode.
65 choices: ['active', 'passive']
66 conn_status:
67 type: str
68 description: Conn status.
69 choices: ['UNKNOWN', 'up', 'down']
70 db_status:
71 type: str
72 description: Db status.
73 choices: ['unknown', 'nomod', 'mod']
74 desc:
75 type: str
76 description: Desc.
77 dev_status:
78 type: str
79 description: Dev status.
80 choices: ['none', 'unknown', 'checkedin', 'inprogress', 'installed', 'aborted',
81 'sched', 'retry', 'canceled', 'pending', 'retrieved', 'changed_conf',
82 'sync_fail', 'timeout', 'rev_revert', 'auto_updated']
83 fap_cnt:
84 type: int
85 description: Fap cnt.
86 faz_full_act:
87 aliases: ['faz.full_act']
88 type: int
89 description: Faz.
90 faz_perm:
91 aliases: ['faz.perm']
92 type: int
93 description: Faz.
94 faz_quota:
95 aliases: ['faz.quota']
96 type: int
97 description: Faz.
98 faz_used:
99 aliases: ['faz.used']
100 type: int
101 description: Faz.
102 fex_cnt:
103 type: int
104 description: Fex cnt.
105 flags:
106 type: list
107 elements: str
108 description: Flags.
109 choices: ['has_hdd', 'vdom_enabled', 'discover', 'reload', 'interim_build',
110 'offline_mode', 'is_model', 'fips_mode', 'linked_to_model',
111 'ip-conflict', 'faz-autosync', 'need_reset', 'backup_mode',
112 'azure_vwan_nva', 'fgsp_configured', 'cnf_mode', 'sase_managed',
113 'override_management_intf', 'sdwan_management', 'deny_api_access']
114 foslic_cpu:
115 type: int
116 description: VM Meter vCPU count.
117 foslic_dr_site:
118 type: str
119 description: VM Meter DR Site status.
120 choices: ['disable', 'enable']
121 foslic_inst_time:
122 type: int
123 description: VM Meter first deployment time
124 foslic_last_sync:
125 type: int
126 description: VM Meter last synchronized time
127 foslic_ram:
128 type: int
129 description: VM Meter device RAM size
130 foslic_type:
131 type: str
132 description: VM Meter license type.
133 choices: ['temporary', 'trial', 'regular', 'trial_expired']
134 foslic_utm:
135 type: list
136 elements: str
137 description:
138 - VM Meter services
139 - fw - Firewall
140 - av - Anti-virus
141 - ips - IPS
142 - app - App control
143 - url - Web filter
144 - utm - Full UTM
145 - fwb - FortiWeb
146 choices: ['fw', 'av', 'ips', 'app', 'url', 'utm', 'fwb']
147 fsw_cnt:
148 type: int
149 description: Fsw cnt.
150 ha_group_id:
151 type: int
152 description: Ha group id.
153 ha_group_name:
154 type: str
155 description: Ha group name.
156 ha_mode:
157 type: str
158 description: Enabled - Value reserved for non-FOS HA devices.
159 choices: ['standalone', 'AP', 'AA', 'ELBC', 'DUAL', 'enabled', 'unknown',
160 'fmg-enabled', 'autoscale']
161 ha_slave:
162 type: list
163 elements: dict
164 description: Ha slave.
165 suboptions:
166 idx:
167 type: int
168 description: Idx.
169 name:
170 type: str
171 description: Name.
172 prio:
173 type: int
174 description: Prio.
175 role:
176 type: str
177 description: Role.
178 choices: ['slave', 'master']
179 sn:
180 type: str
181 description: Sn.
182 status:
183 type: int
184 description: Status.
185 conf_status:
186 type: int
187 description: Conf status.
188 hdisk_size:
189 type: int
190 description: Hdisk size.
191 hostname:
192 type: str
193 description: Hostname.
194 hw_rev_major:
195 type: int
196 description: Hw rev major.
197 hw_rev_minor:
198 type: int
199 description: Hw rev minor.
200 ip:
201 type: str
202 description: Ip.
203 ips_ext:
204 type: int
205 description: Ips ext.
206 ips_ver:
207 type: str
208 description: Ips ver.
209 last_checked:
210 type: int
211 description: Last checked.
212 last_resync:
213 type: int
214 description: Last resync.
215 latitude:
216 type: str
217 description: Latitude.
218 lic_flags:
219 type: int
220 description: Lic flags.
221 lic_region:
222 type: str
223 description: Lic region.
224 location_from:
225 type: str
226 description: Location from.
227 logdisk_size:
228 type: int
229 description: Logdisk size.
230 longitude:
231 type: str
232 description: Longitude.
233 maxvdom:
234 type: int
235 description: Maxvdom.
236 meta_fields:
237 aliases: ['meta fields']
238 type: dict
239 description: Default metafields
240 mgmt_id:
241 type: int
242 description: Mgmt id.
243 mgmt_if:
244 type: str
245 description: Mgmt if.
246 mgmt_mode:
247 type: str
248 description: Mgmt mode.
249 choices: ['unreg', 'fmg', 'faz', 'fmgfaz']
250 mgt_vdom:
251 type: str
252 description: Mgt vdom.
253 mr:
254 type: int
255 description: Mr.
256 name:
257 type: str
258 description: Unique name for the device.
259 os_type:
260 type: str
261 description: Os type.
262 choices: ['unknown', 'fos', 'fsw', 'foc', 'fml', 'faz', 'fwb', 'fch', 'fct',
263 'log', 'fmg', 'fsa', 'fdd', 'fac', 'fpx', 'fna', 'fdc', 'ffw', 'fsr',
264 'fad', 'fap', 'fxt', 'fts', 'fai', 'fwc', 'fis', 'fed', 'fpa', 'fca',
265 'ftc', 'fss', 'fra', 'sim']
266 os_ver:
267 type: str
268 description: Os ver.
269 choices: ['unknown', '0.0', '1.0', '2.0', '3.0', '4.0', '5.0', '6.0', '7.0',
270 '8.0', '9.0']
271 patch:
272 type: int
273 description: Patch.
274 platform_str:
275 type: str
276 description: Platform str.
277 psk:
278 type: str
279 description: Psk.
280 sn:
281 type: str
282 description: Unique value for each device.
283 vdom:
284 type: list
285 elements: dict
286 description: Vdom.
287 suboptions:
288 comments:
289 type: str
290 description: Comments.
291 name:
292 type: str
293 description: Name.
294 opmode:
295 type: str
296 description: Opmode.
297 choices: ['nat', 'transparent']
298 rtm_prof_id:
299 type: int
300 description: Rtm prof id.
301 status:
302 type: str
303 description: Status.
304 vpn_id:
305 type: int
306 description: Vpn id.
307 meta_fields:
308 aliases: ['meta fields']
309 type: dict
310 description: Meta fields.
311 vdom_type:
312 type: str
313 description: Vdom type.
314 choices: ['traffic', 'admin']
315 version:
316 type: int
317 description: Version.
318 vm_cpu:
319 type: int
320 description: Vm cpu.
321 vm_cpu_limit:
322 type: int
323 description: Vm cpu limit.
324 vm_lic_expire:
325 type: int
326 description: Vm lic expire.
327 vm_mem:
328 type: int
329 description: Vm mem.
330 vm_mem_limit:
331 type: int
332 description: Vm mem limit.
333 vm_status:
334 type: raw
335 description: (int or str) Vm status.
336 module_sn:
337 type: str
338 description: Module sn.
339 prefer_img_ver:
340 type: str
341 description: Prefer img ver.
342 prio:
343 type: int
344 description: Prio.
345 role:
346 type: str
347 description: Role.
348 choices: ['master', 'ha-slave', 'autoscale-slave']
349 hyperscale:
350 type: int
351 description: Hyperscale.
352 nsxt_service_name:
353 type: str
354 description: Nsxt service name.
355 private_key:
356 type: str
357 description: Private key.
358 private_key_status:
359 type: int
360 description: Private key status.
361 vm_lic_overdue_since:
362 type: int
363 description: Vm lic overdue since.
364 first_tunnel_up:
365 type: int
366 description: First tunnel up.
367 eip:
368 type: str
369 description: Eip.
370 mgmt_uuid:
371 type: str
372 description: Mgmt uuid.
373 hw_generation:
374 type: int
375 description: Hw generation.
376 relver_info:
377 type: str
378 description: Relver info.
379 cluster_worker:
380 type: str
381 description: Cluster worker.
382 ha_vsn:
383 aliases: ['ha.vsn']
384 type: str
385 description: Ha.
386 ha_upgrade_mode:
387 type: int
388 description: Ha upgrade mode.
389 vm_payg_status:
390 type: int
391 description: Vm payg status.
392 sov_sase_license:
393 type: str
394 description: Sov sase license.
395 tunnel_sn:
396 type: str
397 description: Tunnel sn.
398 '''
399
400 EXAMPLES = '''
401 - name: Delete first FOS devices from FMG In a specific adom
402 hosts: fortimanagers
403 gather_facts: false
404 connection: httpapi
405 vars:
406 ansible_httpapi_use_ssl: true
407 ansible_httpapi_validate_certs: false
408 ansible_httpapi_port: 443
409 device_adom: "root"
410 tasks:
411 - name: Fetch all devices
412 fortinet.fortimanager.fmgr_fact:
413 facts:
414 selector: "dvmdb_device"
415 params:
416 adom: "{{ device_adom }}"
417 device: "your_value"
418 register: alldevices
419 - name: No name
420 when: alldevices.meta.response_data != []
421 ansible.builtin.debug:
422 msg:
423 - "We are going to delete device: {{ alldevices.meta.response_data[0].name }}"
424 - "IP of the device is: {{ alldevices.meta.response_data[0].ip }}"
425 - name: Create The Task To Delete The Device
426 when: alldevices.meta.response_data != [] and False
427 fortinet.fortimanager.fmgr_dvm_cmd_del_device:
428 dvm_cmd_del_device:
429 device: "{{ alldevices.meta.response_data[0].name }}"
430 adom: "{{ device_adom }}"
431 flags:
432 - "create_task"
433 - "nonblocking"
434 register: uninstalling_task
435 - name: Poll the task of deleting device
436 when: alldevices.meta.response_data != [] and False
437 fortinet.fortimanager.fmgr_fact:
438 facts:
439 selector: "task_task"
440 params:
441 task: "{{ uninstalling_task.meta.response_data.taskid }}"
442 register: taskinfo
443 until: taskinfo.meta.response_data.percent == 100
444 retries: 30
445 delay: 5
446 failed_when: taskinfo.meta.response_data.state == 'error'
447 '''
448
449 RETURN = '''
450 meta:
451 description: The result of the request.
452 type: dict
453 returned: always
454 contains:
455 request_url:
456 description: The full url requested.
457 returned: always
458 type: str
459 sample: /sys/login/user
460 response_code:
461 description: The status of api request.
462 returned: always
463 type: int
464 sample: 0
465 response_data:
466 description: The api response.
467 type: list
468 returned: always
469 response_message:
470 description: The descriptive message of the api response.
471 type: str
472 returned: always
473 sample: OK.
474 system_information:
475 description: The information of the target system.
476 type: dict
477 returned: always
478 rc:
479 description: The status the request.
480 type: int
481 returned: always
482 sample: 0
483 version_check_warning:
484 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
485 type: list
486 returned: complex
487 '''
488 from ansible.module_utils.basic import AnsibleModule
489 from ansible.module_utils.connection import Connection
490 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
491 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
492
493
494 def main():
495 urls_list = [
496 '/dvmdb/adom/{adom}/device/{device}',
497 '/dvmdb/device/{device}'
498 ]
499 module_arg_spec = {
500 'adom': {'required': True, 'type': 'str'},
501 'device': {'required': True, 'type': 'str'},
502 'dvmdb_device': {
503 'type': 'dict', 'v_range': [['6.0.0', '']],
504 'options': {
505 'adm_pass': {'no_log': True, 'type': 'raw'},
506 'adm_usr': {'type': 'str'},
507 'app_ver': {'type': 'str'},
508 'av_ver': {'type': 'str'},
509 'beta': {'type': 'int'},
510 'branch_pt': {'type': 'int'},
511 'build': {'type': 'int'},
512 'checksum': {'type': 'str'},
513 'conf_status': {'choices': ['unknown', 'insync', 'outofsync'], 'type': 'str'},
514 'conn_mode': {'choices': ['active', 'passive'], 'type': 'str'},
515 'conn_status': {'choices': ['UNKNOWN', 'up', 'down'], 'type': 'str'},
516 'db_status': {'choices': ['unknown', 'nomod', 'mod'], 'type': 'str'},
517 'desc': {'type': 'str'},
518 'dev_status': {
519 'choices': [
520 'none', 'unknown', 'checkedin', 'inprogress', 'installed', 'aborted', 'sched', 'retry', 'canceled', 'pending', 'retrieved',
521 'changed_conf', 'sync_fail', 'timeout', 'rev_revert', 'auto_updated'
522 ],
523 'type': 'str'
524 },
525 'fap_cnt': {'type': 'int'},
526 'faz.full_act': {'type': 'int'},
527 'faz.perm': {'type': 'int'},
528 'faz.quota': {'type': 'int'},
529 'faz.used': {'type': 'int'},
530 'fex_cnt': {'type': 'int'},
531 'flags': {
532 'type': 'list',
533 'choices': [
534 'has_hdd', 'vdom_enabled', 'discover', 'reload', 'interim_build', 'offline_mode', 'is_model', 'fips_mode', 'linked_to_model',
535 'ip-conflict', 'faz-autosync', 'need_reset', 'backup_mode', 'azure_vwan_nva', 'fgsp_configured', 'cnf_mode', 'sase_managed',
536 'override_management_intf', 'sdwan_management', 'deny_api_access'
537 ],
538 'elements': 'str'
539 },
540 'foslic_cpu': {'type': 'int'},
541 'foslic_dr_site': {'choices': ['disable', 'enable'], 'type': 'str'},
542 'foslic_inst_time': {'type': 'int'},
543 'foslic_last_sync': {'type': 'int'},
544 'foslic_ram': {'type': 'int'},
545 'foslic_type': {'choices': ['temporary', 'trial', 'regular', 'trial_expired'], 'type': 'str'},
546 'foslic_utm': {'type': 'list', 'choices': ['fw', 'av', 'ips', 'app', 'url', 'utm', 'fwb'], 'elements': 'str'},
547 'fsw_cnt': {'type': 'int'},
548 'ha_group_id': {'type': 'int'},
549 'ha_group_name': {'type': 'str'},
550 'ha_mode': {'choices': ['standalone', 'AP', 'AA', 'ELBC', 'DUAL', 'enabled', 'unknown', 'fmg-enabled', 'autoscale'], 'type': 'str'},
551 'ha_slave': {
552 'type': 'list',
553 'options': {
554 'idx': {'type': 'int'},
555 'name': {'type': 'str'},
556 'prio': {'type': 'int'},
557 'role': {'choices': ['slave', 'master'], 'type': 'str'},
558 'sn': {'type': 'str'},
559 'status': {'type': 'int'},
560 'conf_status': {'v_range': [['7.0.10', '7.0.16'], ['7.2.1', '']], 'type': 'int'}
561 },
562 'elements': 'dict'
563 },
564 'hdisk_size': {'type': 'int'},
565 'hostname': {'type': 'str'},
566 'hw_rev_major': {'type': 'int'},
567 'hw_rev_minor': {'type': 'int'},
568 'ip': {'type': 'str'},
569 'ips_ext': {'type': 'int'},
570 'ips_ver': {'type': 'str'},
571 'last_checked': {'type': 'int'},
572 'last_resync': {'type': 'int'},
573 'latitude': {'type': 'str'},
574 'lic_flags': {'type': 'int'},
575 'lic_region': {'type': 'str'},
576 'location_from': {'type': 'str'},
577 'logdisk_size': {'type': 'int'},
578 'longitude': {'type': 'str'},
579 'maxvdom': {'type': 'int'},
580 'meta fields': {'type': 'dict'},
581 'mgmt_id': {'v_range': [['6.0.0', '7.2.0']], 'type': 'int'},
582 'mgmt_if': {'type': 'str'},
583 'mgmt_mode': {'choices': ['unreg', 'fmg', 'faz', 'fmgfaz'], 'type': 'str'},
584 'mgt_vdom': {'type': 'str'},
585 'mr': {'type': 'int'},
586 'name': {'type': 'str'},
587 'os_type': {
588 'choices': [
589 'unknown', 'fos', 'fsw', 'foc', 'fml', 'faz', 'fwb', 'fch', 'fct', 'log', 'fmg', 'fsa', 'fdd', 'fac', 'fpx', 'fna', 'fdc', 'ffw',
590 'fsr', 'fad', 'fap', 'fxt', 'fts', 'fai', 'fwc', 'fis', 'fed', 'fpa', 'fca', 'ftc', 'fss', 'fra', 'sim'
591 ],
592 'type': 'str'
593 },
594 'os_ver': {'choices': ['unknown', '0.0', '1.0', '2.0', '3.0', '4.0', '5.0', '6.0', '7.0', '8.0', '9.0'], 'type': 'str'},
595 'patch': {'type': 'int'},
596 'platform_str': {'type': 'str'},
597 'psk': {'type': 'str'},
598 'sn': {'type': 'str'},
599 'vdom': {
600 'type': 'list',
601 'options': {
602 'comments': {'type': 'str'},
603 'name': {'type': 'str'},
604 'opmode': {'choices': ['nat', 'transparent'], 'type': 'str'},
605 'rtm_prof_id': {'type': 'int'},
606 'status': {'type': 'str'},
607 'vpn_id': {'v_range': [['6.2.2', '']], 'type': 'int'},
608 'meta fields': {'v_range': [['6.4.3', '']], 'type': 'dict'},
609 'vdom_type': {'v_range': [['7.2.0', '']], 'choices': ['traffic', 'admin'], 'type': 'str'}
610 },
611 'elements': 'dict'
612 },
613 'version': {'type': 'int'},
614 'vm_cpu': {'type': 'int'},
615 'vm_cpu_limit': {'type': 'int'},
616 'vm_lic_expire': {'type': 'int'},
617 'vm_mem': {'type': 'int'},
618 'vm_mem_limit': {'type': 'int'},
619 'vm_status': {'type': 'raw'},
620 'module_sn': {'v_range': [['6.2.1', '']], 'type': 'str'},
621 'prefer_img_ver': {'v_range': [['6.2.1', '']], 'type': 'str'},
622 'prio': {'v_range': [['6.4.1', '']], 'type': 'int'},
623 'role': {'v_range': [['6.4.1', '']], 'choices': ['master', 'ha-slave', 'autoscale-slave'], 'type': 'str'},
624 'hyperscale': {'v_range': [['6.2.7', '6.2.13'], ['6.4.3', '']], 'type': 'int'},
625 'nsxt_service_name': {'v_range': [['6.4.4', '']], 'type': 'str'},
626 'private_key': {'v_range': [['6.2.7', '6.2.13'], ['6.4.4', '']], 'no_log': True, 'type': 'str'},
627 'private_key_status': {'v_range': [['6.2.7', '6.2.13'], ['6.4.4', '']], 'no_log': True, 'type': 'int'},
628 'vm_lic_overdue_since': {'v_range': [['6.4.12', '6.4.15'], ['7.0.8', '7.0.16'], ['7.2.3', '']], 'type': 'int'},
629 'first_tunnel_up': {'v_range': [['7.0.4', '7.0.16'], ['7.2.1', '']], 'type': 'int'},
630 'eip': {'v_range': [['7.2.1', '']], 'type': 'str'},
631 'mgmt_uuid': {'v_range': [['7.2.1', '']], 'type': 'str'},
632 'hw_generation': {'v_range': [['7.2.4', '7.2.12'], ['7.4.1', '']], 'type': 'int'},
633 'relver_info': {'v_range': [['7.4.3', '']], 'type': 'str'},
634 'cluster_worker': {'v_range': [['7.6.0', '']], 'type': 'str'},
635 'ha.vsn': {'v_range': [['7.2.6', '7.2.12'], ['7.4.4', '']], 'type': 'str'},
636 'ha_upgrade_mode': {'v_range': [['7.4.4', '']], 'type': 'int'},
637 'vm_payg_status': {'v_range': [['7.4.4', '7.4.10'], ['7.6.2', '']], 'type': 'int'},
638 'sov_sase_license': {'v_range': [['7.4.7', '7.4.10'], ['7.6.4', '']], 'type': 'str'},
639 'tunnel_sn': {'v_range': [['7.6.5', '']], 'type': 'str'}
640 }
641 }
642 }
643
644 module_option_spec = get_module_arg_spec('partial crud')
645 module_arg_spec.update(module_option_spec)
646 check_galaxy_version(module_arg_spec)
647 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'dvmdb_device'),
648 supports_check_mode=True)
649 if not module._socket_path:
650 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
651 connection = Connection(module._socket_path)
652 fmgr = NAPIManager('partial crud', module_arg_spec, urls_list,
653 None, 'data', module, connection)
654 fmgr.process_partial_crud()
655 module.exit_json(meta=module.params)
656
657
658 if __name__ == '__main__':
659 main()