Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2023 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 The module file for nxos_fc_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 ---
18 module: nxos_fc_interfaces
19 short_description: Fc Interfaces resource module
20 description: This module manages the interface attributes of NX-OS fc interfaces.
21 version_added: 5.2.0
22 author: Suhas Bharadwaj (@srbharadwaj)
23 notes:
24 - Tested against NXOS 9.3(2) on Cisco MDS Switches
25 options:
26 running_config:
27 description:
28 - This option is used only with state I(parsed).
29 - The value of this option should be the output received from the NX-OS
30 device by executing the command B(show running-config interface)
31 - The state I(parsed) reads the configuration from C(running_config)
32 option and transforms it into Ansible structured data as per the
33 resource module's argspec and the value is then returned in the
34 I(parsed) key within the result.
35 type: str
36 config:
37 description: A dictionary of interface options
38 type: list
39 elements: dict
40 suboptions:
41 name:
42 description:
43 - Full name of interface, e.g. fc1/1, fc18/48
44 type: str
45 required: true
46 description:
47 description:
48 - Interface description.
49 type: str
50 enabled:
51 description:
52 - Administrative state of the interface. Set the value to C(true) to
53 administratively enable the interface or C(true) to disable it
54 type: bool
55 speed:
56 description:
57 - Interface link speed.
58 choices:
59 - 'auto'
60 - '1000'
61 - '2000'
62 - '4000'
63 - '8000'
64 - '10000'
65 - '16000'
66 - '32000'
67 - '64000'
68 - 'auto max 2000'
69 - 'auto max 4000'
70 - 'auto max 8000'
71 - 'auto max 16000'
72 - 'auto max 32000'
73 - 'auto max 64000'
74 type: str
75 mode:
76 description:
77 - Port mode of the fc interface
78 choices:
79 - 'auto'
80 - 'E'
81 - 'F'
82 - 'Fx'
83 - 'NP'
84 - 'SD'
85 type: str
86 trunk_mode:
87 description:
88 - Trunk mode of the fc interface
89 choices:
90 - 'auto'
91 - 'on'
92 - 'off'
93 type: str
94 analytics:
95 description:
96 - Analytics type on the fc interface
97 choices:
98 - 'fc-scsi'
99 - 'fc-nvme'
100 - 'fc-all'
101 type: str
102 state:
103 description:
104 - The state of the configuration after module completion
105 type: str
106 choices:
107 - merged
108 - replaced
109 - overridden
110 - deleted
111 - gathered
112 - rendered
113 - parsed
114 default: merged
115 """
116 EXAMPLES = """
117 # Using merged
118
119 # Before state:
120 # -------------
121 #
122 # switch# show running-config interface all
123 # interface fc18/10
124 # analytics type fc-nvme
125 # switchport speed auto max 16000
126 # switchport mode auto
127 # switchport description $
128 # switchport trunk mode on
129 # shutdown
130
131 - name: Merge provided configuration with device configuration
132 cisco.nxos.nxos_fc_interfaces:
133 config:
134 - name: fc18/10
135 analytics: fc-scsi
136 state: merged
137
138 # Task Output
139 # -----------
140 #
141 # before:
142 # - name: fc18/10
143 # speed: auto max 16000
144 # mode: auto
145 # trunk_mode: on
146 # enabled: true
147 # description: $
148 # analytics: fc-nvme
149 # commands:
150 # - interface fc18/10
151 # - analytics type fc-scsi
152 # after:
153 # - name: fc18/10
154 # speed: auto max 16000
155 # mode: auto
156 # trunk_mode: on
157 # enabled: true
158 # description: $
159 # analytics: fc-all
160
161 # After state:
162 # ------------
163 #
164 # switch# show running-config interface all
165 # interface fc18/10
166 # analytics type fc-scsi
167 # analytics type fc-nvme
168 # switchport speed auto max 16000
169 # switchport mode auto
170 # switchport description $
171 # switchport trunk mode on
172 # shutdown
173
174 # Using replaced
175
176 # Before state:
177 # -------------
178 #
179 # switch# show running-config interface all
180 # interface fc18/12
181 # analytics type fc-scsi
182 # analytics type fc-nvme
183 # switchport speed auto max 64000
184 # switchport mode auto
185 # switchport description 1
186 # switchport trunk mode on
187 # no shutdown
188
189 - name: Replaces device configuration of listed interfaces with provided configuration
190 cisco.nxos.nxos_fc_interfaces:
191 config:
192 - name: fc18/12
193 speed: auto max 64000
194 mode: auto
195 trunk_mode: "on"
196 enabled: true
197 description: 1
198 analytics: fc-scsi
199 state: replaced
200
201 # Task Output
202 # -----------
203 #
204 # before:
205 # - name: fc18/12
206 # speed: auto max 64000
207 # mode: auto
208 # trunk_mode: on
209 # enabled: true
210 # description: 1
211 # analytics: fc-all
212 # commands:
213 # - interface fc18/12
214 # - no analytics type fc-all
215 # - analytics type fc-scsi
216 # after:
217 # - name: fc18/12
218 # speed: auto max 64000
219 # mode: auto
220 # trunk_mode: on
221 # enabled: true
222 # description: 1
223 # analytics: fc-scsi
224
225 # After state:
226 # ------------
227 #
228 # switch# show running-config interface all
229 # interface fc18/12
230 # analytics type fc-scsi
231 # switchport speed auto max 64000
232 # switchport mode auto
233 # switchport description 1
234 # switchport trunk mode on
235 # no shutdown
236
237
238 # Using deleted
239
240 # Before state:
241 # -------------
242 #
243 # switch# show running-config interface all
244 # interface fc1/2
245 # switchport speed 1000
246 # switchport mode E
247 # no switchport description
248 # switchport trunk mode off
249 # no shutdown
250
251 - name: Delete or return interface parameters to default settings
252 cisco.nxos.nxos_fc_interfaces:
253 config:
254 - name: fc1/2
255 state: deleted
256
257 # Task Output
258 # -----------
259 #
260 # before:
261 # - name: fc1/2
262 # speed: 1000
263 # mode: E
264 # trunk_mode: off
265 # enabled: true
266 # commands:
267 # - interface fc1/2
268 # - no switchport speed 1000
269 # - no switchport mode E
270 # - switchport trunk mode on
271 # - shutdown
272 # after:
273 # - name: fc1/2
274 # speed: auto
275 # mode: auto
276 # trunk_mode: on
277 # enabled: true
278
279 # After state:
280 # ------------
281 #
282 # switch# show running-config interface all
283 # interface fc1/2
284 # switchport speed auto
285 # switchport mode auto
286 # no switchport description
287 # switchport trunk mode on
288 # shutdown
289
290 # Using overridden
291
292 # Before state:
293 # -------------
294 #
295 # switch# show running-config interface all
296 # interface fc18/12
297 # analytics type fc-scsi
298 # analytics type fc-nvme
299 # switchport speed auto max 64000
300 # switchport mode auto
301 # switchport description 1
302 # switchport trunk mode on
303 # no shutdown
304 # interface fc18/13
305 # analytics type fc-scsi
306 # analytics type fc-nvme
307 # switchport speed auto max 64000
308 # switchport mode auto
309 # switchport description 1
310 # switchport trunk mode on
311 # no shutdown
312
313 - name: Replaces device configuration of listed interfaces with provided configuration
314 cisco.nxos.nxos_fc_interfaces:
315 config:
316 - name: fc18/12
317 speed: auto max 64000
318 mode: auto
319 trunk_mode: "on"
320 enabled: true
321 description: 1
322 analytics: fc-scsi
323 state: overridden
324
325 # Task Output
326 # -----------
327 #
328 # before:
329 # - name: fc18/12
330 # speed: auto max 64000
331 # mode: auto
332 # trunk_mode: on
333 # enabled: true
334 # description: 1
335 # analytics: fc-all
336 # - name: fc18/13
337 # speed: auto max 64000
338 # mode: auto
339 # trunk_mode: on
340 # enabled: true
341 # description: 1
342 # analytics: fc-all
343 # commands:
344 # - interface fc18/12
345 # no analytics type fc-all
346 # analytics type fc-scsi
347 # - interface fc18/13
348 # no switchport description
349 # no switchport speed auto max 64000
350 # no switchport mode auto
351 # switchport trunk mode on
352 # shutdown
353 # after:
354 # - name: fc18/12
355 # speed: auto max 64000
356 # mode: auto
357 # trunk_mode: on
358 # enabled: true
359 # description: 1
360 # analytics: fc-scsi
361 # - name: fc18/13
362 # speed: auto max 64000
363 # mode: auto
364 # trunk_mode: on
365 # enabled: true
366
367 # After state:
368 # ------------
369 #
370 # switch# show running-config interface all
371 # interface fc18/12
372 # analytics type fc-scsi
373 # switchport speed auto max 64000
374 # switchport mode auto
375 # switchport description 1
376 # switchport trunk mode on
377 # no shutdown
378 # interface fc18/13
379 # switchport mode auto
380 # switchport trunk mode on
381 # shutdown
382
383 # Using rendered
384
385 - name: Use rendered state to convert task input to device specific commands
386 cisco.nxos.nxos_fc_interfaces:
387 config:
388 - name: fc1/1
389 speed: auto
390 mode: auto
391 trunk_mode: "on"
392 enabled: true
393 description: This is a sample line
394 - name: fc1/2
395 speed: 1000
396 mode: E
397 trunk_mode: "off"
398 enabled: true
399 state: rendered
400
401 # Task Output
402 # -----------
403 #
404 # rendered:
405 # interface fc1/1
406 # switchport speed auto
407 # switchport mode auto
408 # switchport description This is a sample line
409 # switchport trunk mode on
410 # no shutdown
411 #
412 # interface fc1/2
413 # switchport speed 1000
414 # switchport mode E
415 # no switchport description
416 # switchport trunk mode off
417 # no shutdown
418
419 # Using parsed
420
421 # parsed.cfg
422 # ------------
423 #
424 # interface fc1/1
425 # switchport speed auto
426 # switchport mode auto
427 # switchport description This is a sample line
428 # switchport trunk mode on
429 # no shutdown
430 #
431 # interface fc1/2
432 # switchport speed 1000
433 # switchport mode E
434 # no switchport description
435 # switchport trunk mode off
436 # no shutdown
437
438 - name: Use parsed state to convert externally supplied config to structured format
439 cisco.nxos.nxos_fc_interfaces:
440 running_config: "{{ lookup('file', 'parsed.cfg') }}"
441 state: parsed
442
443 # Task output
444 # -----------
445 #
446 # parsed:
447 # - name: fc1/1
448 # speed: auto
449 # mode: auto
450 # trunk_mode: on
451 # enabled: true
452 # description: This is a sample line
453 # - name: fc1/2
454 # speed: 1000
455 # mode: E
456 # trunk_mode: off
457 # enabled: true
458
459 # Using gathered
460
461 # Before state:
462 # -------------
463 #
464 # switch# show running-config | section interface
465 # interface fc1/1
466 # switchport speed auto
467 # switchport mode auto
468 # switchport description This is a sample line
469 # switchport trunk mode on
470 # no shutdown
471 #
472 # interface fc1/2
473 # switchport speed 1000
474 # switchport mode E
475 # no switchport description
476 # switchport trunk mode off
477 # no shutdown
478 #
479 - name: Gather interfaces facts from the device using nxos_fc_interfaces
480 cisco.nxos.nxos_fc_interfaces:
481 state: gathered
482 #
483 # Task output
484 # -----------
485 #
486 # - name: fc1/1
487 # speed: auto
488 # mode: auto
489 # trunk_mode: on
490 # enabled: true
491 # description: This is a sample line
492 # - name: fc1/2
493 # speed: 1000
494 # mode: E
495 # trunk_mode: off
496 # enabled: true
497 """
498
499 RETURN = """
500 before:
501 description: The configuration prior to the module execution.
502 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
503 type: dict
504 sample: >
505 This output will always be in the same format as the
506 module argspec.
507 after:
508 description: The resulting configuration after module execution.
509 returned: when changed
510 type: dict
511 sample: >
512 This output will always be in the same format as the
513 module argspec.
514 commands:
515 description: The set of commands pushed to the remote device.
516 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
517 type: list
518 sample:
519 - interface fc1/1
520 - description sample description
521 - shutdown
522 rendered:
523 description: The provided configuration in the task rendered in device-native format (offline).
524 returned: when I(state) is C(rendered)
525 type: list
526 sample:
527 - interface fc1/1
528 - description sample description
529 - shutdown
530 gathered:
531 description: Facts about the network resource gathered from the remote device as structured data.
532 returned: when I(state) is C(gathered)
533 type: list
534 sample: >
535 This output will always be in the same format as the
536 module argspec.
537 parsed:
538 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
539 returned: when I(state) is C(parsed)
540 type: list
541 sample: >
542 This output will always be in the same format as the
543 module argspec.
544 """
545
546 from ansible.module_utils.basic import AnsibleModule
547
548 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.fc_interfaces.fc_interfaces import (
549 Fc_interfacesArgs,
550 )
551 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.fc_interfaces.fc_interfaces import (
552 Fc_interfaces,
553 )
554
555
556 def main():
557 """
558 Main entry point for module execution
559
560 :returns: the result form module invocation
561 """
562 module = AnsibleModule(
563 argument_spec=Fc_interfacesArgs.argument_spec,
564 mutually_exclusive=[["config", "running_config"]],
565 required_if=[
566 ["state", "merged", ["config"]],
567 ["state", "replaced", ["config"]],
568 ["state", "overridden", ["config"]],
569 ["state", "rendered", ["config"]],
570 ["state", "parsed", ["running_config"]],
571 ],
572 supports_check_mode=True,
573 )
574
575 result = Fc_interfaces(module).execute_module()
576 module.exit_json(**result)
577
578
579 if __name__ == "__main__":
580 main()