1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3# Copyright 2019 Red Hat
4# GNU General Public License v3.0+
5# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7#############################################
8#                WARNING                    #
9#############################################
10#
11# This file is auto generated by the resource
12#   module builder playbook.
13#
14# Do not edit this file manually.
15#
16# Changes to this file will be over written
17#   by the resource module builder.
18#
19# Changes should be made in the model used to
20#   generate this file or in the resource module
21#   builder template.
22#
23#############################################
24
25"""
26The module file for junos_lacp_interfaces
27"""
28
29from __future__ import absolute_import, division, print_function
30__metaclass__ = type
31
32ANSIBLE_METADATA = {
33    'metadata_version': '1.1',
34    'status': ['preview'],
35    'supported_by': 'network'
36}
37
38DOCUMENTATION = """
39---
40module: junos_lacp_interfaces
41version_added: 2.9
42short_description: Manage Link Aggregation Control Protocol (LACP) attributes of interfaces on Juniper JUNOS devices.
43description:
44  - This module manages Link Aggregation Control Protocol (LACP) attributes of interfaces on Juniper JUNOS devices.
45author: Ganesh Nalawade (@ganeshrn)
46options:
47  config:
48    description: The list of dictionaries of LACP interfaces options.
49    type: list
50    elements: dict
51    suboptions:
52      name:
53        description:
54          - Name Identifier of the interface or link aggregation group.
55        type: str
56      period:
57        description:
58          - Timer interval for periodic transmission of LACP packets. If the value is
59            set to C(fast) the packets are received every second and if the value is
60            C(slow) the packets are received every 30 seconds. This value is applicable
61            for aggregate interface only.
62        type: str
63        choices: ['fast', 'slow']
64      sync_reset:
65        description:
66          - The argument notifies minimum-link failure out of sync to peer. If the value
67            is C(disable) it disables minimum-link failure handling at LACP level and if
68            value is C(enable) it enables minimum-link failure handling at LACP level.
69            This value is applicable for aggregate interface only.
70        type: str
71        choices: ['disable', 'enable']
72      force_up:
73        description:
74          - This is a boolean argument to control if the port should be up in absence
75            of received link Aggregation Control Protocol Data Unit (LACPDUS).
76            This value is applicable for member interfaces only.
77        type: bool
78      port_priority:
79        description:
80          - Priority of the member port. This value is applicable for member interfaces only.
81          - Refer to vendor documentation for valid values.
82        type: int
83      system:
84        description:
85          - This dict object contains configurable options related to LACP
86            system parameters for the link aggregation group.
87            This value is applicable for aggregate interface only.
88        type: dict
89        suboptions:
90          priority:
91            description:
92              - Specifies the system priority to use in LACP negotiations for
93                the bundle.
94              - Refer to vendor documentation for valid values.
95            type: int
96          mac:
97            description:
98              - Specifies the system ID to use in LACP negotiations for
99                the bundle, encoded as a MAC address.
100            type: dict
101            suboptions:
102                address:
103                  description:
104                    - The system ID to use in LACP negotiations.
105                  type: str
106  state:
107    description:
108      - The state of the configuration after module completion.
109    type: str
110    choices:
111    - merged
112    - replaced
113    - overridden
114    - deleted
115    default: merged
116"""
117EXAMPLES = """
118# Using merged
119# Before state:
120# -------------
121# user@junos01# show interfaces
122# ge-0/0/2 {
123#     ether-options {
124#         802.3ad ae4;
125#     }
126# }
127# ge-0/0/3 {
128#    ether-options {
129#         802.3ad ae0;
130#     }
131# }
132# ae0 {
133#     description "lag interface merged";
134#     aggregated-ether-options {
135#         lacp {
136#             passive;
137#         }
138#     }
139# }
140# ae4 {
141#     description "test aggregate interface";
142#     aggregated-ether-options {
143#         lacp {
144#             passive;
145#             link-protection;
146#         }
147#     }
148# }
149
150- name: Merge provided configuration with device configuration
151  junos_lacp_interfaces:
152    config:
153      - name: ae0
154        period: fast
155        sync_reset: enable
156        system:
157          priority: 100
158          mac:
159            address: 00:00:00:00:00:02
160      - name: ge-0/0/3
161        port_priority: 100
162        force_up: True
163    state: merged
164
165# After state:
166# -------------
167# user@junos01# show interfaces
168# ge-0/0/2 {
169#     ether-options {
170#         802.3ad ae4;
171#     }
172# }
173# ge-0/0/3 {
174#     ether-options {
175#         802.3ad {
176#             lacp {
177#                 force-up;
178#                 port-priority 100;
179#             }
180#             ae0;
181#         }
182#     }
183# }
184# ae0 {
185#     description "lag interface merged";
186#     aggregated-ether-options {
187#         lacp {
188#             passive;
189#             periodic fast;
190#             sync-reset enable;
191#             system-priority 100;
192#             system-id 00:00:00:00:00:02;
193#         }
194#     }
195# }
196# ae4 {
197#     description "test aggregate interface";
198#     aggregated-ether-options {
199#         lacp {
200#             passive;
201#             link-protection;
202#         }
203#     }
204# }
205
206# Using replaced
207# Before state:
208# -------------
209# user@junos01# show interfaces
210# ge-0/0/2 {
211#     ether-options {
212#         802.3ad ae4;
213#     }
214# }
215# ge-0/0/3 {
216#     ether-options {
217#         802.3ad {
218#             lacp {
219#                 force-up;
220#                 port-priority 100;
221#             }
222#             ae0;
223#         }
224#     }
225# }
226# ae0 {
227#     description "lag interface merged";
228#     aggregated-ether-options {
229#         lacp {
230#             passive;
231#             periodic fast;
232#             sync-reset enable;
233#             system-priority 100;
234#             system-id 00:00:00:00:00:02;
235#         }
236#     }
237# }
238# ae4 {
239#     description "test aggregate interface";
240#     aggregated-ether-options {
241#         lacp {
242#             passive;
243#             link-protection;
244#         }
245#     }
246# }
247
248- name: Replace device LACP interfaces configuration with provided configuration
249  junos_lacp_interfaces:
250    config:
251      - name: ae0
252        period: slow
253    state: replaced
254
255# After state:
256# -------------
257# user@junos01# show interfaces
258# ge-0/0/2 {
259#     ether-options {
260#         802.3ad ae4;
261#     }
262# }
263# ge-0/0/3 {
264#     ether-options {
265#         802.3ad {
266#             lacp {
267#                 force-up;
268#                 port-priority 100;
269#             }
270#             ae0;
271#         }
272#     }
273# }
274# ae0 {
275#     description "lag interface merged";
276#     aggregated-ether-options {
277#         lacp {
278#             passive;
279#             periodic slow;
280#         }
281#     }
282# }
283# ae4 {
284#     description "test aggregate interface";
285#     aggregated-ether-options {
286#         lacp {
287#             passive;
288#             link-protection;
289#         }
290#     }
291# }
292
293# Using overridden
294# Before state:
295# -------------
296# user@junos01# show interfaces
297# ge-0/0/2 {
298#     ether-options {
299#         802.3ad ae4;
300#     }
301# }
302# ge-0/0/3 {
303#     ether-options {
304#         802.3ad {
305#             lacp {
306#                 force-up;
307#                 port-priority 100;
308#             }
309#             ae0;
310#         }
311#     }
312# }
313# ae0 {
314#     description "lag interface merged";
315#     aggregated-ether-options {
316#         lacp {
317#             passive;
318#             periodic slow;
319#         }
320#     }
321# }
322# ae4 {
323#     description "test aggregate interface";
324#     aggregated-ether-options {
325#         lacp {
326#             passive;
327#             link-protection;
328#         }
329#     }
330# }
331
332- name: Overrides all device LACP interfaces configuration with provided configuration
333  junos_lacp_interfaces:
334    config:
335      - name: ae0
336        system:
337          priority: 300
338          mac:
339            address: 00:00:00:00:00:03
340      - name: ge-0/0/2
341        port_priority: 200
342        force_up: False
343    state: overridden
344
345# After state:
346# -------------
347# user@junos01# show interfaces
348# ge-0/0/2 {
349#     ether-options {
350#         802.3ad {
351#             lacp {
352#                 port-priority 200;
353#             }
354#             ae4;
355#         }
356#     }
357# }
358# ge-0/0/3 {
359#     ether-options {
360#         802.3ad {
361#             lacp {
362#                 force-up;
363#                 port-priority 100;
364#             }
365#             ae0;
366#         }
367#     }
368# }
369# ae0 {
370#     description "lag interface merged";
371#     aggregated-ether-options {
372#         lacp {
373#             passive;
374#             system-priority 300;
375#             system-id 00:00:00:00:00:03;
376#         }
377#     }
378# }
379# ae4 {
380#     description "test aggregate interface";
381#     aggregated-ether-options {
382#         lacp {
383#             passive;
384#             link-protection;
385#         }
386#     }
387# }
388
389# Using deleted
390# Before state:
391# -------------
392# user@junos01# show interfaces
393# ge-0/0/2 {
394#     ether-options {
395#         802.3ad {
396#             lacp {
397#                 port-priority 200;
398#             }
399#             ae4;
400#         }
401#     }
402# }
403# ge-0/0/3 {
404#     ether-options {
405#         802.3ad {
406#             lacp {
407#                 force-up;
408#                 port-priority 100;
409#             }
410#             ae0;
411#         }
412#     }
413# }
414# ae0 {
415#     description "lag interface merged";
416#     aggregated-ether-options {
417#         lacp {
418#             passive;
419#             system-priority 300;
420#             system-id 00:00:00:00:00:03;
421#         }
422#     }
423# }
424# ae4 {
425#     description "test aggregate interface";
426#     aggregated-ether-options {
427#         lacp {
428#             passive;
429#             link-protection;
430#         }
431#     }
432# }
433
434- name: "Delete LACP interfaces attributes of given interfaces (Note: This won't delete the interface itself)"
435  junos_lacp_interfaces:
436    config:
437      - name: ae0
438      - name: ge-0/0/3
439      - name: ge-0/0/2
440    state: deleted
441
442# After state:
443# -------------
444# user@junos01# show interfaces
445# ge-0/0/2 {
446#     ether-options {
447#         802.3ad ae4;
448#     }
449# }
450# ge-0/0/3 {
451#    ether-options {
452#         802.3ad ae0;
453#     }
454# }
455# ae0 {
456#     description "lag interface merged";
457#     aggregated-ether-options {
458#         lacp {
459#             passive;
460#         }
461#     }
462# }
463# ae4 {
464#     description "test aggregate interface";
465#     aggregated-ether-options {
466#         lacp {
467#             passive;
468#             link-protection;
469#         }
470#     }
471# }
472"""
473
474RETURN = """
475before:
476  description: The configuration as structured data prior to module invocation.
477  returned: always
478  type: list
479  sample: >
480    The configuration returned will always be in the same format
481     of the parameters above.
482after:
483  description: The configuration as structured data after module completion.
484  returned: when changed
485  type: list
486  sample: >
487    The configuration returned will always be in the same format
488     of the parameters above.
489commands:
490  description: The set of commands pushed to the remote device.
491  returned: always
492  type: list
493  sample: ['command 1', 'command 2', 'command 3']
494"""
495
496
497from ansible.module_utils.basic import AnsibleModule
498from ansible.module_utils.network.junos.argspec.lacp_interfaces.lacp_interfaces import Lacp_interfacesArgs
499from ansible.module_utils.network.junos.config.lacp_interfaces.lacp_interfaces import Lacp_interfaces
500
501
502def main():
503    """
504    Main entry point for module execution
505    :returns: the result form module invocation
506    """
507    required_if = [('state', 'merged', ('config',)),
508                   ('state', 'replaced', ('config',)),
509                   ('state', 'overridden', ('config',))]
510
511    module = AnsibleModule(argument_spec=Lacp_interfacesArgs.argument_spec,
512                           required_if=required_if,
513                           supports_check_mode=True)
514
515    result = Lacp_interfaces(module).execute_module()
516    module.exit_json(**result)
517
518
519if __name__ == '__main__':
520    main()
521