Debian Codegraph @

ansible_collections/cisco/nxos/plugins/modules/nxos_lag_interfaces.py

raw
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 """
26 The module file for nxos_lag_interfaces
27 """
28
29 from __future__ import absolute_import, division, print_function
30
31
32 __metaclass__ = type
33
34
35 DOCUMENTATION = """
36 module: nxos_lag_interfaces
37 short_description: LAG interfaces resource module
38 description: This module manages attributes of link aggregation groups of NX-OS Interfaces.
39 version_added: 1.0.0
40 author:
41 - Trishna Guha (@trishnaguha)
42 - Nilashish Chakraborty (@NilashishC)
43 options:
44 running_config:
45 description:
46 - This option is used only with state I(parsed).
47 - The value of this option should be the output received from the NX-OS device
48 by executing the command B(show running-config | section ^interface).
49 - The state I(parsed) reads the configuration from C(running_config) option and
50 transforms it into Ansible structured data as per the resource module's argspec
51 and the value is then returned in the I(parsed) key within the result.
52 type: str
53 config:
54 description: A list of link aggregation group configurations.
55 type: list
56 elements: dict
57 suboptions:
58 name:
59 description:
60 - Name of the link aggregation group (LAG).
61 type: str
62 required: true
63 members:
64 description:
65 - The list of interfaces that are part of the group.
66 type: list
67 elements: dict
68 suboptions:
69 member:
70 description:
71 - The interface name.
72 type: str
73 mode:
74 description:
75 - Link aggregation group (LAG).
76 type: str
77 choices:
78 - 'active'
79 - 'on'
80 - 'passive'
81 force:
82 description:
83 - When true it forces link aggregation group members to match what is
84 declared in the members param. This can be used to remove members.
85 type: bool
86 state:
87 description:
88 - The state of the configuration after module completion.
89 type: str
90 choices:
91 - merged
92 - replaced
93 - overridden
94 - deleted
95 - gathered
96 - rendered
97 - parsed
98 default: merged
99 notes:
100 - Tested against NXOS 7.3.(0)D1(1) on VIRL.
101 - Unsupported for Cisco MDS
102 - This module works with connection C(network_cli).
103
104 """
105 EXAMPLES = """
106 # Using merged
107
108 # Before state:
109 # -------------
110 #
111 # interface Ethernet1/4
112
113 - name: Merge provided configuration with device configuration.
114 cisco.nxos.nxos_lag_interfaces:
115 config:
116 - name: port-channel99
117 members:
118 - member: Ethernet1/4
119 state: merged
120
121 # After state:
122 # ------------
123 #
124 # interface Ethernet1/4
125 # channel-group 99
126
127
128 # Using replaced
129
130 # Before state:
131 # -------------
132 #
133 # interface Ethernet1/4
134 # channel-group 99 mode active
135
136 - name: Replace device configuration of specified LAG attributes of given interfaces
137 with provided configuration.
138 cisco.nxos.nxos_lag_interfaces:
139 config:
140 - name: port-channel10
141 members:
142 - member: Ethernet1/4
143 state: replaced
144
145 # After state:
146 # ------------
147 #
148 # interface Ethernet1/4
149 # channel-group 10
150
151
152 # Using overridden
153
154 # Before state:
155 # -------------
156 #
157 # interface Ethernet1/4
158 # channel-group 10
159 # interface Ethernet1/2
160 # channel-group 99 mode passive
161
162 - name: Override device configuration of all LAG attributes of given interfaces on
163 device with provided configuration.
164 cisco.nxos.nxos_lag_interfaces:
165 config:
166 - name: port-channel20
167 members:
168 - member: Ethernet1/6
169 force: true
170 state: overridden
171
172 # After state:
173 # ------------
174 # interface Ethernet1/2
175 # interface Ethernet1/4
176 # interface Ethernet1/6
177 # channel-group 20 force
178
179
180 # Using deleted
181
182 # Before state:
183 # -------------
184 #
185 # interface Ethernet1/4
186 # channel-group 99 mode active
187
188 - name: Delete LAG attributes of given interface (This won't delete the port-channel
189 itself).
190 cisco.nxos.nxos_lag_interfaces:
191 config:
192 - port-channel: port-channel99
193 state: deleted
194
195 - name: Delete LAG attributes of all the interfaces
196 cisco.nxos.nxos_lag_interfaces:
197 state: deleted
198
199 # After state:
200 # ------------
201 #
202 # interface Ethernet1/4
203 # no channel-group 99
204
205 # Using rendered
206
207 - name: Use rendered state to convert task input to device specific commands
208 cisco.nxos.nxos_lag_interfaces:
209 config:
210 - name: port-channel10
211 members:
212 - member: Ethernet1/800
213 mode: active
214 - member: Ethernet1/801
215 - name: port-channel11
216 members:
217 - member: Ethernet1/802
218 mode: passive
219 state: rendered
220
221 # Task Output (redacted)
222 # -----------------------
223
224 # rendered:
225 # - "interface Ethernet1/800"
226 # - "channel-group 10 mode active"
227 # - "interface Ethernet1/801"
228 # - "channel-group 10"
229 # - "interface Ethernet1/802"
230 # - "channel-group 11 mode passive"
231
232 # Using parsed
233
234 # parsed.cfg
235 # ------------
236
237 # interface port-channel10
238 # interface port-channel11
239 # interface port-channel12
240 # interface Ethernet1/800
241 # channel-group 10 mode active
242 # interface Ethernet1/801
243 # channel-group 10 mode active
244 # interface Ethernet1/802
245 # channel-group 11 mode passive
246 # interface Ethernet1/803
247 # channel-group 11 mode passive
248
249 - name: Use parsed state to convert externally supplied config to structured format
250 cisco.nxos.nxos_lag_interfaces:
251 running_config: "{{ lookup('file', 'parsed.cfg') }}"
252 state: parsed
253
254 # Task output (redacted)
255 # -----------------------
256
257 # parsed:
258 # - members:
259 # - member: Ethernet1/800
260 # mode: active
261 # - member: Ethernet1/801
262 # mode: active
263 # name: port-channel10
264 #
265 # - members:
266 # - member: Ethernet1/802
267 # mode: passive
268 # - member: Ethernet1/803
269 # mode: passive
270 # name: port-channel11
271 #
272 # - name: port-channel12
273
274 # Using gathered
275
276 # Existing device config state
277 # -------------------------------
278 # interface port-channel10
279 # interface port-channel11
280 # interface Ethernet1/1
281 # channel-group 10 mode active
282 # interface Ethernet1/2
283 # channel-group 11 mode passive
284 #
285
286 - name: Gather lag_interfaces facts from the device using nxos_lag_interfaces
287 cisco.nxos.nxos_lag_interfaces:
288 state: gathered
289
290 # Task output (redacted)
291 # -----------------------
292 # gathered:
293 # - name: port-channel10
294 # members:
295 # - member: Ethernet1/1
296 # mode: active
297 # - name: port-channel11
298 # members:
299 # - member: Ethernet1/2
300 # mode: passive
301 """
302 RETURN = """
303 before:
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.
310 after:
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.
317 commands:
318 description: The set of commands pushed to the remote device.
319 returned: always
320 type: list
321 sample:
322 - "interface Ethernet1/800"
323 - "channel-group 10 mode active"
324 - "interface Ethernet1/801"
325 - "channel-group 10"
326 - "interface Ethernet1/802"
327 - "channel-group 11 mode passive"
328 """
329
330
331 from ansible.module_utils.basic import AnsibleModule
332
333 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.lag_interfaces.lag_interfaces import (
334 Lag_interfacesArgs,
335 )
336 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.lag_interfaces.lag_interfaces import (
337 Lag_interfaces,
338 )
339
340
341 def main():
342 """
343 Main entry point for module execution
344
345 :returns: the result form module invocation
346 """
347 required_if = [
348 ("state", "merged", ("config",)),
349 ("state", "replaced", ("config",)),
350 ("state", "overridden", ("config",)),
351 ("state", "rendered", ("config",)),
352 ("state", "parsed", ("running_config",)),
353 ]
354 mutually_exclusive = [("config", "running_config")]
355
356 module = AnsibleModule(
357 argument_spec=Lag_interfacesArgs.argument_spec,
358 required_if=required_if,
359 mutually_exclusive=mutually_exclusive,
360 supports_check_mode=True,
361 )
362
363 result = Lag_interfaces(module).execute_module()
364 module.exit_json(**result)
365
366
367 if __name__ == "__main__":
368 main()