Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_router_isis.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3
4 # Copyright: (c) 2022 Fortinet
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 __metaclass__ = type
13
14 ANSIBLE_METADATA = {
15 "status": ["preview"],
16 "supported_by": "community",
17 "metadata_version": "1.1",
18 }
19
20 DOCUMENTATION = """
21 ---
22 module: fortios_router_isis
23 short_description: Configure IS-IS in Fortinet's FortiOS and FortiGate.
24 description:
25 - This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the
26 user to set and modify router feature and isis category.
27 Examples include all parameters and values need to be adjusted to datasources before usage.
28 Tested with FOS v6.0.0
29 version_added: "2.0.0"
30 author:
31 - Link Zheng (@chillancezen)
32 - Jie Xue (@JieX19)
33 - Hongbin Lu (@fgtdev-hblu)
34 - Frank Shen (@frankshen01)
35 - Miguel Angel Munoz (@mamunozgonzalez)
36 - Nicolas Thomas (@thomnico)
37 notes:
38 - Legacy fortiosapi has been deprecated, httpapi is the preferred way to run playbooks
39
40 - The module supports check_mode.
41
42 requirements:
43 - ansible>=2.16
44 options:
45 access_token:
46 description:
47 - Token-based authentication.
48 Generated from GUI of Fortigate.
49 type: str
50 required: false
51 enable_log:
52 description:
53 - Enable/Disable logging for task.
54 type: bool
55 required: false
56 default: false
57 vdom:
58 description:
59 - Virtual domain, among those defined previously. A vdom is a
60 virtual instance of the FortiGate that can be configured and
61 used as a different unit.
62 type: str
63 default: root
64 member_path:
65 type: str
66 description:
67 - Member attribute path to operate on.
68 - Delimited by a slash character if there are more than one attribute.
69 - Parameter marked with member_path is legitimate for doing member operation.
70 member_state:
71 type: str
72 description:
73 - Add or delete a member under specified attribute path.
74 - When member_state is specified, the state option is ignored.
75 choices:
76 - 'present'
77 - 'absent'
78
79 router_isis:
80 description:
81 - Configure IS-IS.
82 default: null
83 type: dict
84 suboptions:
85 adjacency_check:
86 description:
87 - Enable/disable adjacency check.
88 type: str
89 choices:
90 - 'enable'
91 - 'disable'
92 adjacency_check6:
93 description:
94 - Enable/disable IPv6 adjacency check.
95 type: str
96 choices:
97 - 'enable'
98 - 'disable'
99 adv_passive_only:
100 description:
101 - Enable/disable IS-IS advertisement of passive interfaces only.
102 type: str
103 choices:
104 - 'enable'
105 - 'disable'
106 adv_passive_only6:
107 description:
108 - Enable/disable IPv6 IS-IS advertisement of passive interfaces only.
109 type: str
110 choices:
111 - 'enable'
112 - 'disable'
113 auth_keychain_l1:
114 description:
115 - Authentication key-chain for level 1 PDUs. Source router.key-chain.name.
116 type: str
117 auth_keychain_l2:
118 description:
119 - Authentication key-chain for level 2 PDUs. Source router.key-chain.name.
120 type: str
121 auth_mode_l1:
122 description:
123 - Level 1 authentication mode.
124 type: str
125 choices:
126 - 'password'
127 - 'md5'
128 auth_mode_l2:
129 description:
130 - Level 2 authentication mode.
131 type: str
132 choices:
133 - 'password'
134 - 'md5'
135 auth_password_l1:
136 description:
137 - Authentication password for level 1 PDUs.
138 type: str
139 auth_password_l2:
140 description:
141 - Authentication password for level 2 PDUs.
142 type: str
143 auth_sendonly_l1:
144 description:
145 - Enable/disable level 1 authentication send-only.
146 type: str
147 choices:
148 - 'enable'
149 - 'disable'
150 auth_sendonly_l2:
151 description:
152 - Enable/disable level 2 authentication send-only.
153 type: str
154 choices:
155 - 'enable'
156 - 'disable'
157 default_originate:
158 description:
159 - Enable/disable distribution of default route information.
160 type: str
161 choices:
162 - 'enable'
163 - 'disable'
164 default_originate6:
165 description:
166 - Enable/disable distribution of default IPv6 route information.
167 type: str
168 choices:
169 - 'enable'
170 - 'disable'
171 dynamic_hostname:
172 description:
173 - Enable/disable dynamic hostname.
174 type: str
175 choices:
176 - 'enable'
177 - 'disable'
178 ignore_lsp_errors:
179 description:
180 - Enable/disable ignoring of LSP errors with bad checksums.
181 type: str
182 choices:
183 - 'enable'
184 - 'disable'
185 is_type:
186 description:
187 - IS type.
188 type: str
189 choices:
190 - 'level-1-2'
191 - 'level-1'
192 - 'level-2-only'
193 isis_interface:
194 description:
195 - IS-IS interface configuration.
196 type: list
197 elements: dict
198 suboptions:
199 auth_keychain_l1:
200 description:
201 - Authentication key-chain for level 1 PDUs. Source router.key-chain.name.
202 type: str
203 auth_keychain_l2:
204 description:
205 - Authentication key-chain for level 2 PDUs. Source router.key-chain.name.
206 type: str
207 auth_mode_l1:
208 description:
209 - Level 1 authentication mode.
210 type: str
211 choices:
212 - 'md5'
213 - 'password'
214 auth_mode_l2:
215 description:
216 - Level 2 authentication mode.
217 type: str
218 choices:
219 - 'md5'
220 - 'password'
221 auth_password_l1:
222 description:
223 - Authentication password for level 1 PDUs.
224 type: str
225 auth_password_l2:
226 description:
227 - Authentication password for level 2 PDUs.
228 type: str
229 auth_send_only_l1:
230 description:
231 - Enable/disable authentication send-only for level 1 PDUs.
232 type: str
233 choices:
234 - 'enable'
235 - 'disable'
236 auth_send_only_l2:
237 description:
238 - Enable/disable authentication send-only for level 2 PDUs.
239 type: str
240 choices:
241 - 'enable'
242 - 'disable'
243 circuit_type:
244 description:
245 - IS-IS interface"s circuit type.
246 type: str
247 choices:
248 - 'level-1-2'
249 - 'level-1'
250 - 'level-2'
251 csnp_interval_l1:
252 description:
253 - Level 1 CSNP interval.
254 type: int
255 csnp_interval_l2:
256 description:
257 - Level 2 CSNP interval.
258 type: int
259 hello_interval_l1:
260 description:
261 - Level 1 hello interval.
262 type: int
263 hello_interval_l2:
264 description:
265 - Level 2 hello interval.
266 type: int
267 hello_multiplier_l1:
268 description:
269 - Level 1 multiplier for Hello holding time.
270 type: int
271 hello_multiplier_l2:
272 description:
273 - Level 2 multiplier for Hello holding time.
274 type: int
275 hello_padding:
276 description:
277 - Enable/disable padding to IS-IS hello packets.
278 type: str
279 choices:
280 - 'enable'
281 - 'disable'
282 lsp_interval:
283 description:
284 - LSP transmission interval (milliseconds).
285 type: int
286 lsp_retransmit_interval:
287 description:
288 - LSP retransmission interval (sec).
289 type: int
290 mesh_group:
291 description:
292 - Enable/disable IS-IS mesh group.
293 type: str
294 choices:
295 - 'enable'
296 - 'disable'
297 mesh_group_id:
298 description:
299 - 'Mesh group ID <0-4294967295>, 0: mesh-group blocked.'
300 type: int
301 metric_l1:
302 description:
303 - Level 1 metric for interface.
304 type: int
305 metric_l2:
306 description:
307 - Level 2 metric for interface.
308 type: int
309 name:
310 description:
311 - IS-IS interface name. Source system.interface.name.
312 required: true
313 type: str
314 network_type:
315 description:
316 - IS-IS interface"s network type.
317 type: str
318 choices:
319 - 'broadcast'
320 - 'point-to-point'
321 - 'loopback'
322 priority_l1:
323 description:
324 - Level 1 priority.
325 type: int
326 priority_l2:
327 description:
328 - Level 2 priority.
329 type: int
330 status:
331 description:
332 - Enable/disable interface for IS-IS.
333 type: str
334 choices:
335 - 'enable'
336 - 'disable'
337 status6:
338 description:
339 - Enable/disable IPv6 interface for IS-IS.
340 type: str
341 choices:
342 - 'enable'
343 - 'disable'
344 wide_metric_l1:
345 description:
346 - Level 1 wide metric for interface.
347 type: int
348 wide_metric_l2:
349 description:
350 - Level 2 wide metric for interface.
351 type: int
352 isis_net:
353 description:
354 - IS-IS net configuration.
355 type: list
356 elements: dict
357 suboptions:
358 id:
359 description:
360 - ISIS network ID. see <a href='#notes'>Notes</a>.
361 required: true
362 type: int
363 net:
364 description:
365 - IS-IS networks (format = xx.xxxx. .xxxx.xx.).
366 type: str
367 lsp_gen_interval_l1:
368 description:
369 - Minimum interval for level 1 LSP regenerating.
370 type: int
371 lsp_gen_interval_l2:
372 description:
373 - Minimum interval for level 2 LSP regenerating.
374 type: int
375 lsp_refresh_interval:
376 description:
377 - LSP refresh time in seconds.
378 type: int
379 max_lsp_lifetime:
380 description:
381 - Maximum LSP lifetime in seconds.
382 type: int
383 metric_style:
384 description:
385 - Use old-style (ISO 10589) or new-style packet formats.
386 type: str
387 choices:
388 - 'narrow'
389 - 'wide'
390 - 'transition'
391 - 'narrow-transition'
392 - 'narrow-transition-l1'
393 - 'narrow-transition-l2'
394 - 'wide-l1'
395 - 'wide-l2'
396 - 'wide-transition'
397 - 'wide-transition-l1'
398 - 'wide-transition-l2'
399 - 'transition-l1'
400 - 'transition-l2'
401 overload_bit:
402 description:
403 - Enable/disable signal other routers not to use us in SPF.
404 type: str
405 choices:
406 - 'enable'
407 - 'disable'
408 overload_bit_on_startup:
409 description:
410 - Overload-bit only temporarily after reboot.
411 type: int
412 overload_bit_suppress:
413 description:
414 - Suppress overload-bit for the specific prefixes.
415 type: list
416 elements: str
417 choices:
418 - 'external'
419 - 'interlevel'
420 redistribute:
421 description:
422 - IS-IS redistribute protocols.
423 type: list
424 elements: dict
425 suboptions:
426 level:
427 description:
428 - Level.
429 type: str
430 choices:
431 - 'level-1-2'
432 - 'level-1'
433 - 'level-2'
434 metric:
435 description:
436 - Metric.
437 type: int
438 metric_type:
439 description:
440 - Metric type.
441 type: str
442 choices:
443 - 'external'
444 - 'internal'
445 protocol:
446 description:
447 - Protocol name.
448 required: true
449 type: str
450 routemap:
451 description:
452 - Route map name. Source router.route-map.name.
453 type: str
454 status:
455 description:
456 - Status.
457 type: str
458 choices:
459 - 'enable'
460 - 'disable'
461 redistribute_l1:
462 description:
463 - Enable/disable redistribution of level 1 routes into level 2.
464 type: str
465 choices:
466 - 'enable'
467 - 'disable'
468 redistribute_l1_list:
469 description:
470 - Access-list for route redistribution from l1 to l2. Source router.access-list.name.
471 type: str
472 redistribute_l2:
473 description:
474 - Enable/disable redistribution of level 2 routes into level 1.
475 type: str
476 choices:
477 - 'enable'
478 - 'disable'
479 redistribute_l2_list:
480 description:
481 - Access-list for route redistribution from l2 to l1. Source router.access-list.name.
482 type: str
483 redistribute6:
484 description:
485 - IS-IS IPv6 redistribution for routing protocols.
486 type: list
487 elements: dict
488 suboptions:
489 level:
490 description:
491 - Level.
492 type: str
493 choices:
494 - 'level-1-2'
495 - 'level-1'
496 - 'level-2'
497 metric:
498 description:
499 - Metric.
500 type: int
501 metric_type:
502 description:
503 - Metric type.
504 type: str
505 choices:
506 - 'external'
507 - 'internal'
508 protocol:
509 description:
510 - Protocol name.
511 required: true
512 type: str
513 routemap:
514 description:
515 - Route map name. Source router.route-map.name.
516 type: str
517 status:
518 description:
519 - Enable/disable redistribution.
520 type: str
521 choices:
522 - 'enable'
523 - 'disable'
524 redistribute6_l1:
525 description:
526 - Enable/disable redistribution of level 1 IPv6 routes into level 2.
527 type: str
528 choices:
529 - 'enable'
530 - 'disable'
531 redistribute6_l1_list:
532 description:
533 - Access-list for IPv6 route redistribution from l1 to l2. Source router.access-list6.name.
534 type: str
535 redistribute6_l2:
536 description:
537 - Enable/disable redistribution of level 2 IPv6 routes into level 1.
538 type: str
539 choices:
540 - 'enable'
541 - 'disable'
542 redistribute6_l2_list:
543 description:
544 - Access-list for IPv6 route redistribution from l2 to l1. Source router.access-list6.name.
545 type: str
546 spf_interval_exp_l1:
547 description:
548 - Level 1 SPF calculation delay.
549 type: str
550 spf_interval_exp_l2:
551 description:
552 - Level 2 SPF calculation delay.
553 type: str
554 summary_address:
555 description:
556 - IS-IS summary addresses.
557 type: list
558 elements: dict
559 suboptions:
560 id:
561 description:
562 - Summary address entry ID. see <a href='#notes'>Notes</a>.
563 required: true
564 type: int
565 level:
566 description:
567 - Level.
568 type: str
569 choices:
570 - 'level-1-2'
571 - 'level-1'
572 - 'level-2'
573 prefix:
574 description:
575 - Prefix.
576 type: str
577 summary_address6:
578 description:
579 - IS-IS IPv6 summary address.
580 type: list
581 elements: dict
582 suboptions:
583 id:
584 description:
585 - Prefix entry ID. see <a href='#notes'>Notes</a>.
586 required: true
587 type: int
588 level:
589 description:
590 - Level.
591 type: str
592 choices:
593 - 'level-1-2'
594 - 'level-1'
595 - 'level-2'
596 prefix6:
597 description:
598 - IPv6 prefix.
599 type: str
600 """
601
602 EXAMPLES = """
603 - name: Configure IS-IS.
604 fortinet.fortios.fortios_router_isis:
605 vdom: "{{ vdom }}"
606 router_isis:
607 adjacency_check: "enable"
608 adjacency_check6: "enable"
609 adv_passive_only: "enable"
610 adv_passive_only6: "enable"
611 auth_keychain_l1: "<your_own_value> (source router.key-chain.name)"
612 auth_keychain_l2: "<your_own_value> (source router.key-chain.name)"
613 auth_mode_l1: "password"
614 auth_mode_l2: "password"
615 auth_password_l1: "<your_own_value>"
616 auth_password_l2: "<your_own_value>"
617 auth_sendonly_l1: "enable"
618 auth_sendonly_l2: "enable"
619 default_originate: "enable"
620 default_originate6: "enable"
621 dynamic_hostname: "enable"
622 ignore_lsp_errors: "enable"
623 is_type: "level-1-2"
624 isis_interface:
625 -
626 auth_keychain_l1: "<your_own_value> (source router.key-chain.name)"
627 auth_keychain_l2: "<your_own_value> (source router.key-chain.name)"
628 auth_mode_l1: "md5"
629 auth_mode_l2: "md5"
630 auth_password_l1: "<your_own_value>"
631 auth_password_l2: "<your_own_value>"
632 auth_send_only_l1: "enable"
633 auth_send_only_l2: "enable"
634 circuit_type: "level-1-2"
635 csnp_interval_l1: "10"
636 csnp_interval_l2: "10"
637 hello_interval_l1: "10"
638 hello_interval_l2: "10"
639 hello_multiplier_l1: "3"
640 hello_multiplier_l2: "3"
641 hello_padding: "enable"
642 lsp_interval: "33"
643 lsp_retransmit_interval: "5"
644 mesh_group: "enable"
645 mesh_group_id: "0"
646 metric_l1: "10"
647 metric_l2: "10"
648 name: "default_name_43 (source system.interface.name)"
649 network_type: "broadcast"
650 priority_l1: "64"
651 priority_l2: "64"
652 status: "enable"
653 status6: "enable"
654 wide_metric_l1: "10"
655 wide_metric_l2: "10"
656 isis_net:
657 -
658 id: "52"
659 net: "<your_own_value>"
660 lsp_gen_interval_l1: "30"
661 lsp_gen_interval_l2: "30"
662 lsp_refresh_interval: "900"
663 max_lsp_lifetime: "1200"
664 metric_style: "narrow"
665 overload_bit: "enable"
666 overload_bit_on_startup: "0"
667 overload_bit_suppress: "external"
668 redistribute:
669 -
670 level: "level-1-2"
671 metric: "0"
672 metric_type: "external"
673 protocol: "<your_own_value>"
674 routemap: "<your_own_value> (source router.route-map.name)"
675 status: "enable"
676 redistribute_l1: "enable"
677 redistribute_l1_list: "<your_own_value> (source router.access-list.name)"
678 redistribute_l2: "enable"
679 redistribute_l2_list: "<your_own_value> (source router.access-list.name)"
680 redistribute6:
681 -
682 level: "level-1-2"
683 metric: "0"
684 metric_type: "external"
685 protocol: "<your_own_value>"
686 routemap: "<your_own_value> (source router.route-map.name)"
687 status: "enable"
688 redistribute6_l1: "enable"
689 redistribute6_l1_list: "<your_own_value> (source router.access-list6.name)"
690 redistribute6_l2: "enable"
691 redistribute6_l2_list: "<your_own_value> (source router.access-list6.name)"
692 spf_interval_exp_l1: "<your_own_value>"
693 spf_interval_exp_l2: "<your_own_value>"
694 summary_address:
695 -
696 id: "87"
697 level: "level-1-2"
698 prefix: "<your_own_value>"
699 summary_address6:
700 -
701 id: "91"
702 level: "level-1-2"
703 prefix6: "<your_own_value>"
704 """
705
706 RETURN = """
707 build:
708 description: Build number of the fortigate image
709 returned: always
710 type: str
711 sample: '1547'
712 http_method:
713 description: Last method used to provision the content into FortiGate
714 returned: always
715 type: str
716 sample: 'PUT'
717 http_status:
718 description: Last result given by FortiGate on last operation applied
719 returned: always
720 type: str
721 sample: "200"
722 mkey:
723 description: Master key (id) used in the last call to FortiGate
724 returned: success
725 type: str
726 sample: "id"
727 name:
728 description: Name of the table used to fulfill the request
729 returned: always
730 type: str
731 sample: "urlfilter"
732 path:
733 description: Path of the table used to fulfill the request
734 returned: always
735 type: str
736 sample: "webfilter"
737 revision:
738 description: Internal revision number
739 returned: always
740 type: str
741 sample: "17.0.2.10658"
742 serial:
743 description: Serial number of the unit
744 returned: always
745 type: str
746 sample: "FGVMEVYYQT3AB5352"
747 status:
748 description: Indication of the operation's result
749 returned: always
750 type: str
751 sample: "success"
752 vdom:
753 description: Virtual domain used
754 returned: always
755 type: str
756 sample: "root"
757 version:
758 description: Version of the FortiGate
759 returned: always
760 type: str
761 sample: "v5.6.3"
762 """
763 from ansible.module_utils.basic import AnsibleModule
764 from ansible.module_utils.connection import Connection
765 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
766 FortiOSHandler,
767 )
768 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
769 check_legacy_fortiosapi,
770 )
771 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
772 schema_to_module_spec,
773 )
774 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
775 check_schema_versioning,
776 )
777 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
778 FAIL_SOCKET_MSG,
779 )
780 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
781 remove_invalid_fields,
782 )
783 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
784 is_same_comparison,
785 )
786 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
787 serialize,
788 )
789 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
790 find_current_values,
791 )
792 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
793 unify_data_format,
794 )
795
796
797 def filter_router_isis_data(json):
798 option_list = [
799 "adjacency_check",
800 "adjacency_check6",
801 "adv_passive_only",
802 "adv_passive_only6",
803 "auth_keychain_l1",
804 "auth_keychain_l2",
805 "auth_mode_l1",
806 "auth_mode_l2",
807 "auth_password_l1",
808 "auth_password_l2",
809 "auth_sendonly_l1",
810 "auth_sendonly_l2",
811 "default_originate",
812 "default_originate6",
813 "dynamic_hostname",
814 "ignore_lsp_errors",
815 "is_type",
816 "isis_interface",
817 "isis_net",
818 "lsp_gen_interval_l1",
819 "lsp_gen_interval_l2",
820 "lsp_refresh_interval",
821 "max_lsp_lifetime",
822 "metric_style",
823 "overload_bit",
824 "overload_bit_on_startup",
825 "overload_bit_suppress",
826 "redistribute",
827 "redistribute_l1",
828 "redistribute_l1_list",
829 "redistribute_l2",
830 "redistribute_l2_list",
831 "redistribute6",
832 "redistribute6_l1",
833 "redistribute6_l1_list",
834 "redistribute6_l2",
835 "redistribute6_l2_list",
836 "spf_interval_exp_l1",
837 "spf_interval_exp_l2",
838 "summary_address",
839 "summary_address6",
840 ]
841
842 json = remove_invalid_fields(json)
843 dictionary = {}
844
845 for attribute in option_list:
846 if attribute in json and json[attribute] is not None:
847 dictionary[attribute] = json[attribute]
848
849 return dictionary
850
851
852 def flatten_single_path(data, path, index):
853 if (
854 not data
855 or index == len(path)
856 or path[index] not in data
857 or (not data[path[index]] and not isinstance(data[path[index]], list))
858 ):
859 return
860
861 if index == len(path) - 1:
862 data[path[index]] = " ".join(str(elem) for elem in data[path[index]])
863 if len(data[path[index]]) == 0:
864 data[path[index]] = None
865 elif isinstance(data[path[index]], list):
866 for value in data[path[index]]:
867 flatten_single_path(value, path, index + 1)
868 else:
869 flatten_single_path(data[path[index]], path, index + 1)
870
871
872 def flatten_multilists_attributes(data):
873 multilist_attrs = [
874 ["overload_bit_suppress"],
875 ]
876
877 for attr in multilist_attrs:
878 flatten_single_path(data, attr, 0)
879
880 return data
881
882
883 def underscore_to_hyphen(data):
884 new_data = None
885 if isinstance(data, list):
886 new_data = []
887 for i, elem in enumerate(data):
888 new_data.append(underscore_to_hyphen(elem))
889 elif isinstance(data, dict):
890 new_data = {}
891 for k, v in data.items():
892 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
893 else:
894 return data
895 return new_data
896
897
898 def router_isis(data, fos, check_mode=False):
899
900 state = None
901 vdom = data["vdom"]
902 parameters = None
903 state = data.get("state", None)
904 router_isis_data = data["router_isis"]
905
906 filtered_data = filter_router_isis_data(router_isis_data)
907 filtered_data = flatten_multilists_attributes(filtered_data)
908 converted_data = underscore_to_hyphen(filtered_data)
909
910 # check_mode starts from here
911 if check_mode:
912 diff = {
913 "before": "",
914 "after": filtered_data,
915 }
916 mkeyname = fos.get_mkeyname(None, None)
917 mkey = fos.get_mkey("router", "isis", filtered_data, vdom=vdom)
918 current_data = fos.get(
919 "router", "isis", vdom=vdom, mkey=mkey, parameters=parameters
920 )
921 is_existed = (
922 current_data
923 and current_data.get("http_status") == 200
924 and (
925 mkeyname
926 and isinstance(current_data.get("results"), list)
927 and len(current_data["results"]) > 0
928 or not mkeyname
929 and current_data["results"] # global object response
930 )
931 )
932
933 # 2. if it exists and the state is 'present' then compare current settings with desired
934 if state == "present" or state is True or state is None:
935 # for non global modules, mkeyname must exist and it's a new module when mkey is None
936 if mkeyname is not None and mkey is None:
937 return False, True, filtered_data, diff
938
939 # if mkey exists then compare each other
940 # record exits and they're matched or not
941 copied_filtered_data = filtered_data.copy()
942 copied_filtered_data.pop(mkeyname, None)
943 unified_filtered_data = unify_data_format(copied_filtered_data)
944
945 current_data_results = current_data.get("results", {})
946 current_config = (
947 current_data_results[0]
948 if mkeyname
949 and isinstance(current_data_results, list)
950 and len(current_data_results) > 0
951 else current_data_results
952 )
953 if is_existed:
954 unified_current_values = find_current_values(
955 unified_filtered_data,
956 unify_data_format(current_config),
957 )
958
959 is_same = is_same_comparison(
960 serialize(unified_current_values), serialize(unified_filtered_data)
961 )
962
963 return (
964 False,
965 not is_same,
966 filtered_data,
967 {"before": unified_current_values, "after": unified_filtered_data},
968 )
969
970 # record does not exist
971 return False, True, filtered_data, diff
972
973 if state == "absent":
974 if mkey is None:
975 return (
976 False,
977 False,
978 filtered_data,
979 {"before": current_data["results"][0], "after": ""},
980 )
981
982 if is_existed:
983 return (
984 False,
985 True,
986 filtered_data,
987 {"before": current_data["results"][0], "after": ""},
988 )
989 return False, False, filtered_data, {}
990
991 return True, False, {"reason: ": "Must provide state parameter"}, {}
992 # pass post processed data to member operations
993 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
994 data_copy = data.copy()
995 data_copy["router_isis"] = filtered_data
996 fos.do_member_operation(
997 "router",
998 "isis",
999 data_copy,
1000 )
1001
1002 return fos.set(
1003 "router", "isis", data=converted_data, vdom=vdom, parameters=parameters
1004 )
1005
1006
1007 def is_successful_status(resp):
1008 return (
1009 "status" in resp
1010 and resp["status"] == "success"
1011 or "http_status" in resp
1012 and resp["http_status"] == 200
1013 or "http_method" in resp
1014 and resp["http_method"] == "DELETE"
1015 and resp["http_status"] == 404
1016 )
1017
1018
1019 def fortios_router(data, fos, check_mode):
1020
1021 if data["router_isis"]:
1022 resp = router_isis(data, fos, check_mode)
1023 else:
1024 fos._module.fail_json(msg="missing task body: %s" % ("router_isis"))
1025 if isinstance(resp, tuple) and len(resp) == 4:
1026 return resp
1027 return (
1028 not is_successful_status(resp),
1029 is_successful_status(resp)
1030 and (resp["revision_changed"] if "revision_changed" in resp else True),
1031 resp,
1032 {},
1033 )
1034
1035
1036 versioned_schema = {
1037 "v_range": [["v6.0.0", ""]],
1038 "type": "dict",
1039 "children": {
1040 "is_type": {
1041 "v_range": [["v6.0.0", ""]],
1042 "type": "string",
1043 "options": [
1044 {"value": "level-1-2"},
1045 {"value": "level-1"},
1046 {"value": "level-2-only"},
1047 ],
1048 },
1049 "adv_passive_only": {
1050 "v_range": [["v6.0.0", ""]],
1051 "type": "string",
1052 "options": [{"value": "enable"}, {"value": "disable"}],
1053 },
1054 "adv_passive_only6": {
1055 "v_range": [["v6.0.0", ""]],
1056 "type": "string",
1057 "options": [{"value": "enable"}, {"value": "disable"}],
1058 },
1059 "auth_mode_l1": {
1060 "v_range": [["v6.0.0", ""]],
1061 "type": "string",
1062 "options": [{"value": "password"}, {"value": "md5"}],
1063 },
1064 "auth_mode_l2": {
1065 "v_range": [["v6.0.0", ""]],
1066 "type": "string",
1067 "options": [{"value": "password"}, {"value": "md5"}],
1068 },
1069 "auth_password_l1": {"v_range": [["v6.0.0", ""]], "type": "string"},
1070 "auth_password_l2": {"v_range": [["v6.0.0", ""]], "type": "string"},
1071 "auth_keychain_l1": {"v_range": [["v6.0.0", ""]], "type": "string"},
1072 "auth_keychain_l2": {"v_range": [["v6.0.0", ""]], "type": "string"},
1073 "auth_sendonly_l1": {
1074 "v_range": [["v6.0.0", ""]],
1075 "type": "string",
1076 "options": [{"value": "enable"}, {"value": "disable"}],
1077 },
1078 "auth_sendonly_l2": {
1079 "v_range": [["v6.0.0", ""]],
1080 "type": "string",
1081 "options": [{"value": "enable"}, {"value": "disable"}],
1082 },
1083 "ignore_lsp_errors": {
1084 "v_range": [["v6.0.0", ""]],
1085 "type": "string",
1086 "options": [{"value": "enable"}, {"value": "disable"}],
1087 },
1088 "lsp_gen_interval_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1089 "lsp_gen_interval_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1090 "lsp_refresh_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1091 "max_lsp_lifetime": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1092 "spf_interval_exp_l1": {"v_range": [["v6.0.0", ""]], "type": "string"},
1093 "spf_interval_exp_l2": {"v_range": [["v6.0.0", ""]], "type": "string"},
1094 "dynamic_hostname": {
1095 "v_range": [["v6.0.0", ""]],
1096 "type": "string",
1097 "options": [{"value": "enable"}, {"value": "disable"}],
1098 },
1099 "adjacency_check": {
1100 "v_range": [["v6.0.0", ""]],
1101 "type": "string",
1102 "options": [{"value": "enable"}, {"value": "disable"}],
1103 },
1104 "adjacency_check6": {
1105 "v_range": [["v6.0.0", ""]],
1106 "type": "string",
1107 "options": [{"value": "enable"}, {"value": "disable"}],
1108 },
1109 "overload_bit": {
1110 "v_range": [["v6.0.0", ""]],
1111 "type": "string",
1112 "options": [{"value": "enable"}, {"value": "disable"}],
1113 },
1114 "overload_bit_suppress": {
1115 "v_range": [["v6.0.0", ""]],
1116 "type": "list",
1117 "options": [{"value": "external"}, {"value": "interlevel"}],
1118 "multiple_values": True,
1119 "elements": "str",
1120 },
1121 "overload_bit_on_startup": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1122 "default_originate": {
1123 "v_range": [["v6.0.0", ""]],
1124 "type": "string",
1125 "options": [{"value": "enable"}, {"value": "disable"}],
1126 },
1127 "default_originate6": {
1128 "v_range": [["v6.0.0", ""]],
1129 "type": "string",
1130 "options": [{"value": "enable"}, {"value": "disable"}],
1131 },
1132 "metric_style": {
1133 "v_range": [["v6.0.0", ""]],
1134 "type": "string",
1135 "options": [
1136 {"value": "narrow"},
1137 {"value": "wide"},
1138 {"value": "transition"},
1139 {"value": "narrow-transition"},
1140 {"value": "narrow-transition-l1"},
1141 {"value": "narrow-transition-l2"},
1142 {"value": "wide-l1"},
1143 {"value": "wide-l2"},
1144 {"value": "wide-transition"},
1145 {"value": "wide-transition-l1"},
1146 {"value": "wide-transition-l2"},
1147 {"value": "transition-l1"},
1148 {"value": "transition-l2"},
1149 ],
1150 },
1151 "redistribute_l1": {
1152 "v_range": [["v6.0.0", ""]],
1153 "type": "string",
1154 "options": [{"value": "enable"}, {"value": "disable"}],
1155 },
1156 "redistribute_l1_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
1157 "redistribute_l2": {
1158 "v_range": [["v6.0.0", ""]],
1159 "type": "string",
1160 "options": [{"value": "enable"}, {"value": "disable"}],
1161 },
1162 "redistribute_l2_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
1163 "redistribute6_l1": {
1164 "v_range": [["v6.0.0", ""]],
1165 "type": "string",
1166 "options": [{"value": "enable"}, {"value": "disable"}],
1167 },
1168 "redistribute6_l1_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
1169 "redistribute6_l2": {
1170 "v_range": [["v6.0.0", ""]],
1171 "type": "string",
1172 "options": [{"value": "enable"}, {"value": "disable"}],
1173 },
1174 "redistribute6_l2_list": {"v_range": [["v6.0.0", ""]], "type": "string"},
1175 "isis_net": {
1176 "type": "list",
1177 "elements": "dict",
1178 "children": {
1179 "id": {
1180 "v_range": [["v6.0.0", ""]],
1181 "type": "integer",
1182 "required": True,
1183 },
1184 "net": {"v_range": [["v6.0.0", ""]], "type": "string"},
1185 },
1186 "v_range": [["v6.0.0", ""]],
1187 },
1188 "isis_interface": {
1189 "type": "list",
1190 "elements": "dict",
1191 "children": {
1192 "name": {
1193 "v_range": [["v6.0.0", ""]],
1194 "type": "string",
1195 "required": True,
1196 },
1197 "status": {
1198 "v_range": [["v6.0.0", ""]],
1199 "type": "string",
1200 "options": [{"value": "enable"}, {"value": "disable"}],
1201 },
1202 "status6": {
1203 "v_range": [["v6.0.0", ""]],
1204 "type": "string",
1205 "options": [{"value": "enable"}, {"value": "disable"}],
1206 },
1207 "network_type": {
1208 "v_range": [["v6.0.0", ""]],
1209 "type": "string",
1210 "options": [
1211 {"value": "broadcast"},
1212 {"value": "point-to-point"},
1213 {"value": "loopback"},
1214 ],
1215 },
1216 "circuit_type": {
1217 "v_range": [["v6.0.0", ""]],
1218 "type": "string",
1219 "options": [
1220 {"value": "level-1-2"},
1221 {"value": "level-1"},
1222 {"value": "level-2"},
1223 ],
1224 },
1225 "csnp_interval_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1226 "csnp_interval_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1227 "hello_interval_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1228 "hello_interval_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1229 "hello_multiplier_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1230 "hello_multiplier_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1231 "hello_padding": {
1232 "v_range": [["v6.0.0", ""]],
1233 "type": "string",
1234 "options": [{"value": "enable"}, {"value": "disable"}],
1235 },
1236 "lsp_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1237 "lsp_retransmit_interval": {
1238 "v_range": [["v6.0.0", ""]],
1239 "type": "integer",
1240 },
1241 "metric_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1242 "metric_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1243 "wide_metric_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1244 "wide_metric_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1245 "auth_password_l1": {"v_range": [["v6.0.0", ""]], "type": "string"},
1246 "auth_password_l2": {"v_range": [["v6.0.0", ""]], "type": "string"},
1247 "auth_keychain_l1": {"v_range": [["v6.0.0", ""]], "type": "string"},
1248 "auth_keychain_l2": {"v_range": [["v6.0.0", ""]], "type": "string"},
1249 "auth_send_only_l1": {
1250 "v_range": [["v6.0.0", ""]],
1251 "type": "string",
1252 "options": [{"value": "enable"}, {"value": "disable"}],
1253 },
1254 "auth_send_only_l2": {
1255 "v_range": [["v6.0.0", ""]],
1256 "type": "string",
1257 "options": [{"value": "enable"}, {"value": "disable"}],
1258 },
1259 "auth_mode_l1": {
1260 "v_range": [["v6.0.0", ""]],
1261 "type": "string",
1262 "options": [{"value": "md5"}, {"value": "password"}],
1263 },
1264 "auth_mode_l2": {
1265 "v_range": [["v6.0.0", ""]],
1266 "type": "string",
1267 "options": [{"value": "md5"}, {"value": "password"}],
1268 },
1269 "priority_l1": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1270 "priority_l2": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1271 "mesh_group": {
1272 "v_range": [["v6.0.0", ""]],
1273 "type": "string",
1274 "options": [{"value": "enable"}, {"value": "disable"}],
1275 },
1276 "mesh_group_id": {"v_range": [["v6.0.0", ""]], "type": "integer"},
1277 },
1278 "v_range": [["v6.0.0", ""]],
1279 },
1280 "summary_address": {
1281 "type": "list",
1282 "elements": "dict",
1283 "children": {
1284 "id": {
1285 "v_range": [["v6.0.0", ""]],
1286 "type": "integer",
1287 "required": True,
1288 },
1289 "prefix": {"v_range": [["v6.0.0", ""]], "type": "string"},
1290 "level": {
1291 "v_range": [["v6.0.0", ""]],
1292 "type": "string",
1293 "options": [
1294 {"value": "level-1-2"},
1295 {"value": "level-1"},
1296 {"value": "level-2"},
1297 ],
1298 },
1299 },
1300 "v_range": [["v6.0.0", ""]],
1301 },
1302 "summary_address6": {
1303 "type": "list",
1304 "elements": "dict",
1305 "children": {
1306 "id": {
1307 "v_range": [["v6.0.0", ""]],
1308 "type": "integer",
1309 "required": True,
1310 },
1311 "prefix6": {"v_range": [["v6.0.0", ""]], "type": "string"},
1312 "level": {
1313 "v_range": [["v6.0.0", ""]],
1314 "type": "string",
1315 "options": [
1316 {"value": "level-1-2"},
1317 {"value": "level-1"},
1318 {"value": "level-2"},
1319 ],
1320 },
1321 },
1322 "v_range": [["v6.0.0", ""]],
1323 },
1324 "redistribute": {
1325 "type": "list",
1326 "elements": "dict",
1327 "children": {
1328 "protocol": {
1329 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1330 "type": "string",
1331 "required": True,
1332 },
1333 "status": {
1334 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1335 "type": "string",
1336 "options": [{"value": "enable"}, {"value": "disable"}],
1337 },
1338 "metric": {
1339 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1340 "type": "integer",
1341 },
1342 "metric_type": {
1343 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1344 "type": "string",
1345 "options": [{"value": "external"}, {"value": "internal"}],
1346 },
1347 "level": {
1348 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1349 "type": "string",
1350 "options": [
1351 {"value": "level-1-2"},
1352 {"value": "level-1"},
1353 {"value": "level-2"},
1354 ],
1355 },
1356 "routemap": {
1357 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1358 "type": "string",
1359 },
1360 },
1361 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1362 },
1363 "redistribute6": {
1364 "type": "list",
1365 "elements": "dict",
1366 "children": {
1367 "protocol": {
1368 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1369 "type": "string",
1370 "required": True,
1371 },
1372 "status": {
1373 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1374 "type": "string",
1375 "options": [{"value": "enable"}, {"value": "disable"}],
1376 },
1377 "metric": {
1378 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1379 "type": "integer",
1380 },
1381 "metric_type": {
1382 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1383 "type": "string",
1384 "options": [{"value": "external"}, {"value": "internal"}],
1385 },
1386 "level": {
1387 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1388 "type": "string",
1389 "options": [
1390 {"value": "level-1-2"},
1391 {"value": "level-1"},
1392 {"value": "level-2"},
1393 ],
1394 },
1395 "routemap": {
1396 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1397 "type": "string",
1398 },
1399 },
1400 "v_range": [["v6.0.0", "v7.0.5"], ["v7.2.0", "v7.2.0"]],
1401 },
1402 },
1403 }
1404
1405
1406 def main():
1407 module_spec = schema_to_module_spec(versioned_schema)
1408 mkeyname = None
1409 fields = {
1410 "access_token": {"required": False, "type": "str", "no_log": True},
1411 "enable_log": {"required": False, "type": "bool", "default": False},
1412 "vdom": {"required": False, "type": "str", "default": "root"},
1413 "member_path": {"required": False, "type": "str"},
1414 "member_state": {
1415 "type": "str",
1416 "required": False,
1417 "choices": ["present", "absent"],
1418 },
1419 "router_isis": {
1420 "required": False,
1421 "type": "dict",
1422 "default": None,
1423 "options": {},
1424 },
1425 }
1426 for attribute_name in module_spec["options"]:
1427 fields["router_isis"]["options"][attribute_name] = module_spec["options"][
1428 attribute_name
1429 ]
1430 if mkeyname and mkeyname == attribute_name:
1431 fields["router_isis"]["options"][attribute_name]["required"] = True
1432
1433 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
1434 check_legacy_fortiosapi(module)
1435
1436 is_error = False
1437 has_changed = False
1438 result = None
1439 diff = None
1440
1441 versions_check_result = None
1442 if module._socket_path:
1443 connection = Connection(module._socket_path)
1444 if "access_token" in module.params:
1445 connection.set_custom_option("access_token", module.params["access_token"])
1446
1447 if "enable_log" in module.params:
1448 connection.set_custom_option("enable_log", module.params["enable_log"])
1449 else:
1450 connection.set_custom_option("enable_log", False)
1451 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
1452 versions_check_result = check_schema_versioning(
1453 fos, versioned_schema, "router_isis"
1454 )
1455
1456 is_error, has_changed, result, diff = fortios_router(
1457 module.params, fos, module.check_mode
1458 )
1459
1460 else:
1461 module.fail_json(**FAIL_SOCKET_MSG)
1462
1463 if versions_check_result and versions_check_result["matched"] is False:
1464 module.warn(
1465 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
1466 )
1467
1468 if not is_error:
1469 if versions_check_result and versions_check_result["matched"] is False:
1470 module.exit_json(
1471 changed=has_changed,
1472 version_check_warning=versions_check_result,
1473 meta=result,
1474 diff=diff,
1475 )
1476 else:
1477 module.exit_json(changed=has_changed, meta=result, diff=diff)
1478 else:
1479 if versions_check_result and versions_check_result["matched"] is False:
1480 module.fail_json(
1481 msg="Error in repo",
1482 version_check_warning=versions_check_result,
1483 meta=result,
1484 )
1485 else:
1486 module.fail_json(msg="Error in repo", meta=result)
1487
1488
1489 if __name__ == "__main__":
1490 main()