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_lag_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_lag_interfaces
41version_added: 2.9
42short_description: Manage Link Aggregation on Juniper JUNOS devices.
43description: This module manages properties of Link Aggregation Group on Juniper JUNOS devices.
44author: Ganesh Nalawade (@ganeshrn)
45options:
46  config:
47    description: A list of link aggregation group configurations.
48    type: list
49    suboptions:
50      name:
51        description:
52        - Name of the link aggregation group (LAG).
53        type: str
54        required: True
55      mode:
56        description:
57          - LAG mode. A value of C(passive) will enable LACP in C(passive) mode that is it
58            will respond to LACP packets and C(active) configures the link to initiate
59            transmission of LACP packets.
60        choices: ['active', 'passive']
61      link_protection:
62        description:
63          - This boolean option indicates if link protection should be enabled for the LAG interface.
64            If value is C(True) link protection is enabled on LAG and if value is C(False) link protection
65            is disabled.
66        type: bool
67      members:
68        description:
69          - List of member interfaces of the link aggregation group. The value can be
70            single interface or list of interfaces.
71        type: list
72        suboptions:
73          member:
74            description:
75              - Name of the member interface.
76            type: str
77          link_type:
78            description:
79              - The value of this options configures the member link as either C(primary)
80                or C(backup). Value C(primary) configures primary interface for link-protection mode
81                and C(backup) configures backup interface for link-protection mode.
82            choices: ['primary', 'backup']
83  state:
84    description:
85    - The state of the configuration after module completion
86    type: str
87    choices:
88    - merged
89    - replaced
90    - overridden
91    - deleted
92    default: merged
93requirements:
94  - ncclient (>=v0.6.4)
95notes:
96  - This module requires the netconf system service be enabled on
97    the remote device being managed.
98  - Tested against vSRX JUNOS version 18.4R1.
99  - This module works with connection C(netconf). See L(the Junos OS Platform Options,../network/user_guide/platform_junos.html).
100"""
101EXAMPLES = """
102# Using merged
103
104# Before state:
105# -------------
106# user@junos01# show interfaces
107# ge-0/0/1 {
108#    description "Ansible configured interface 1";
109#    ether-options {
110#        802.3ad ae0;
111#    }
112# }
113# ge-0/0/2 {
114#    description "Ansible configured interface 2";
115#    ether-options {
116#        802.3ad ae0;
117#    }
118# }
119# ae0 {
120#     description "lag interface";
121# }
122# ae1 {
123#     description "lag interface 1";
124# }
125
126- name: "Delete LAG attributes of given interfaces (Note: This won't delete the interface itself)"
127  junos_lag_interfaces:
128    config:
129      - name: ae0
130      - name: ae1
131    state: deleted
132
133# After state:
134# -------------
135# user@junos01# show interfaces
136# ge-0/0/1 {
137#    description "Ansible configured interface 1";
138# }
139# ge-0/0/2 {
140#    description "Ansible configured interface 2";
141# }
142
143
144# Using merged
145
146# Before state:
147# -------------
148# user@junos01# show interfaces
149# ge-0/0/1 {
150#    description "Ansible configured interface 1";
151# }
152# ge-0/0/2 {
153#    description "Ansible configured interface 2";
154# }
155
156- name: Merge provided configuration with device configuration
157  junos_lag_interfaces:
158    config:
159      - name: ae0
160        members:
161          - member: ge-0/0/1
162            link_type: primary
163          - member: ge-0/0/2
164            link_type: backup
165    state: merged
166
167# After state:
168# -------------
169# user@junos01# show interfaces
170# ge-0/0/1 {
171#    description "Ansible configured interface 1";
172#    ether-options {
173#        802.3ad {
174#            ae0;
175#            primary;
176#        }
177#    }
178# }
179# ge-0/0/2 {
180#    description "Ansible configured interface 2";
181#    ether-options {
182#        802.3ad {
183#            ae0;
184#            backup;
185#        }
186#    }
187# }
188
189
190# Using merged
191
192# Before state:
193# -------------
194# user@junos01# show interfaces
195# ge-0/0/1 {
196#    description "Ansible configured interface 1";
197#    ether-options {
198#        802.3ad ae0;
199#    }
200# }
201# ge-0/0/2 {
202#    description "Ansible configured interface 2";
203#    ether-options {
204#        802.3ad ae0;
205#    }
206# }
207# ae0 {
208#     description "lag interface";
209# }
210# ae3 {
211#     description "lag interface 3";
212# }
213
214- name: Overrides all device LAG configuration with provided configuration
215  junos_lag_interfaces:
216    config:
217      - name: ae0
218        members:
219          - member: ge-0/0/2
220      - name: ae1
221        members:
222          - member: ge-0/0/1
223        mode: passive
224    state: overridden
225
226# After state:
227# -------------
228# user@junos01# show interfaces
229# ge-0/0/1 {
230#    description "Ansible configured interface 1";
231#    ether-options {
232#        802.3ad ae1;
233#    }
234# }
235# ge-0/0/2 {
236#    description "Ansible configured interface 2";
237#    ether-options {
238#        802.3ad ae0;
239#    }
240# }
241# ae0 {
242#     description "lag interface";
243# }
244# ae1 {
245#    aggregated-ether-options {
246#        lacp {
247#            active;
248#        }
249#    }
250# }
251
252
253# Using merged
254
255# Before state:
256# -------------
257# user@junos01# show interfaces
258# ge-0/0/1 {
259#    description "Ansible configured interface 1";
260# }
261# ge-0/0/2 {
262#    description "Ansible configured interface 2";
263# }
264# ge-0/0/3 {
265#    description "Ansible configured interface 3";
266# }
267
268- name: Replace device LAG configuration with provided configuration
269  junos_lag_interfaces:
270    config:
271      - name: ae0
272        members:
273          - member: ge-0/0/1
274        mode: active
275    state: replaced
276
277# After state:
278# -------------
279# user@junos01# show interfaces
280# ge-0/0/1 {
281#    description "Ansible configured interface 1";
282#    ether-options {
283#        802.3ad ae0;
284#    }
285# }
286# ge-0/0/2 {
287#    description "Ansible configured interface 2";
288# }
289# ae0 {
290#    aggregated-ether-options {
291#        lacp {
292#            active;
293#        }
294#    }
295# }
296# ge-0/0/3 {
297#    description "Ansible configured interface 3";
298# }
299
300
301"""
302RETURN = """
303before:
304  description: The configuration as structured data prior to module invocation.
305  returned: always
306  type: list
307  sample: >
308    The configuration returned will always be in the same format
309     of the parameters above.
310after:
311  description: The configuration as structured data after module completion.
312  returned: when changed
313  type: list
314  sample: >
315    The configuration returned will always be in the same format
316     of the parameters above.
317xml:
318  description: The set of xml rpc payload pushed to the remote device.
319  returned: always
320  type: list
321  sample: ['xml 1', 'xml 2', 'xml 3']
322"""
323
324
325from ansible.module_utils.basic import AnsibleModule
326from ansible.module_utils.network.junos.argspec.lag_interfaces.lag_interfaces import Lag_interfacesArgs
327from ansible.module_utils.network.junos.config.lag_interfaces.lag_interfaces import Lag_interfaces
328
329
330def main():
331    """
332    Main entry point for module execution
333
334    :returns: the result form module invocation
335    """
336    required_if = [('state', 'merged', ('config',)),
337                   ('state', 'replaced', ('config',)),
338                   ('state', 'overridden', ('config',))]
339
340    module = AnsibleModule(argument_spec=Lag_interfacesArgs.argument_spec,
341                           required_if=required_if,
342                           supports_check_mode=True)
343
344    result = Lag_interfaces(module).execute_module()
345    module.exit_json(**result)
346
347
348if __name__ == '__main__':
349    main()
350