Debian Codegraph @

ansible_collections/f5networks/f5_modules/plugins/modules/bigip_network_globals.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright: (c) 2019, F5 Networks Inc.
5 # GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10 DOCUMENTATION = r'''
11 ---
12 module: bigip_network_globals
13 short_description: Manage network global settings on BIG-IP
14 description:
15 - Module to manage STP, Multicast, DAG, LLDP and Self Allow global settings on a BIG-IP.
16 version_added: "1.0.0"
17 options:
18 stp:
19 description:
20 - Manage global settings for STP on BIG-IP.
21 type: dict
22 suboptions:
23 config_name:
24 description:
25 - Specifies the configuration name. The accepted length is from 1 to 32 characters.
26 - Only has effect when the C(mode) is C(mstp).
27 type: str
28 config_revision:
29 description:
30 - Specifies the revision level of the MSTP configuration, when C(mode) is C(mstp).
31 - You must specify a number in the range of 0 to 65535.
32 type: int
33 description:
34 description:
35 - User-defined description.
36 type: str
37 fwd_delay:
38 description:
39 - The number of seconds for which an interface was blocked from forwarding network traffic after a
40 reconfiguration of the spanning tree topology. This parameter has no effect when C(rstp) or C(mstp) modes
41 are used, as long as all bridges in the spanning tree use the RSTP or MSTP protocol.
42 - If any legacy STP bridges are present, neighboring bridges must fall back to the old protocol,
43 whose reconfiguration time is affected by the forward delay value.
44 - The valid range is 4 to 30.
45 type: int
46 hello_time:
47 description:
48 - Specifies the time interval in seconds between the periodic transmissions that communicate spanning tree
49 information to the adjacent bridges in the network.
50 - The hello time set by default on the device is optimal in virtually all cases. F5 recommends that you do
51 not change the hello time.
52 - The valid range is 1 to 10.
53 type: int
54 max_age:
55 description:
56 - Specifies the number of seconds for which spanning tree information received from other bridges is
57 considered valid.
58 - The valid range is 6 to 40 seconds.
59 type: int
60 max_hops:
61 description:
62 - Specifies the maximum number of hops an MSTP packet may travel before it is discarded.
63 - This option only takes effect when C(mode) is C(mstp).
64 - The number of hops must be in the range of 1 to 255.
65 type: int
66 mode:
67 description:
68 - Specifies the spanning tree mode.
69 - "The C(mstp), C(rstp) and C(stp) options are only supported on hardware platforms. Attempting to set these
70 modes on VE type platforms will result in failure. The only valid options on VE type platforms are:
71 C(passthru) and C(disabled)."
72 type: str
73 choices:
74 - disabled
75 - mstp
76 - passthru
77 - rstp
78 - stp
79 transmit_hold:
80 description:
81 - Specifies the absolute limit on the number of spanning tree protocol packets the traffic management system
82 may transmit on a port in any hello time interval.
83 - The valid range is 1 to 10 packets.
84 type: int
85 multicast:
86 description:
87 - Manage multicast traffic configuration options.
88 type: dict
89 suboptions:
90 max_pending_packets:
91 description:
92 - Specifies the maximum number of packet queued on behalf of a single incomplete MFC entry.
93 - The valid range is 0 - 4294967295.
94 type: int
95 max_pending_routes:
96 description:
97 - Specifies the number of incomplete MFC entries each TMM will allow to exist at one time.
98 - The valid range is 0 - 4294967295.
99 type: int
100 route_lookup_timeout:
101 description:
102 - Specifies maximum lifetime of an incomplete MFC entry, in seconds.
103 - The valid range is 0 - 4294967295.
104 type: int
105 rate_limit:
106 description:
107 - When C(true), the DB variable C(switchboard.maxmcastrate) setting controls the multicast packet per second rate
108 limiting in the switch.
109 type: bool
110 dag:
111 description:
112 - Manage global disaggregation settings.
113 type: dict
114 suboptions:
115 round_robin_mode:
116 description:
117 - Specifies whether the round robin disaggregator (DAG) on a blade can disaggregate packets to all the TMMs
118 in the system or only to the TMMs local to the blade.
119 - When C(global), the DAG will disaggregate packets to all TMMs in the system.
120 - When C(local), the DAG will disaggregate packets only to the TMMs local to the blade.
121 type: str
122 choices:
123 - global
124 - local
125 icmp_hash:
126 description:
127 - Specifies the ICMP hash for ICMP echo request and ICMP echo reply in SW DAG.
128 - When C(icmp), ICMP echo request and ICMP echo reply are disaggregated based on ICMP id.
129 - When C(ipicmp), ICMP echo request and ICMP echo reply are disaggregated based on ICMP id and IP addresses.
130 - This option is only available in C(TMOS) version C(13.x) and above.
131 type: str
132 choices:
133 - icmp
134 - ipicmp
135 dag_ipv6_prefix_len:
136 description:
137 - Specifies whether SPDAG or IPv6 prefix DAG should be used to disaggregate IPv6 traffic when vlan cmp hash
138 is set to C(src-ip) or C(dst-ip).
139 - The valid value range is 0 - 128, with C(128) value SPAG is in use.
140 - This option is only available in TMOS version C(13.x) and above.
141 type: int
142 lldp:
143 description:
144 - Manage LLDP configuration options.
145 type: dict
146 suboptions:
147 enabled:
148 description:
149 - Specifies the current status of LLDP.
150 - When C(true), the LLDP is enabled globally on the device.
151 - When C(false), the LLDP is disabled globally on the device.
152 type: bool
153 max_neighbors_per_port:
154 description:
155 - Specifies the maximum number of neighbors per port.
156 - The valid value range is 0 - 65535.
157 type: int
158 reinit_delay:
159 description:
160 - Specifies the maximum number of seconds to wait after reaching the TTL interval before resetting TTL timer.
161 - The valid value range is 0 - 65535.
162 type: int
163 tx_delay:
164 description:
165 - Specifies the number of seconds to wait for LLDP to initialize on an interface before sending LLDP message.
166 - The valid value range is 0 - 65535.
167 type: int
168 tx_hold:
169 description:
170 - "Specifies the multiplier that determines the LLDP Time to Live (TTL). TTL is determined by multiplying
171 this value and C(tx_interval)."
172 - The valid value range is 0 - 65535.
173 type: int
174 tx_interval:
175 description:
176 - Specifies the interval devices use to send LLDP information from each of their interfaces.
177 - The valid value range is 0 - 65535.
178 type: int
179 self_allow:
180 description:
181 - Manage Self Allow global configuration options.
182 type: dict
183 suboptions:
184 defaults:
185 description:
186 - The default set of protocols and ports allowed by a self IP if the self IP allow-service setting is
187 B(default).
188 type: list
189 elements: dict
190 suboptions:
191 protocol:
192 description:
193 - The protocol name to be set.
194 type: str
195 port:
196 description:
197 - The port number to be set.
198 - The valid value range is 0 - 65535.
199 type: int
200 all:
201 description:
202 - Sets B(all) or B(none) ports and protocols as a system wide C(self_allow) setting.
203 - When C(true), the self_allow allows all protocols and ports. This is the equivalent of setting B(all) option
204 in C(TMSH).
205 - When C(false), the self_allow allows no protocols and ports. This is the equivalent of setting B(none) option
206 in C(TMSH).
207 type: bool
208 version_added: "1.1.0"
209 extends_documentation_fragment: f5networks.f5_modules.f5
210 author:
211 - Wojciech Wypior (@wojtek0806)
212 '''
213
214 EXAMPLES = r'''
215 - name: Update STP settings
216 bigip_network_globals:
217 stp:
218 config_name: foobar
219 config_revision: 1
220 max_hops: 20
221 mode: mstp
222 provider:
223 password: secret
224 server: lb.mydomain.com
225 user: admin
226 delegate_to: localhost
227
228 - name: Update DAG settings
229 bigip_network_globals:
230 dag:
231 icmp_hash: ipicmp
232 round_robin_mode: local
233 provider:
234 password: secret
235 server: lb.mydomain.com
236 user: admin
237 delegate_to: localhost
238
239 - name: Update multiple settings
240 bigip_network_globals:
241 stp:
242 config_name: foobar
243 config_revision: 1
244 max_hops: 20
245 mode: mstp
246 dag:
247 icmp_hash: ipicmp
248 round_robin_mode: local
249 provider:
250 password: secret
251 server: lb.mydomain.com
252 user: admin
253 delegate_to: localhost
254 '''
255
256 RETURN = r'''
257 stp:
258 description: Manage global settings for STP on BIG-IP.
259 type: complex
260 returned: changed
261 contains:
262 config_name:
263 description: The configuration name.
264 returned: changed
265 type: str
266 sample: foobar
267 config_revision:
268 description: The revision level of the MSTP configuration.
269 returned: changed
270 type: int
271 sample: 2
272 description:
273 description: User-defined description.
274 returned: changed
275 type: str
276 sample: My description
277 fwd_delay:
278 description: The number of seconds for which an interface was blocked from forwarding network traffic.
279 returned: changed
280 type: int
281 sample: 4
282 hello_time:
283 description: The time interval at seconds between the periodic transmissions of spanning tree information.
284 returned: changed
285 type: int
286 sample: 2
287 max_age:
288 description: The number of seconds that spanning tree information received from other bridges is considered valid.
289 returned: changed
290 type: int
291 sample: 30
292 max_hops:
293 description: The maximum number of hops an MSTP packet may travel before it is discarded.
294 returned: changed
295 type: int
296 sample: 15
297 mode:
298 description: The spanning tree mode.
299 returned: changed
300 type: str
301 sample: mstp
302 transmit_hold:
303 description:
304 - The limit on the number of STP the traffic management system may transmit on a port in any hello
305 time interval.
306 returned: changed
307 type: int
308 sample: 5
309 sample: hash/dictionary of values
310 multicast:
311 description: Manage multicast traffic configuration options.
312 type: complex
313 returned: changed
314 contains:
315 max_pending_packets:
316 description: The maximum number of packet queued on behalf of a single incomplete MFC entry.
317 returned: changed
318 type: int
319 sample: 3000
320 max_pending_routes:
321 description: The number of incomplete MFC entries each TMM will allow to exist at one time.
322 returned: changed
323 type: int
324 sample: 50
325 route_lookup_timeout:
326 description: The maximum lifetime of an incomplete MFC entry, in seconds.
327 returned: changed
328 type: int
329 sample: 20
330 rate_limit:
331 description: Enables DB variable control over multicast packet per second rate limiting in the switch.
332 returned: changed
333 type: bool
334 sample: true
335 sample: hash/dictionary of values
336 dag:
337 description: Manage multicast traffic configuration options.
338 type: complex
339 returned: changed
340 contains:
341 round_robin_mode:
342 description: The mode of operation of the DAG on a blade.
343 returned: changed
344 type: str
345 sample: local
346 icmp_hash:
347 description: Specifies the ICMP hash for the ICMP echo request and ICMP echo reply in SW DAG.
348 returned: changed
349 type: str
350 sample: ipicmp
351 dag_ipv6_prefix_len:
352 description: Specifies whether SPDAG or IPv6 prefix DAG should be used to disaggregate IPv6 traffic.
353 returned: changed
354 type: int
355 sample: 128
356 sample: hash/dictionary of values
357 lldp:
358 description: Manage multicast traffic configuration options.
359 type: complex
360 returned: changed
361 contains:
362 enabled:
363 description: The current status of LLDP.
364 returned: changed
365 type: bool
366 sample: true
367 max_neighbors_per_port:
368 description: The maximum number of neighbors per port.
369 returned: changed
370 type: int
371 sample: 128
372 reinit_delay:
373 description: The maximum number of seconds to wait before resetting the TTL timer after reaching the TTL interval.
374 returned: changed
375 type: int
376 sample: 30
377 tx_delay:
378 description: The number of seconds to wait for LLDP to initialize on an interface before sending LLDP message.
379 returned: changed
380 type: int
381 sample: 500
382 tx_hold:
383 description: The multiplier that determines the LLDP Time to Live.
384 returned: changed
385 type: int
386 sample: 10
387 tx_interval:
388 description: The interval devices use to send LLDP information from each of their interfaces.
389 returned: changed
390 type: int
391 sample: 240
392 sample: hash/dictionary of values
393 self_allow:
394 description: Manages self_allow system wide settings.
395 type: complex
396 returned: changed
397 contains:
398 defaults:
399 description: The default set of protocols and ports allowed by a self IP.
400 type: complex
401 returned: changed
402 contains:
403 protocol:
404 description: The protocol name to be set.
405 returned: changed
406 type: str
407 sample: tcp
408 port:
409 description: The port number to be set.
410 returned: changed
411 type: int
412 sample: 443
413 sample: hash/dictionary of values
414 all:
415 description: Allows all or none ports and protocols as a system wide self_allow setting.
416 returned: changed
417 type: bool
418 sample: true
419 sample: hash/dictionary of values
420 '''
421 from datetime import datetime
422
423 from ansible.module_utils.basic import AnsibleModule
424 from ansible.module_utils.six import string_types
425
426 from ..module_utils.bigip import F5RestClient
427 from ..module_utils.common import (
428 F5ModuleError, AnsibleF5Parameters, f5_argument_spec, flatten_boolean
429 )
430 from ..module_utils.compare import (
431 cmp_str_with_none, cmp_simple_list
432 )
433 from ..module_utils.icontrol import tmos_version
434 from ..module_utils.teem import send_teem
435
436
437 class Parameters(AnsibleF5Parameters):
438 api_map = {}
439
440 api_attributes = []
441
442 returnables = [
443 'stp',
444 'dag',
445 'multicast',
446 'lldp',
447 'self_allow',
448 ]
449
450 updatables = [
451 'stp_config_name',
452 'stp_config_revision',
453 'stp_description',
454 'stp_fwd_delay',
455 'stp_hello_time',
456 'stp_max_age',
457 'stp_max_hops',
458 'stp_mode',
459 'stp_transmit_hold',
460 'mcast_max_pending_packets',
461 'mcast_max_pending_routes',
462 'mcast_rate_limit',
463 'mcast_route_lookup_timeout',
464 'dag_round_robin',
465 'dag_ipv6_prefix_len',
466 'dag_icmp_hash',
467 'lldp_enabled',
468 'lldp_disabled',
469 'lldp_max_neighbors_per_port',
470 'lldp_reinit_delay',
471 'lldp_tx_delay',
472 'lldp_tx_hold',
473 'lldp_tx_interval',
474 'self_allow_all',
475 'self_allow_defaults',
476 ]
477
478
479 class ApiParameters(Parameters):
480 @property
481 def stp_config_name(self):
482 if self._values['stp'] is None:
483 return None
484 return self._values['stp'].get('configName', None)
485
486 @property
487 def stp_config_revision(self):
488 if self._values['stp'] is None:
489 return None
490 return self._values['stp']['configRevision']
491
492 @property
493 def stp_description(self):
494 if self._values['stp'] is None:
495 return None
496 return self._values['stp'].get('description', None)
497
498 @property
499 def stp_fwd_delay(self):
500 if self._values['stp'] is None:
501 return None
502 return self._values['stp']['fwdDelay']
503
504 @property
505 def stp_hello_time(self):
506 if self._values['stp'] is None:
507 return None
508 return self._values['stp']['helloTime']
509
510 @property
511 def stp_max_age(self):
512 if self._values['stp'] is None:
513 return None
514 return self._values['stp']['maxAge']
515
516 @property
517 def stp_max_hops(self):
518 if self._values['stp'] is None:
519 return None
520 return self._values['stp']['maxHops']
521
522 @property
523 def stp_mode(self):
524 if self._values['stp'] is None:
525 return None
526 return self._values['stp']['mode']
527
528 @property
529 def stp_transmit_hold(self):
530 if self._values['stp'] is None:
531 return None
532 return self._values['stp']['transmitHold']
533
534 @property
535 def mcast_max_pending_packets(self):
536 if self._values['multicast'] is None:
537 return None
538 return self._values['multicast']['maxPendingPackets']
539
540 @property
541 def mcast_max_pending_routes(self):
542 if self._values['multicast'] is None:
543 return None
544 return self._values['multicast']['maxPendingRoutes']
545
546 @property
547 def mcast_rate_limit(self):
548 if self._values['multicast'] is None:
549 return None
550 result = flatten_boolean(self._values['multicast']['rateLimit'])
551 if result == 'yes':
552 return 'enabled'
553 if result == 'no':
554 return 'disabled'
555
556 @property
557 def mcast_route_lookup_timeout(self):
558 if self._values['multicast'] is None:
559 return None
560 return self._values['multicast']['routeLookupTimeout']
561
562 @property
563 def dag_round_robin_mode(self):
564 if self._values['dag'] is None:
565 return None
566 return self._values['dag']['roundRobinMode']
567
568 @property
569 def dag_ipv6_prefix_len(self):
570 if self._values['dag'] is None:
571 return None
572 return self._values['dag'].get('dagIpv6PrefixLen', None)
573
574 @property
575 def dag_icmp_hash(self):
576 if self._values['dag'] is None:
577 return None
578 return self._values['dag'].get('icmpHash', None)
579
580 @property
581 def lldp_enabled(self):
582 if self._values['lldp'] is None:
583 return None
584 if 'enabled' in self._values['lldp']:
585 result = flatten_boolean(self._values['lldp']['enabled'])
586 if result == 'yes':
587 return True
588
589 @property
590 def lldp_disabled(self):
591 if self._values['lldp'] is None:
592 return None
593 if 'disabled' in self._values['lldp']:
594 result = flatten_boolean(self._values['lldp']['disabled'])
595 if result == 'yes':
596 return True
597
598 @property
599 def lldp_max_neighbors_per_port(self):
600 if self._values['lldp'] is None:
601 return None
602 return self._values['lldp']['maxNeighborsPerPort']
603
604 @property
605 def lldp_reinit_delay(self):
606 if self._values['lldp'] is None:
607 return None
608 return self._values['lldp']['reinitDelay']
609
610 @property
611 def lldp_tx_delay(self):
612 if self._values['lldp'] is None:
613 return None
614 return self._values['lldp']['txDelay']
615
616 @property
617 def lldp_tx_hold(self):
618 if self._values['lldp'] is None:
619 return None
620 return self._values['lldp']['txHold']
621
622 @property
623 def lldp_tx_interval(self):
624 if self._values['lldp'] is None:
625 return None
626 return self._values['lldp']['txInterval']
627
628 @property
629 def self_allow_all(self):
630 if self.self_allow_defaults is None:
631 return 'no'
632 if self.self_allow_defaults == 'all':
633 return 'yes'
634
635 @property
636 def self_allow_defaults(self):
637 if self._values['self_allow'] is None:
638 return None
639 return self._values['self_allow'].get('defaults', None)
640
641
642 class ModuleParameters(Parameters):
643 @property
644 def stp_config_name(self):
645 if self._values['stp'] is None:
646 return None
647 if self._values['stp']['config_name'] is None:
648 return None
649 if len(self._values['stp']['config_name']) > 32:
650 raise F5ModuleError(
651 "The 'config_name' cannot be more than 32 characters in length."
652 )
653 return self._values['stp']['config_name']
654
655 @property
656 def stp_config_revision(self):
657 if self._values['stp'] is None:
658 return None
659 if self._values['stp']['config_revision'] is None:
660 return None
661 if 0 <= self._values['stp']['config_revision'] <= 65535:
662 return self._values['stp']['config_revision']
663 raise F5ModuleError(
664 "Valid 'config_revision' must be in range 0 - 65535."
665 )
666
667 @property
668 def stp_description(self):
669 if self._values['stp'] is None:
670 return None
671 if self._values['stp']['description'] is None:
672 return None
673 return self._values['stp']['description']
674
675 @property
676 def stp_fwd_delay(self):
677 if self._values['stp'] is None:
678 return None
679 if self._values['stp']['fwd_delay'] is None:
680 return None
681 if 4 <= self._values['stp']['fwd_delay'] <= 30:
682 return self._values['stp']['fwd_delay']
683 raise F5ModuleError(
684 "Valid 'fwd_delay' must be in range 4 - 30 seconds."
685 )
686
687 @property
688 def stp_hello_time(self):
689 if self._values['stp'] is None:
690 return None
691 if self._values['stp']['hello_time'] is None:
692 return None
693 if 1 <= self._values['stp']['hello_time'] <= 10:
694 return self._values['stp']['hello_time']
695 raise F5ModuleError(
696 "Valid 'hello_time' must be in range 1 - 10 seconds."
697 )
698
699 @property
700 def stp_max_age(self):
701 if self._values['stp'] is None:
702 return None
703 if self._values['stp']['max_age'] is None:
704 return None
705 if 6 <= self._values['stp']['max_age'] <= 40:
706 return self._values['stp']['max_age']
707 raise F5ModuleError(
708 "Valid 'hello_time' must be in range 6 - 40 seconds."
709 )
710
711 @property
712 def stp_max_hops(self):
713 if self._values['stp'] is None:
714 return None
715 if self._values['stp']['max_hops'] is None:
716 return None
717 if 1 <= self._values['stp']['max_hops'] <= 255:
718 return self._values['stp']['max_hops']
719 raise F5ModuleError(
720 "Valid 'max_hops' must be in range 1 - 255."
721 )
722
723 @property
724 def stp_mode(self):
725 if self._values['stp'] is None:
726 return None
727 if self._values['stp']['mode'] is None:
728 return None
729 return self._values['stp']['mode']
730
731 @property
732 def stp_transmit_hold(self):
733 if self._values['stp'] is None:
734 return None
735 if self._values['stp']['transmit_hold'] is None:
736 return None
737 if 1 <= self._values['stp']['transmit_hold'] <= 10:
738 return self._values['stp']['transmit_hold']
739 raise F5ModuleError(
740 "Valid 'transmit_hold' must be in range 1 - 10 packets."
741 )
742
743 @property
744 def mcast_max_pending_packets(self):
745 if self._values['multicast'] is None:
746 return None
747 if self._values['multicast']['max_pending_packets'] is None:
748 return None
749 if 0 <= self._values['multicast']['max_pending_packets'] <= 4294967295:
750 return self._values['multicast']['max_pending_packets']
751 raise F5ModuleError(
752 "Valid 'max_pending_packets' must be in range 0 - 4294967295."
753 )
754
755 @property
756 def mcast_max_pending_routes(self):
757 if self._values['multicast'] is None:
758 return None
759 if self._values['multicast']['max_pending_routes'] is None:
760 return None
761 if 0 <= self._values['multicast']['max_pending_routes'] <= 4294967295:
762 return self._values['multicast']['max_pending_routes']
763 raise F5ModuleError(
764 "Valid 'max_pending_routes' must be in range 0 - 4294967295."
765 )
766
767 @property
768 def mcast_rate_limit(self):
769 if self._values['multicast'] is None:
770 return None
771 result = flatten_boolean(self._values['multicast']['rate_limit'])
772 if result == 'yes':
773 return 'enabled'
774 if result == 'no':
775 return 'disabled'
776
777 @property
778 def mcast_route_lookup_timeout(self):
779 if self._values['multicast'] is None:
780 return None
781 if self._values['multicast']['route_lookup_timeout'] is None:
782 return None
783 if 0 <= self._values['multicast']['route_lookup_timeout'] <= 4294967295:
784 return self._values['multicast']['route_lookup_timeout']
785 raise F5ModuleError(
786 "Valid 'route_lookup_timeout' must be in range 0 - 4294967295."
787 )
788
789 @property
790 def dag_round_robin_mode(self):
791 if self._values['dag'] is None:
792 return None
793 if self._values['dag']['round_robin_mode'] is None:
794 return None
795 return self._values['dag']['round_robin_mode']
796
797 @property
798 def dag_ipv6_prefix_len(self):
799 if self._values['dag'] is None:
800 return None
801 if self._values['dag']['dag_ipv6_prefix_len'] is None:
802 return None
803 if 0 <= self._values['dag']['dag_ipv6_prefix_len'] <= 128:
804 return self._values['dag']['dag_ipv6_prefix_len']
805 raise F5ModuleError(
806 "Valid 'dag_ipv6_prefix_len' must be in range 0 - 128."
807 )
808
809 @property
810 def dag_icmp_hash(self):
811 if self._values['dag'] is None:
812 return None
813 if self._values['dag']['icmp_hash'] is None:
814 return None
815 return self._values['dag']['icmp_hash']
816
817 @property
818 def lldp_enabled(self):
819 if self._values['lldp'] is None:
820 return None
821 result = flatten_boolean(self._values['lldp']['enabled'])
822 if result == 'yes':
823 return True
824 return None
825
826 @property
827 def lldp_disabled(self):
828 if self._values['lldp'] is None:
829 return None
830 result = flatten_boolean(self._values['lldp']['enabled'])
831 if result == 'no':
832 return True
833 return None
834
835 @property
836 def lldp_max_neighbors_per_port(self):
837 if self._values['lldp'] is None:
838 return None
839 if self._values['lldp']['max_neighbors_per_port'] is None:
840 return None
841 if 0 <= self._values['lldp']['max_neighbors_per_port'] <= 65535:
842 return self._values['lldp']['max_neighbors_per_port']
843 raise F5ModuleError(
844 "Valid 'max_neighbors_per_port' must be in range 0 - 65535."
845 )
846
847 @property
848 def lldp_reinit_delay(self):
849 if self._values['lldp'] is None:
850 return None
851 if self._values['lldp']['reinit_delay'] is None:
852 return None
853 if 0 <= self._values['lldp']['reinit_delay'] <= 65535:
854 return self._values['lldp']['reinit_delay']
855 raise F5ModuleError(
856 "Valid 'reinit_delay' must be in range 0 - 65535 seconds."
857 )
858
859 @property
860 def lldp_tx_delay(self):
861 if self._values['lldp'] is None:
862 return None
863 if self._values['lldp']['tx_delay'] is None:
864 return None
865 if 0 <= self._values['lldp']['tx_delay'] <= 65535:
866 return self._values['lldp']['tx_delay']
867 raise F5ModuleError(
868 "Valid 'tx_delay' must be in range 0 - 65535 seconds."
869 )
870
871 @property
872 def lldp_tx_hold(self):
873 if self._values['lldp'] is None:
874 return None
875 if self._values['lldp']['tx_hold'] is None:
876 return None
877 if 0 <= self._values['lldp']['tx_hold'] <= 65535:
878 return self._values['lldp']['tx_hold']
879 raise F5ModuleError(
880 "Valid 'tx_hold' must be in range 0 - 65535."
881 )
882
883 @property
884 def lldp_tx_interval(self):
885 if self._values['lldp'] is None:
886 return None
887 if self._values['lldp']['tx_interval'] is None:
888 return None
889 if 0 <= self._values['lldp']['tx_interval'] <= 65535:
890 return self._values['lldp']['tx_interval']
891 raise F5ModuleError(
892 "Valid 'tx_interval' must be in range 0 - 65535 seconds."
893 )
894
895 @property
896 def self_allow_defaults(self):
897 if self._values['self_allow'] is None:
898 return None
899 if self.self_allow_all == 'yes':
900 return 'all'
901 if self.self_allow_all == 'no':
902 return 'none'
903 result = list()
904 for item in self._values['self_allow']['defaults']:
905 if not 0 <= item['port'] or not item['port'] <= 65535:
906 raise F5ModuleError(
907 "Valid self_allow_defaults port must be in range 0 - 65535."
908 )
909 to_append = "{0}:{1}".format(item['protocol'], item['port'])
910 result.append(to_append)
911 return result
912
913 @property
914 def self_allow_all(self):
915 if self._values['self_allow'] is None:
916 return None
917 result = flatten_boolean(self._values['self_allow']['all'])
918 return result
919
920
921 class Changes(Parameters):
922 def to_return(self):
923 result = {}
924 try:
925 for returnable in self.returnables:
926 result[returnable] = getattr(self, returnable)
927 result = self._filter_params(result)
928 except Exception:
929 raise
930 return result
931
932
933 class UsableChanges(Changes):
934 @property
935 def stp(self):
936 to_filter = dict(
937 configName=self._values['stp_config_name'],
938 configRevision=self._values['stp_config_revision'],
939 description=self._values['stp_description'],
940 fwdDelay=self._values['stp_fwd_delay'],
941 helloTime=self._values['stp_hello_time'],
942 maxAge=self._values['stp_max_age'],
943 maxHops=self._values['stp_max_hops'],
944 mode=self._values['stp_mode'],
945 transmitHold=self._values['stp_transmit_hold']
946 )
947 result = self._filter_params(to_filter)
948 if result:
949 return result
950
951 @property
952 def multicast(self):
953 to_filter = dict(
954 maxPendingPackets=self._values['mcast_max_pending_packets'],
955 maxPendingRoutes=self._values['mcast_max_pending_routes'],
956 rateLimit=self._values['mcast_rate_limit'],
957 routeLookupTimeout=self._values['mcast_route_lookup_timeout'],
958 )
959 result = self._filter_params(to_filter)
960 if result:
961 return result
962
963 @property
964 def dag(self):
965 to_filter = dict(
966 roundRobinMode=self._values['dag_round_robin_mode'],
967 dagIpv6PrefixLen=self._values['dag_ipv6_prefix_len'],
968 icmpHash=self._values['dag_icmp_hash'],
969 )
970 result = self._filter_params(to_filter)
971 if result:
972 return result
973
974 @property
975 def lldp(self):
976 to_filter = dict(
977 enabled=self._values['lldp_enabled'],
978 disabled=self._values['lldp_disabled'],
979 maxNeighborsPerPort=self._values['lldp_max_neighbors_per_port'],
980 reinitDelay=self._values['lldp_reinit_delay'],
981 txDelay=self._values['lldp_tx_delay'],
982 txHold=self._values['lldp_tx_hold'],
983 txInterval=self._values['lldp_tx_interval'],
984 )
985 result = self._filter_params(to_filter)
986 if result:
987 return result
988
989 @property
990 def self_allow(self):
991 to_filter = dict(
992 defaults=self._values['self_allow_defaults'],
993 )
994 result = self._filter_params(to_filter)
995 if result:
996 return result
997
998
999 class ReportableChanges(Changes):
1000 @property
1001 def stp(self):
1002 if self._values['stp'] is None:
1003 return None
1004 to_filter = dict(
1005 config_name=self._values['stp'].get('configName', None),
1006 config_revision=self._values['stp'].get('configRevision', None),
1007 description=self._values['stp'].get('description', None),
1008 fwd_delay=self._values['stp'].get('fwdDelay', None),
1009 hello_time=self._values['stp'].get('helloTime', None),
1010 max_age=self._values['stp'].get('maxAge', None),
1011 max_hops=self._values['stp'].get('maxHops', None),
1012 mode=self._values['stp'].get('mode', None),
1013 transmit_hold=self._values['stp'].get('transmitHold', None),
1014 )
1015 result = self._filter_params(to_filter)
1016 if result:
1017 return result
1018
1019 @property
1020 def multicast(self):
1021 if self._values['multicast'] is None:
1022 return None
1023 to_filter = dict(
1024 max_pending_packets=self._values['multicast'].get('maxPendingPackets', None),
1025 max_pending_routes=self._values['multicast'].get('maxPendingRoutes', None),
1026 rate_limit=flatten_boolean(self._values['multicast'].get('rateLimit', None)),
1027 route_lookup_timeout=self._values['multicast'].get('routeLookupTimeout', None)
1028 )
1029 result = self._filter_params(to_filter)
1030 if result:
1031 return result
1032
1033 @property
1034 def dag(self):
1035 if self._values['dag'] is None:
1036 return None
1037 to_filter = dict(
1038 round_robin_mode=self._values['dag'].get('roundRobinMode', None),
1039 dag_ipv6_prefix_len=self._values['dag'].get('dagIpv6PrefixLen', None),
1040 icmp_hash=self._values['dag'].get('icmpHash', None),
1041 )
1042 result = self._filter_params(to_filter)
1043 if result:
1044 return result
1045
1046 @property
1047 def lldp(self):
1048 if self._values['lldp'] is None:
1049 return None
1050 to_filter = dict(
1051 enabled=self.enabled,
1052 max_neighbors_per_port=self._values['lldp'].get('maxNeighborsPerPort', None),
1053 reinit_delay=self._values['lldp'].get('reinitDelay', None),
1054 tx_delay=self._values['lldp'].get('txDelay', None),
1055 tx_hold=self._values['lldp'].get('txHold', None),
1056 tx_interval=self._values['lldp'].get('txInterval', None)
1057 )
1058 result = self._filter_params(to_filter)
1059 if result:
1060 return result
1061
1062 @property
1063 def enabled(self):
1064 enabled = self._values['lldp'].get('enabled', None)
1065 disabled = self._values['lldp'].get('disabled', None)
1066 if enabled:
1067 return 'yes'
1068 if disabled:
1069 return 'no'
1070
1071 @property
1072 def self_allow(self):
1073 if self._values['self_allow'] is None:
1074 return None
1075 to_filter = dict(
1076 defaults=self._parse_self_defaults(),
1077 all=self._get_all_value(),
1078 )
1079 result = self._filter_params(to_filter)
1080 if result:
1081 return result
1082
1083 def _parse_self_defaults(self):
1084 items = self._values['self_allow'].get('defaults')
1085 if isinstance(items, list):
1086 result = dict()
1087 for item in items:
1088 result['protocol'] = item.split(':')[0]
1089 result['port'] = item.split(':')[1]
1090 return result
1091
1092 def _get_all_value(self):
1093 items = self._values['self_allow'].get('defaults')
1094 if isinstance(items, string_types):
1095 if items == 'none':
1096 return 'no'
1097 if items == 'all':
1098 return 'yes'
1099
1100
1101 class Difference(object):
1102 def __init__(self, want, have=None):
1103 self.want = want
1104 self.have = have
1105
1106 def compare(self, param):
1107 try:
1108 result = getattr(self, param)
1109 return result
1110 except AttributeError:
1111 return self.__default(param)
1112
1113 def __default(self, param):
1114 attr1 = getattr(self.want, param)
1115 try:
1116 attr2 = getattr(self.have, param)
1117 if attr1 != attr2:
1118 return attr1
1119 except AttributeError:
1120 return attr1
1121
1122 @property
1123 def stp_config_name(self):
1124 result = cmp_str_with_none(self.want.stp_config_name, self.have.stp_config_name)
1125 return result
1126
1127 @property
1128 def stp_description(self):
1129 result = cmp_str_with_none(self.want.stp_description, self.have.stp_description)
1130 return result
1131
1132 @property
1133 def self_allow_defaults(self):
1134 if self.want.self_allow_defaults is None:
1135 return None
1136 if self.want.self_allow_defaults == 'none' and self.have.self_allow_defaults is None:
1137 return None
1138 if self.want.self_allow_defaults in ['all', 'none']:
1139 if isinstance(self.have.self_allow_defaults, string_types):
1140 if self.want.self_allow_defaults != self.have.self_allow_defaults:
1141 return self.want.self_allow_defaults
1142 else:
1143 return None
1144 if isinstance(self.have.self_allow_defaults, list):
1145 return self.want.self_allow_defaults
1146 result = cmp_simple_list(self.want.self_allow_defaults, self.have.self_allow_defaults)
1147 return result
1148
1149
1150 class ModuleManager(object):
1151 def __init__(self, *args, **kwargs):
1152 self.module = kwargs.get('module', None)
1153 self.client = F5RestClient(**self.module.params)
1154 self.want = ModuleParameters(params=self.module.params)
1155 self.have = ApiParameters()
1156 self.changes = UsableChanges()
1157
1158 def _update_changed_options(self):
1159 diff = Difference(self.want, self.have)
1160 updatables = Parameters.updatables
1161 changed = dict()
1162 for k in updatables:
1163 change = diff.compare(k)
1164 if change is None:
1165 continue
1166 else:
1167 if isinstance(change, dict):
1168 changed.update(change)
1169 else:
1170 changed[k] = change
1171 if changed:
1172 self.changes = UsableChanges(params=changed)
1173 return True
1174 return False
1175
1176 def _announce_deprecations(self, result):
1177 warnings = result.pop('__warnings', [])
1178 for warning in warnings:
1179 self.client.module.deprecate(
1180 msg=warning['msg'],
1181 version=warning['version']
1182 )
1183
1184 def exec_module(self):
1185 start = datetime.now().isoformat()
1186 version = tmos_version(self.client)
1187 result = dict()
1188
1189 changed = self.present()
1190
1191 reportable = ReportableChanges(params=self.changes.to_return())
1192 changes = reportable.to_return()
1193 result.update(**changes)
1194 result.update(dict(changed=changed))
1195 self._announce_deprecations(result)
1196 send_teem(start, self.client, self.module, version)
1197 return result
1198
1199 def present(self):
1200 return self.update()
1201
1202 def update(self):
1203 self.have = self.read_current_from_device()
1204 if not self.should_update():
1205 return False
1206 if self.module.check_mode:
1207 return True
1208 self.update_on_device()
1209 return True
1210
1211 def should_update(self):
1212 result = self._update_changed_options()
1213 if result:
1214 return True
1215 return False
1216
1217 def update_on_device(self):
1218 params = self.changes.to_return()
1219 if self.changes.stp:
1220 self.update_on_device_stp(params['stp'])
1221 if self.changes.multicast:
1222 self.update_on_device_mcast(params['multicast'])
1223 if self.changes.dag:
1224 self.update_on_device_dag(params['dag'])
1225 if self.changes.lldp:
1226 self.update_on_device_lldp(params['lldp'])
1227 if self.changes.self_allow:
1228 self.update_on_device_self(params['self_allow'])
1229
1230 def update_on_device_stp(self, params):
1231 uri = "https://{0}:{1}/mgmt/tm/net/stp-globals/".format(
1232 self.client.provider['server'],
1233 self.client.provider['server_port'],
1234
1235 )
1236 resp = self.client.api.patch(uri, json=params)
1237 try:
1238 response = resp.json()
1239 except ValueError as ex:
1240 raise F5ModuleError(str(ex))
1241
1242 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1243 return True
1244 raise F5ModuleError(resp.content)
1245
1246 def update_on_device_mcast(self, params):
1247 uri = "https://{0}:{1}/mgmt/tm/net/multicast-globals/".format(
1248 self.client.provider['server'],
1249 self.client.provider['server_port'],
1250
1251 )
1252 resp = self.client.api.patch(uri, json=params)
1253 try:
1254 response = resp.json()
1255 except ValueError as ex:
1256 raise F5ModuleError(str(ex))
1257
1258 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1259 return True
1260 raise F5ModuleError(resp.content)
1261
1262 def update_on_device_dag(self, params):
1263 uri = "https://{0}:{1}/mgmt/tm/net/dag-globals/".format(
1264 self.client.provider['server'],
1265 self.client.provider['server_port'],
1266
1267 )
1268 resp = self.client.api.patch(uri, json=params)
1269 try:
1270 response = resp.json()
1271 except ValueError as ex:
1272 raise F5ModuleError(str(ex))
1273
1274 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1275 return True
1276 raise F5ModuleError(resp.content)
1277
1278 def update_on_device_lldp(self, params):
1279 uri = "https://{0}:{1}/mgmt/tm/net/lldp-globals/".format(
1280 self.client.provider['server'],
1281 self.client.provider['server_port'],
1282
1283 )
1284 resp = self.client.api.patch(uri, json=params)
1285 try:
1286 response = resp.json()
1287 except ValueError as ex:
1288 raise F5ModuleError(str(ex))
1289
1290 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1291 return True
1292 raise F5ModuleError(resp.content)
1293
1294 def update_on_device_self(self, params):
1295 uri = "https://{0}:{1}/mgmt/tm/net/self-allow/".format(
1296 self.client.provider['server'],
1297 self.client.provider['server_port'],
1298
1299 )
1300 resp = self.client.api.patch(uri, json=params)
1301 try:
1302 response = resp.json()
1303 except ValueError as ex:
1304 raise F5ModuleError(str(ex))
1305
1306 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1307 return True
1308 raise F5ModuleError(resp.content)
1309
1310 def read_current_from_device(self):
1311 response = dict(
1312 stp=None,
1313 multicast=None,
1314 dag=None,
1315 lldp=None,
1316 self_allow=None,
1317 )
1318 if self.want.stp:
1319 response['stp'] = self.read_current_from_device_stp()
1320 if self.want.multicast:
1321 response['multicast'] = self.read_current_from_device_mcast()
1322 if self.want.dag:
1323 response['dag'] = self.read_current_from_device_dag()
1324 if self.want.lldp:
1325 response['lldp'] = self.read_current_from_device_lldp()
1326 if self.want.self_allow:
1327 response['self_allow'] = self.read_current_from_device_self()
1328 return ApiParameters(params=response)
1329
1330 def read_current_from_device_stp(self):
1331 uri = "https://{0}:{1}/mgmt/tm/net/stp-globals/".format(
1332 self.client.provider['server'],
1333 self.client.provider['server_port'],
1334 )
1335 resp = self.client.api.get(uri)
1336 try:
1337 response = resp.json()
1338 except ValueError as ex:
1339 raise F5ModuleError(str(ex))
1340
1341 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1342 return response
1343 raise F5ModuleError(resp.content)
1344
1345 def read_current_from_device_mcast(self):
1346 uri = "https://{0}:{1}/mgmt/tm/net/multicast-globals/".format(
1347 self.client.provider['server'],
1348 self.client.provider['server_port'],
1349 )
1350 resp = self.client.api.get(uri)
1351 try:
1352 response = resp.json()
1353 except ValueError as ex:
1354 raise F5ModuleError(str(ex))
1355
1356 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1357 return response
1358 raise F5ModuleError(resp.content)
1359
1360 def read_current_from_device_dag(self):
1361 uri = "https://{0}:{1}/mgmt/tm/net/dag-globals/".format(
1362 self.client.provider['server'],
1363 self.client.provider['server_port'],
1364 )
1365 resp = self.client.api.get(uri)
1366 try:
1367 response = resp.json()
1368 except ValueError as ex:
1369 raise F5ModuleError(str(ex))
1370
1371 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1372 return response
1373 raise F5ModuleError(resp.content)
1374
1375 def read_current_from_device_lldp(self):
1376 uri = "https://{0}:{1}/mgmt/tm/net/lldp-globals/".format(
1377 self.client.provider['server'],
1378 self.client.provider['server_port'],
1379 )
1380 resp = self.client.api.get(uri)
1381 try:
1382 response = resp.json()
1383 except ValueError as ex:
1384 raise F5ModuleError(str(ex))
1385
1386 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1387 return response
1388 raise F5ModuleError(resp.content)
1389
1390 def read_current_from_device_self(self):
1391 uri = "https://{0}:{1}/mgmt/tm/net/self-allow/".format(
1392 self.client.provider['server'],
1393 self.client.provider['server_port'],
1394 )
1395 resp = self.client.api.get(uri)
1396 try:
1397 response = resp.json()
1398 except ValueError as ex:
1399 raise F5ModuleError(str(ex))
1400
1401 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
1402 return response
1403 raise F5ModuleError(resp.content)
1404
1405
1406 class ArgumentSpec(object):
1407 def __init__(self):
1408 self.supports_check_mode = True
1409 argument_spec = dict(
1410 stp=dict(
1411 type='dict',
1412 options=dict(
1413 config_name=dict(),
1414 config_revision=dict(type='int'),
1415 description=dict(),
1416 fwd_delay=dict(type='int'),
1417 hello_time=dict(type='int'),
1418 max_age=dict(type='int'),
1419 max_hops=dict(type='int'),
1420 mode=dict(
1421 choices=['disabled', 'mstp', 'passthru', 'rstp', 'stp']
1422 ),
1423 transmit_hold=dict(type='int')
1424 )
1425 ),
1426 multicast=dict(
1427 type='dict',
1428 options=dict(
1429 max_pending_packets=dict(type='int'),
1430 max_pending_routes=dict(type='int'),
1431 rate_limit=dict(type='bool'),
1432 route_lookup_timeout=dict(type='int'),
1433 )
1434 ),
1435 dag=dict(
1436 type='dict',
1437 options=dict(
1438 dag_ipv6_prefix_len=dict(type='int'),
1439 icmp_hash=dict(
1440 choices=['icmp', 'ipicmp']
1441 ),
1442 round_robin_mode=dict(
1443 choices=['global', 'local']
1444 ),
1445 )
1446 ),
1447 lldp=dict(
1448 type='dict',
1449 options=dict(
1450 enabled=dict(type='bool'),
1451 max_neighbors_per_port=dict(type='int'),
1452 reinit_delay=dict(type='int'),
1453 tx_delay=dict(type='int'),
1454 tx_hold=dict(type='int'),
1455 tx_interval=dict(type='int')
1456 )
1457 ),
1458 self_allow=dict(
1459 type='dict',
1460 options=dict(
1461 defaults=dict(
1462 type='list',
1463 elements='dict',
1464 options=dict(
1465 protocol=dict(),
1466 port=dict(type='int'),
1467 ),
1468 required_together=[
1469 ['protocol', 'port']
1470 ]
1471 ),
1472 all=dict(type='bool'),
1473 ),
1474 mutually_exclusive=[
1475 ['defaults', 'all']
1476 ],
1477 required_one_of=[
1478 ['defaults', 'all']
1479 ],
1480 )
1481 )
1482 self.argument_spec = {}
1483 self.argument_spec.update(f5_argument_spec)
1484 self.argument_spec.update(argument_spec)
1485 self.required_one_of = [
1486 ['stp', 'multicast', 'dag', 'lldp', 'self_allow']
1487 ]
1488
1489
1490 def main():
1491 spec = ArgumentSpec()
1492
1493 module = AnsibleModule(
1494 argument_spec=spec.argument_spec,
1495 supports_check_mode=spec.supports_check_mode,
1496 required_one_of=spec.required_one_of
1497 )
1498
1499 try:
1500 mm = ModuleManager(module=module)
1501 results = mm.exec_module()
1502 module.exit_json(**results)
1503 except F5ModuleError as ex:
1504 module.fail_json(msg=str(ex))
1505
1506
1507 if __name__ == '__main__':
1508 main()