| 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 iosxr_lacp |
| 27 |
""" |
| 28 |
|
| 29 |
from __future__ import absolute_import, division, print_function |
| 30 |
|
| 31 |
|
| 32 |
__metaclass__ = type |
| 33 |
|
| 34 |
|
| 35 |
DOCUMENTATION = """ |
| 36 |
module: iosxr_lacp |
| 37 |
short_description: Resource module to configure LACP. |
| 38 |
description: |
| 39 |
- This module manages Global Link Aggregation Control Protocol (LACP) on IOS-XR devices. |
| 40 |
version_added: 1.0.0 |
| 41 |
author: |
| 42 |
- Nilashish Chakraborty (@nilashishc) |
| 43 |
- Rohit Thakur (@rohitthakur2590) |
| 44 |
notes: |
| 45 |
- This module works with connection C(network_cli). See L(the IOS-XR Platform Options,../network/user_guide/platform_iosxr.html). |
| 46 |
options: |
| 47 |
config: |
| 48 |
description: The provided configurations. |
| 49 |
type: dict |
| 50 |
suboptions: |
| 51 |
system: |
| 52 |
description: This option sets the default system parameters for LACP bundles. |
| 53 |
type: dict |
| 54 |
suboptions: |
| 55 |
priority: |
| 56 |
description: |
| 57 |
- The system priority to use in LACP negotiations. |
| 58 |
- Lower value is higher priority. |
| 59 |
- Refer to vendor documentation for valid values. |
| 60 |
type: int |
| 61 |
mac: |
| 62 |
type: dict |
| 63 |
description: |
| 64 |
- The system MAC related configuration for LACP. |
| 65 |
suboptions: |
| 66 |
address: |
| 67 |
description: |
| 68 |
- The system ID to use in LACP negotiations. |
| 69 |
type: str |
| 70 |
running_config: |
| 71 |
description: |
| 72 |
- This option is used only with state I(parsed). |
| 73 |
- The value of this option should be the output received from the IOS-XR device |
| 74 |
by executing the command B(show running-config lacp). |
| 75 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 76 |
transforms it into Ansible structured data as per the resource module's argspec |
| 77 |
and the value is then returned in the I(parsed) key within the result. |
| 78 |
type: str |
| 79 |
state: |
| 80 |
description: |
| 81 |
- The state of the configuration after module completion. |
| 82 |
type: str |
| 83 |
choices: |
| 84 |
- merged |
| 85 |
- replaced |
| 86 |
- deleted |
| 87 |
- parsed |
| 88 |
- rendered |
| 89 |
- gathered |
| 90 |
- overridden |
| 91 |
default: merged |
| 92 |
""" |
| 93 |
EXAMPLES = """ |
| 94 |
# Using merged |
| 95 |
# |
| 96 |
# |
| 97 |
# ------------ |
| 98 |
# Before state |
| 99 |
# ------------ |
| 100 |
# |
| 101 |
# |
| 102 |
# RP/0/0/CPU0:iosxr01#show running-config lacp |
| 103 |
# Tue Jul 16 17:46:08.147 UTC |
| 104 |
# % No such configuration item(s) |
| 105 |
# |
| 106 |
# |
| 107 |
|
| 108 |
- name: Merge provided configuration with device configuration |
| 109 |
cisco.iosxr.iosxr_lacp: |
| 110 |
config: |
| 111 |
system: |
| 112 |
priority: 10 |
| 113 |
mac: |
| 114 |
address: 00c1.4c00.bd15 |
| 115 |
state: merged |
| 116 |
|
| 117 |
# |
| 118 |
# |
| 119 |
# ----------------------- |
| 120 |
# Module Execution Result |
| 121 |
# ----------------------- |
| 122 |
# |
| 123 |
# "before": {} |
| 124 |
# |
| 125 |
# |
| 126 |
# "commands": [ |
| 127 |
# "lacp system priority 10", |
| 128 |
# "lacp system mac 00c1.4c00.bd15" |
| 129 |
# ] |
| 130 |
# |
| 131 |
# |
| 132 |
# "after": { |
| 133 |
# "system": { |
| 134 |
# "mac": { |
| 135 |
# "address": "00c1.4c00.bd15" |
| 136 |
# }, |
| 137 |
# "priority": 10 |
| 138 |
# } |
| 139 |
# } |
| 140 |
# |
| 141 |
# ----------- |
| 142 |
# After state |
| 143 |
# ----------- |
| 144 |
# |
| 145 |
# |
| 146 |
# RP/0/0/CPU0:iosxr01#sh run lacp |
| 147 |
# Tue Jul 16 17:51:29.365 UTC |
| 148 |
# lacp system mac 00c1.4c00.bd15 |
| 149 |
# lacp system priority 10 |
| 150 |
# |
| 151 |
# |
| 152 |
|
| 153 |
# Using replaced |
| 154 |
# |
| 155 |
# |
| 156 |
# ------------- |
| 157 |
# Before state |
| 158 |
# ------------- |
| 159 |
# |
| 160 |
# |
| 161 |
# RP/0/0/CPU0:iosxr01#sh run lacp |
| 162 |
# Tue Jul 16 17:53:59.904 UTC |
| 163 |
# lacp system mac 00c1.4c00.bd15 |
| 164 |
# lacp system priority 10 |
| 165 |
# |
| 166 |
|
| 167 |
- name: Replace device global lacp configuration with the given configuration |
| 168 |
cisco.iosxr.iosxr_lacp: |
| 169 |
config: |
| 170 |
system: |
| 171 |
priority: 11 |
| 172 |
state: replaced |
| 173 |
# |
| 174 |
# |
| 175 |
# ----------------------- |
| 176 |
# Module Execution Result |
| 177 |
# ----------------------- |
| 178 |
# "before": { |
| 179 |
# "system": { |
| 180 |
# "mac": { |
| 181 |
# "address": "00c1.4c00.bd15" |
| 182 |
# }, |
| 183 |
# "priority": 10 |
| 184 |
# } |
| 185 |
# } |
| 186 |
# |
| 187 |
# |
| 188 |
# "commands": [ |
| 189 |
# "no lacp system mac", |
| 190 |
# "lacp system priority 11" |
| 191 |
# ] |
| 192 |
# |
| 193 |
# |
| 194 |
# "after": { |
| 195 |
# "system": { |
| 196 |
# "priority": 11 |
| 197 |
# } |
| 198 |
# } |
| 199 |
# |
| 200 |
# ----------- |
| 201 |
# After state |
| 202 |
# ----------- |
| 203 |
# |
| 204 |
# |
| 205 |
# RP/0/0/CPU0:iosxr01#sh run lacp |
| 206 |
# Tue Jul 16 18:02:40.379 UTC |
| 207 |
# lacp system priority 11 |
| 208 |
# |
| 209 |
# |
| 210 |
|
| 211 |
# Using deleted |
| 212 |
# |
| 213 |
# |
| 214 |
# ------------ |
| 215 |
# Before state |
| 216 |
# ------------ |
| 217 |
# |
| 218 |
# |
| 219 |
# RP/0/0/CPU0:iosxr01#sh run lacp |
| 220 |
# Tue Jul 16 18:37:09.727 UTC |
| 221 |
# lacp system mac 00c1.4c00.bd15 |
| 222 |
# lacp system priority 11 |
| 223 |
# |
| 224 |
# |
| 225 |
|
| 226 |
- name: Delete global LACP configurations from the device |
| 227 |
cisco.iosxr.iosxr_lacp: |
| 228 |
state: deleted |
| 229 |
|
| 230 |
# |
| 231 |
# |
| 232 |
# ----------------------- |
| 233 |
# Module Execution Result |
| 234 |
# ----------------------- |
| 235 |
# "before": { |
| 236 |
# "system": { |
| 237 |
# "mac": { |
| 238 |
# "address": "00c1.4c00.bd15" |
| 239 |
# }, |
| 240 |
# "priority": 11 |
| 241 |
# } |
| 242 |
# } |
| 243 |
# |
| 244 |
# |
| 245 |
# "commands": [ |
| 246 |
# "no lacp system mac", |
| 247 |
# "no lacp system priority" |
| 248 |
# ] |
| 249 |
# |
| 250 |
# |
| 251 |
# "after": {} |
| 252 |
# |
| 253 |
# ------------ |
| 254 |
# After state |
| 255 |
# ------------ |
| 256 |
# |
| 257 |
# |
| 258 |
# RP/0/0/CPU0:iosxr01#sh run lacp |
| 259 |
# Tue Jul 16 18:39:44.116 UTC |
| 260 |
# % No such configuration item(s) |
| 261 |
# |
| 262 |
# |
| 263 |
|
| 264 |
|
| 265 |
# Using parsed |
| 266 |
# parsed.cfg |
| 267 |
# ------------ |
| 268 |
# |
| 269 |
# lacp system mac 00c1.4c00.bd15 |
| 270 |
# lacp system priority 11 |
| 271 |
# - name: Convert LACP config to argspec without connecting to the appliance |
| 272 |
# cisco.iosxr.iosxr_lacp: |
| 273 |
# running_config: "{{ lookup('file', './parsed.cfg') }}" |
| 274 |
# state: parsed |
| 275 |
# Task Output (redacted) |
| 276 |
# ----------------------- |
| 277 |
# "parsed": { |
| 278 |
# "system": { |
| 279 |
# "mac": { |
| 280 |
# "address": "00c1.4c00.bd15" |
| 281 |
# }, |
| 282 |
# "priority": 11 |
| 283 |
# } |
| 284 |
# } |
| 285 |
|
| 286 |
|
| 287 |
# Using rendered |
| 288 |
- name: Render platform specific commands from task input using rendered state |
| 289 |
cisco.iosxr.iosxr_lacp: |
| 290 |
config: |
| 291 |
system: |
| 292 |
priority: 11 |
| 293 |
mac: |
| 294 |
address: 00c1.4c00.bd15 |
| 295 |
state: rendered |
| 296 |
# Task Output (redacted) |
| 297 |
# ----------------------- |
| 298 |
# "rendered": [ |
| 299 |
# "lacp system priority 11", |
| 300 |
# "lacp system mac 00c1.4c00.bd15" |
| 301 |
# ] |
| 302 |
|
| 303 |
|
| 304 |
# Using gathered |
| 305 |
# Before state: |
| 306 |
# ------------ |
| 307 |
# |
| 308 |
# RP/0/0/CPU0:an-iosxr-02#show running-config lacp |
| 309 |
# lacp system mac 00c1.4c00.bd15 |
| 310 |
# lacp system priority 11 |
| 311 |
- name: Gather IOSXR LACP configuration |
| 312 |
cisco.iosxr.iosxr_lacp: |
| 313 |
config: |
| 314 |
state: gathered |
| 315 |
# Task Output (redacted) |
| 316 |
# ----------------------- |
| 317 |
# |
| 318 |
# "gathered": { |
| 319 |
# "system": { |
| 320 |
# "mac": { |
| 321 |
# "address": "00c1.4c00.bd15" |
| 322 |
# }, |
| 323 |
# "priority": 11 |
| 324 |
# } |
| 325 |
# } |
| 326 |
# After state: |
| 327 |
# ------------ |
| 328 |
# |
| 329 |
# RP/0/0/CPU0:an-iosxr-02#show running-config lacp |
| 330 |
# lacp system mac 00c1.4c00.bd15 |
| 331 |
# lacp system priority |
| 332 |
""" |
| 333 |
RETURN = """ |
| 334 |
before: |
| 335 |
description: The configuration as structured data prior to module invocation. |
| 336 |
returned: always |
| 337 |
type: dict |
| 338 |
sample: > |
| 339 |
The configuration returned will always be in the same format |
| 340 |
of the parameters above. |
| 341 |
after: |
| 342 |
description: The configuration as structured data after module completion. |
| 343 |
returned: when changed |
| 344 |
type: dict |
| 345 |
sample: > |
| 346 |
The configuration returned will always be in the same format |
| 347 |
of the parameters above. |
| 348 |
commands: |
| 349 |
description: The set of commands pushed to the remote device. |
| 350 |
returned: always |
| 351 |
type: list |
| 352 |
sample: ['lacp system priority 10', 'lacp system mac 00c1.4c00.bd15'] |
| 353 |
""" |
| 354 |
|
| 355 |
|
| 356 |
from ansible.module_utils.basic import AnsibleModule |
| 357 |
|
| 358 |
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.lacp.lacp import ( |
| 359 |
LacpArgs, |
| 360 |
) |
| 361 |
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.lacp.lacp import Lacp |
| 362 |
|
| 363 |
|
| 364 |
def main(): |
| 365 |
""" |
| 366 |
Main entry point for module execution |
| 367 |
|
| 368 |
:returns: the result form module invocation |
| 369 |
""" |
| 370 |
required_if = [ |
| 371 |
("state", "merged", ("config",)), |
| 372 |
("state", "replaced", ("config",)), |
| 373 |
("state", "rendered", ("config",)), |
| 374 |
("state", "parsed", ("running_config",)), |
| 375 |
] |
| 376 |
|
| 377 |
mutually_exclusive = [("config", "running_config")] |
| 378 |
module = AnsibleModule( |
| 379 |
argument_spec=LacpArgs.argument_spec, |
| 380 |
required_if=required_if, |
| 381 |
supports_check_mode=True, |
| 382 |
mutually_exclusive=mutually_exclusive, |
| 383 |
) |
| 384 |
|
| 385 |
result = Lacp(module).execute_module() |
| 386 |
module.exit_json(**result) |
| 387 |
|
| 388 |
|
| 389 |
if __name__ == "__main__": |
| 390 |
main() |