| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2025, Akini Ross (@akinross) <[email protected]> |
| 5 |
|
| 6 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
|
| 9 |
from __future__ import absolute_import, division, print_function |
| 10 |
|
| 11 |
__metaclass__ = type |
| 12 |
|
| 13 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} |
| 14 |
|
| 15 |
DOCUMENTATION = r""" |
| 16 |
--- |
| 17 |
module: ndo_l3out_svi_interface |
| 18 |
version_added: "2.12.0" |
| 19 |
short_description: Manage L3Out SVI Interfaces on Cisco Nexus Dashboard Orchestrator (NDO). |
| 20 |
description: |
| 21 |
- Manage L3Out SVI Interfaces on Cisco Nexus Dashboard Orchestrator (NDO). |
| 22 |
- This module is only supported on ND v3.1 (NDO v4.3) and later. |
| 23 |
author: |
| 24 |
- Akini Ross (@akinross) |
| 25 |
options: |
| 26 |
template: |
| 27 |
description: |
| 28 |
- The name of the template. |
| 29 |
- The template must be an L3Out template. |
| 30 |
- This parameter or O(template_id) is required. |
| 31 |
type: str |
| 32 |
aliases: [ l3out_template ] |
| 33 |
template_id: |
| 34 |
description: |
| 35 |
- The ID of the L3Out template. |
| 36 |
- This parameter or O(template) is required. |
| 37 |
type: str |
| 38 |
aliases: [ l3out_template_id ] |
| 39 |
l3out: |
| 40 |
description: |
| 41 |
- The name of the L3Out. |
| 42 |
- This parameter or O(l3out_uuid) is required. |
| 43 |
type: str |
| 44 |
aliases: [ l3out_name ] |
| 45 |
l3out_uuid: |
| 46 |
description: |
| 47 |
- The UUID of the L3Out. |
| 48 |
- This parameter or O(l3out) is required. |
| 49 |
type: str |
| 50 |
node_id: |
| 51 |
description: |
| 52 |
- The ID of the node (border leaf switch) where to deploy the L3Out routing protocol and node-level protocol configurations. |
| 53 |
- This parameter is required when O(path) is specified. |
| 54 |
- This parameter is required when the node configuration does not exist under the L3Out template. |
| 55 |
- When specified, the node configuration is created under the L3Out template when it does not exist. |
| 56 |
- When specified, the node configuration is updated under the L3Out template when it already exists. |
| 57 |
- When specified, the node configuration is deleted under the L3Out template when there are no interfaces referencing it. |
| 58 |
type: str |
| 59 |
aliases: [ node, border_leaf ] |
| 60 |
node_router_id: |
| 61 |
description: |
| 62 |
- The router ID of the node. |
| 63 |
- This parameter is required when the node configuration does not exist under the L3Out template. |
| 64 |
- For O(virtual_port_channel) interfaces, this is the router ID of the Side A node. |
| 65 |
type: str |
| 66 |
aliases: [ router_id ] |
| 67 |
node_group_policy: |
| 68 |
description: |
| 69 |
- The name of the node group policy. |
| 70 |
- For O(virtual_port_channel) interfaces, this is the node group policy of the Side A node. |
| 71 |
type: str |
| 72 |
use_router_id_as_loopback: |
| 73 |
description: |
| 74 |
- Whether to use the router ID as the loopback address of the node. |
| 75 |
- For O(virtual_port_channel) interfaces, this applies to the Side A node. |
| 76 |
type: bool |
| 77 |
node_loopback_ip: |
| 78 |
description: |
| 79 |
- The loopback IP address of the node. |
| 80 |
- For O(virtual_port_channel) interfaces, this is the loopback IP address of the Side A node. |
| 81 |
type: str |
| 82 |
aliases: [ loopback_ip ] |
| 83 |
path: |
| 84 |
description: |
| 85 |
- The path of the interface. |
| 86 |
- The path must be an existing physical port (eg. eth1/1). |
| 87 |
type: str |
| 88 |
aliases: [ interface ] |
| 89 |
port_channel: |
| 90 |
description: |
| 91 |
- The port channel details. |
| 92 |
type: dict |
| 93 |
aliases: [ pc ] |
| 94 |
suboptions: |
| 95 |
uuid: |
| 96 |
description: |
| 97 |
- The UUID of the port channel. |
| 98 |
- This parameter or O(port_channel.reference) is required. |
| 99 |
type: str |
| 100 |
reference: |
| 101 |
description: |
| 102 |
- The reference details of the port channel. |
| 103 |
- This parameter or O(port_channel.uuid) is required. |
| 104 |
type: dict |
| 105 |
aliases: [ ref ] |
| 106 |
suboptions: |
| 107 |
name: |
| 108 |
description: |
| 109 |
- The name of the port channel. |
| 110 |
type: str |
| 111 |
required: true |
| 112 |
template: |
| 113 |
description: |
| 114 |
- The name of the template that contains the port channel. |
| 115 |
- This parameter or O(port_channel.reference.template_id) is required. |
| 116 |
type: str |
| 117 |
template_id: |
| 118 |
description: |
| 119 |
- The ID of the template that contains the port channel. |
| 120 |
- This parameter or O(port_channel.reference.template) is required. |
| 121 |
type: str |
| 122 |
virtual_port_channel: |
| 123 |
description: |
| 124 |
- The virtual port channel details. |
| 125 |
type: dict |
| 126 |
aliases: [ vpc ] |
| 127 |
suboptions: |
| 128 |
uuid: |
| 129 |
description: |
| 130 |
- The UUID of the virtual port channel. |
| 131 |
- This parameter or O(virtual_port_channel.reference) is required. |
| 132 |
type: str |
| 133 |
reference: |
| 134 |
description: |
| 135 |
- The reference details of the virtual port channel. |
| 136 |
- This parameter or O(virtual_port_channel.uuid) is required. |
| 137 |
type: dict |
| 138 |
aliases: [ ref ] |
| 139 |
suboptions: |
| 140 |
name: |
| 141 |
description: |
| 142 |
- The name of the virtual port channel. |
| 143 |
type: str |
| 144 |
required: true |
| 145 |
template: |
| 146 |
description: |
| 147 |
- The name of the template that contains the virtual port channel. |
| 148 |
- This parameter or O(virtual_port_channel.reference.template_id) is required. |
| 149 |
type: str |
| 150 |
template_id: |
| 151 |
description: |
| 152 |
- The ID of the template that contains the virtual port channel. |
| 153 |
- This parameter or O(virtual_port_channel.reference.template) is required. |
| 154 |
type: str |
| 155 |
side_b_ipv4_address: |
| 156 |
description: |
| 157 |
- The Side B IPv4 address of the interface. |
| 158 |
type: str |
| 159 |
side_b_ipv6_address: |
| 160 |
description: |
| 161 |
- The Side B IPv6 address of the interface. |
| 162 |
type: str |
| 163 |
side_b_ipv6_link_local_address: |
| 164 |
description: |
| 165 |
- The Side B IPv6 link-local address of the interface. |
| 166 |
type: str |
| 167 |
side_b_ipv6_dad: |
| 168 |
description: |
| 169 |
- Whether to enable IPv6 Duplicate Address Detection (DAD) on the Side B interface. |
| 170 |
- If this parameter is unspecified, NDO defaults to O(ipv6_dad=enabled). |
| 171 |
type: str |
| 172 |
choices: [ enabled, disabled ] |
| 173 |
side_b_node_router_id: |
| 174 |
description: |
| 175 |
- The router ID of the Side B node. |
| 176 |
- This parameter is required when the node configuration does not exist under the L3Out template. |
| 177 |
type: str |
| 178 |
aliases: [ router_id ] |
| 179 |
side_b_node_group_policy: |
| 180 |
description: |
| 181 |
- The name of the Side B node group policy. |
| 182 |
type: str |
| 183 |
side_b_use_router_id_as_loopback: |
| 184 |
description: |
| 185 |
- Whether to use the router ID as the loopback address of the Side B node. |
| 186 |
type: bool |
| 187 |
side_b_node_loopback_ip: |
| 188 |
description: |
| 189 |
- The loopback IP address of the Side B node. |
| 190 |
type: str |
| 191 |
aliases: [ loopback_ip ] |
| 192 |
interface_group_policy: |
| 193 |
description: |
| 194 |
- The name of the interface group policy. |
| 195 |
type: str |
| 196 |
ipv4_address: |
| 197 |
description: |
| 198 |
- The IPv4 address of the interface. |
| 199 |
- For O(virtual_port_channel) interfaces, this is the Side A IPv4 address. |
| 200 |
type: str |
| 201 |
ipv6_address: |
| 202 |
description: |
| 203 |
- The IPv6 address of the interface. |
| 204 |
- For O(virtual_port_channel) interfaces, this is the Side A IPv6 address. |
| 205 |
type: str |
| 206 |
ipv6_link_local_address: |
| 207 |
description: |
| 208 |
- The IPv6 link-local address of the interface. |
| 209 |
- For O(virtual_port_channel) interfaces, this is the Side A IPv6 link-local address. |
| 210 |
type: str |
| 211 |
ipv6_dad: |
| 212 |
description: |
| 213 |
- Whether to enable IPv6 Duplicate Address Detection (DAD). |
| 214 |
- If this parameter is unspecified, NDO defaults to O(ipv6_dad=enabled). |
| 215 |
- For O(virtual_port_channel) interfaces, this is the Side A IPv6 DAD state. |
| 216 |
type: str |
| 217 |
choices: [ enabled, disabled ] |
| 218 |
mac: |
| 219 |
description: |
| 220 |
- The MAC address of the interface. |
| 221 |
type: str |
| 222 |
mtu: |
| 223 |
description: |
| 224 |
- The Maximum Transmission Unit (MTU) of the interface. |
| 225 |
- Use O(mtu=inherit) to inherit the value configured under the fabric L2 MTU settings. |
| 226 |
- The value must be 1, or in the range 576 - 9216 or O(mtu=inherit). |
| 227 |
type: str |
| 228 |
target_dscp: |
| 229 |
description: |
| 230 |
- The target Differentiated Services Code Point (DSCP) of the interface. |
| 231 |
- If this parameter is unspecified, NDO defaults to O(target_dscp=unspecified). |
| 232 |
type: str |
| 233 |
choices: |
| 234 |
- af11 |
| 235 |
- af12 |
| 236 |
- af13 |
| 237 |
- af21 |
| 238 |
- af22 |
| 239 |
- af23 |
| 240 |
- af31 |
| 241 |
- af32 |
| 242 |
- af33 |
| 243 |
- af41 |
| 244 |
- af42 |
| 245 |
- af43 |
| 246 |
- cs0 |
| 247 |
- cs1 |
| 248 |
- cs2 |
| 249 |
- cs3 |
| 250 |
- cs4 |
| 251 |
- cs5 |
| 252 |
- cs6 |
| 253 |
- cs7 |
| 254 |
- expedited_forwarding |
| 255 |
- unspecified |
| 256 |
- voice_admit |
| 257 |
encapsulation_scope: |
| 258 |
description: |
| 259 |
- The encapsulation scope of the interface. |
| 260 |
type: str |
| 261 |
aliases: [ encap_scope ] |
| 262 |
choices: [ local, vrf ] |
| 263 |
encapsulation_type: |
| 264 |
description: |
| 265 |
- The encapsulation type of the interface. |
| 266 |
type: str |
| 267 |
aliases: [ encap_type ] |
| 268 |
choices: [ vlan, vxlan ] |
| 269 |
encapsulation_value: |
| 270 |
description: |
| 271 |
- The encapsulation value of the interface. |
| 272 |
- The option O(encapsulation_type=vlan), specifies VLAN ID which must be in the range 1 - 4094. |
| 273 |
- The option O(encapsulation_type=vxlan), specifies VXLAN Network Identifier (VNI) which must be in the range 5000 - 16777215. |
| 274 |
type: int |
| 275 |
aliases: [ encap, encapsulation, encapsulation_id ] |
| 276 |
encapsulation_mode: |
| 277 |
description: |
| 278 |
- The encapsulation mode of the interface. |
| 279 |
type: str |
| 280 |
aliases: [ encap_mode ] |
| 281 |
choices: [ access, trunk, trunk_native ] |
| 282 |
auto_state: |
| 283 |
description: |
| 284 |
- Whether to enable auto state on the interface. |
| 285 |
- Controls whether the SVI comes up or down based on the state of its associated Layer 2 ports. |
| 286 |
type: str |
| 287 |
choices: [ enabled, disabled ] |
| 288 |
state: |
| 289 |
description: |
| 290 |
- Determines the desired state of the resource. |
| 291 |
- Use C(absent) to remove the resource. |
| 292 |
- Use C(query) to list the resource. |
| 293 |
- Use C(present) to create or update the resource. |
| 294 |
type: str |
| 295 |
choices: [ absent, query, present ] |
| 296 |
default: query |
| 297 |
notes: |
| 298 |
- The O(template) or O(template_id) must exist before using this module in your playbook. |
| 299 |
The M(cisco.mso.ndo_template) module can be used for this. |
| 300 |
- The O(l3out) or O(l3out_uuid) must exist before using this module in your playbook. |
| 301 |
The M(cisco.mso.ndo_l3out_template) module can be used for this. |
| 302 |
- The O(node_group_policy) must exist before using this module in your playbook. |
| 303 |
The M(cisco.mso.ndo_l3out_node_group_policy) module can be used for this. |
| 304 |
- The O(interface_group_policy) must exist before using this module in your playbook. |
| 305 |
The M(cisco.mso.ndo_l3out_interface_group_policy) module can be used for this. |
| 306 |
- The O(port_channel) must exist before using this module in your playbook. |
| 307 |
The M(cisco.mso.ndo_port_channel_interface) module can be used for this. |
| 308 |
- The O(virtual_port_channel) must exist before using this module in your playbook. |
| 309 |
The M(cisco.mso.ndo_virtual_port_channel_interface) module can be used for this. |
| 310 |
seealso: |
| 311 |
- module: cisco.mso.ndo_template |
| 312 |
- module: cisco.mso.ndo_l3out_template |
| 313 |
- module: cisco.mso.ndo_l3out_node_group_policy |
| 314 |
- module: cisco.mso.ndo_l3out_interface_group_policy |
| 315 |
- module: cisco.mso.ndo_port_channel_interface |
| 316 |
- module: cisco.mso.ndo_virtual_port_channel_interface |
| 317 |
extends_documentation_fragment: cisco.mso.modules |
| 318 |
""" |
| 319 |
|
| 320 |
EXAMPLES = r""" |
| 321 |
- name: Create a L3Out SVI Interface of type port with L3Out Node configuration |
| 322 |
cisco.mso.ndo_l3out_svi_interface: |
| 323 |
host: mso_host |
| 324 |
username: admin |
| 325 |
password: SomeSecretPassword |
| 326 |
template: l3out_template |
| 327 |
l3out: l3out_name |
| 328 |
node_id: 101 |
| 329 |
node_router_id: 1.1.1.1 |
| 330 |
path: eth1/1 |
| 331 |
ipv4_address: 10.0.0.2/24 |
| 332 |
ipv6_address: 2::101/16 |
| 333 |
ipv6_link_local_address: FE80::10 |
| 334 |
ipv6_dad: disabled |
| 335 |
encapsulation_type: vxlan |
| 336 |
encapsulation_value: 5100 |
| 337 |
mac: 00:22:BD:F8:19:FE |
| 338 |
mtu: 1000 |
| 339 |
interface_group_policy: interface_group_policy_1 |
| 340 |
node_group_policy: node_group_policy_1 |
| 341 |
target_dscp: af11 |
| 342 |
encapsulation_scope: vrf |
| 343 |
encapsulation_mode: trunk |
| 344 |
auto_state: enabled |
| 345 |
state: present |
| 346 |
|
| 347 |
- name: Create a L3Out SVI Interface of type port_channel with uuid and L3Out Node configuration |
| 348 |
cisco.mso.ndo_l3out_svi_interface: |
| 349 |
host: mso_host |
| 350 |
username: admin |
| 351 |
password: SomeSecretPassword |
| 352 |
template: l3out_template |
| 353 |
l3out: l3out_name |
| 354 |
node_router_id: 1.1.1.1 |
| 355 |
port_channel: |
| 356 |
uuid: '{{ port_channel_interface_1.current.uuid }}' |
| 357 |
encapsulation_type: vlan |
| 358 |
encapsulation_value: 1200 |
| 359 |
ipv4_address: 10.0.1.1/24 |
| 360 |
ipv6_address: 1::102/16 |
| 361 |
ipv6_dad: disabled |
| 362 |
ipv6_link_local_address: FE80::12 |
| 363 |
mac: 00:22:BD:F8:19:CC |
| 364 |
mtu: 1800 |
| 365 |
interface_group_policy: interface_group_policy_1 |
| 366 |
node_group_policy: node_group_policy_1 |
| 367 |
target_dscp: af41 |
| 368 |
encapsulation_scope: local |
| 369 |
encapsulation_mode: access |
| 370 |
auto_state: enabled |
| 371 |
state: present |
| 372 |
|
| 373 |
- name: Create a L3Out SVI Interface of type virtual_port_channel with reference and L3Out Node configuration |
| 374 |
cisco.mso.ndo_l3out_svi_interface: |
| 375 |
host: mso_host |
| 376 |
username: admin |
| 377 |
password: SomeSecretPassword |
| 378 |
template: l3out_template |
| 379 |
l3out: l3out_name |
| 380 |
node_router_id: 1.1.1.1 |
| 381 |
encapsulation_type: vxlan |
| 382 |
encapsulation_value: 51000 |
| 383 |
ipv4_address: 10.0.2.4/24 |
| 384 |
ipv6_address: 10::105/16 |
| 385 |
ipv6_dad: disabled |
| 386 |
ipv6_link_local_address: FE80::14 |
| 387 |
mac: 00:22:BD:F8:19:AD |
| 388 |
mtu: 9216 |
| 389 |
virtual_port_channel: |
| 390 |
reference: |
| 391 |
name: ansible_virtual_port_channel_interface_1 |
| 392 |
template: ansible_fabric_resource_template_template_1 |
| 393 |
side_b_ipv4_address: 10.0.2.5/24 |
| 394 |
side_b_ipv6_address: 10::106/16 |
| 395 |
side_b_ipv6_link_local_address: FE80::15 |
| 396 |
side_b_ipv6_dad: disabled |
| 397 |
side_b_node_router_id: 2.2.2.2 |
| 398 |
side_b_node_group_policy: node_group_policy_1 |
| 399 |
interface_group_policy: interface_group_policy_1 |
| 400 |
node_group_policy: node_group_policy_1 |
| 401 |
target_dscp: cs5 |
| 402 |
encapsulation_scope: vrf |
| 403 |
encapsulation_mode: trunk_native |
| 404 |
auto_state: enabled |
| 405 |
state: present |
| 406 |
|
| 407 |
- name: Update a L3Out SVI Interface of type port_channel with reference and L3Out Node configurations |
| 408 |
cisco.mso.ndo_l3out_svi_interface: |
| 409 |
host: mso_host |
| 410 |
username: admin |
| 411 |
password: SomeSecretPassword |
| 412 |
template_id: "{{ l3out_template.current.templateId }}" |
| 413 |
l3out_uuid: "{{ l3out.current.uuid }}" |
| 414 |
node_router_id: 1.1.1.1 |
| 415 |
port_channel: |
| 416 |
reference: |
| 417 |
name: ansible_port_channel_interface_1 |
| 418 |
template_id: '{{ port_channel_interface_1.current.templateId }}' |
| 419 |
encapsulation_type: vlan |
| 420 |
encapsulation_value: 1200 |
| 421 |
ipv4_address: 10.0.1.1/24 |
| 422 |
ipv6_address: 1::102/16 |
| 423 |
ipv6_dad: disabled |
| 424 |
ipv6_link_local_address: FE80::12 |
| 425 |
mac: 00:22:BD:F8:19:CC |
| 426 |
mtu: 1800 |
| 427 |
interface_group_policy: interface_group_policy_1 |
| 428 |
target_dscp: af41 |
| 429 |
encapsulation_scope: local |
| 430 |
encapsulation_mode: access |
| 431 |
auto_state: enabled |
| 432 |
state: present |
| 433 |
|
| 434 |
- name: Query an existing L3Out SVI Interface of type port with L3Out Node configuration |
| 435 |
cisco.mso.ndo_l3out_svi_interface: |
| 436 |
host: mso_host |
| 437 |
username: admin |
| 438 |
password: SomeSecretPassword |
| 439 |
template: l3out_template |
| 440 |
l3out: l3out_name |
| 441 |
node_id: 101 |
| 442 |
path: eth1/1 |
| 443 |
state: query |
| 444 |
register: query_with_name |
| 445 |
|
| 446 |
- name: Query an existing L3Out SVI Interface of type port_channel with L3Out Node configuration |
| 447 |
cisco.mso.ndo_l3out_svi_interface: |
| 448 |
host: mso_host |
| 449 |
username: admin |
| 450 |
password: SomeSecretPassword |
| 451 |
template: l3out_template |
| 452 |
l3out: l3out_name |
| 453 |
port_channel: |
| 454 |
reference: |
| 455 |
name: port_channel_interface_name |
| 456 |
template: fabric_resource_template_name |
| 457 |
state: query |
| 458 |
register: query_with_name |
| 459 |
|
| 460 |
- name: Query an existing L3Out SVI Interface of type virtual port_channel with L3Out Node configurations |
| 461 |
cisco.mso.ndo_l3out_svi_interface: |
| 462 |
host: mso_host |
| 463 |
username: admin |
| 464 |
password: SomeSecretPassword |
| 465 |
template: l3out_template |
| 466 |
l3out: l3out_name |
| 467 |
virtual_port_channel: |
| 468 |
uuid: '{{ virtual_port_channel_interface_1.current.uuid }}' |
| 469 |
state: query |
| 470 |
register: query_with_name |
| 471 |
|
| 472 |
- name: Query all existing Routed Interfaces of a L3Out with L3Out Node configuration |
| 473 |
cisco.mso.ndo_l3out_svi_interface: |
| 474 |
host: mso_host |
| 475 |
username: admin |
| 476 |
password: SomeSecretPassword |
| 477 |
template: l3out_template |
| 478 |
l3out: l3out_name |
| 479 |
state: query |
| 480 |
|
| 481 |
- name: Delete an existing L3Out SVI Interface of type port |
| 482 |
cisco.mso.ndo_l3out_svi_interface: |
| 483 |
host: mso_host |
| 484 |
username: admin |
| 485 |
password: SomeSecretPassword |
| 486 |
template: l3out_template |
| 487 |
l3out: l3out_name |
| 488 |
node_id: 101 |
| 489 |
path: eth1/1 |
| 490 |
state: absent |
| 491 |
|
| 492 |
- name: Delete an existing L3Out SVI Interface of type port_channel |
| 493 |
cisco.mso.ndo_l3out_svi_interface: |
| 494 |
host: mso_host |
| 495 |
username: admin |
| 496 |
password: SomeSecretPassword |
| 497 |
template: l3out_template |
| 498 |
l3out: l3out_name |
| 499 |
port_channel: |
| 500 |
uuid: '{{ port_channel_interface_1.current.uuid }}' |
| 501 |
state: absent |
| 502 |
|
| 503 |
- name: Delete an existing L3Out SVI Interface of type virtual_port_channel |
| 504 |
cisco.mso.ndo_l3out_svi_interface: |
| 505 |
host: mso_host |
| 506 |
username: admin |
| 507 |
password: SomeSecretPassword |
| 508 |
template: l3out_template |
| 509 |
l3out: l3out_name |
| 510 |
virtual_port_channel: |
| 511 |
reference: |
| 512 |
name: ansible_virtual_port_channel_interface_1 |
| 513 |
template: ansible_fabric_resource_template_template_1 |
| 514 |
state: absent |
| 515 |
""" |
| 516 |
|
| 517 |
RETURN = r""" |
| 518 |
""" |
| 519 |
|
| 520 |
from ansible.module_utils.basic import AnsibleModule |
| 521 |
from ansible_collections.cisco.mso.plugins.module_utils.mso import ( |
| 522 |
MSOModule, |
| 523 |
mso_argument_spec, |
| 524 |
ndo_l3out_port_channel_spec, |
| 525 |
ndo_l3out_virtual_port_channel_spec, |
| 526 |
) |
| 527 |
from ansible_collections.cisco.mso.plugins.module_utils.templates import MSOTemplates |
| 528 |
from ansible_collections.cisco.mso.plugins.module_utils.constants import TARGET_DSCP_MAP |
| 529 |
from ansible_collections.cisco.mso.plugins.module_utils.utils import append_update_ops_data, delete_none_values |
| 530 |
from ansible_collections.cisco.mso.plugins.module_utils.l3out_node import L3OutNode |
| 531 |
import copy |
| 532 |
|
| 533 |
|
| 534 |
def main(): |
| 535 |
argument_spec = mso_argument_spec() |
| 536 |
argument_spec.update( |
| 537 |
template=dict(type="str", aliases=["l3out_template"]), |
| 538 |
template_id=dict(type="str", aliases=["l3out_template_id"]), |
| 539 |
l3out=dict(type="str", aliases=["l3out_name"]), |
| 540 |
l3out_uuid=dict(type="str"), |
| 541 |
node_id=dict(type="str", aliases=["node", "border_leaf"]), |
| 542 |
node_group_policy=dict(type="str"), |
| 543 |
node_router_id=dict(type="str", aliases=["router_id"]), |
| 544 |
use_router_id_as_loopback=dict(type="bool"), |
| 545 |
node_loopback_ip=dict(type="str", aliases=["loopback_ip"]), |
| 546 |
path=dict(type="str", aliases=["interface"]), |
| 547 |
port_channel=ndo_l3out_port_channel_spec(micro_bfd=False), |
| 548 |
virtual_port_channel=ndo_l3out_virtual_port_channel_spec(), |
| 549 |
interface_group_policy=dict(type="str"), |
| 550 |
ipv4_address=dict(type="str"), |
| 551 |
ipv6_address=dict(type="str"), |
| 552 |
ipv6_link_local_address=dict(type="str"), |
| 553 |
ipv6_dad=dict(type="str", choices=["enabled", "disabled"]), |
| 554 |
mac=dict(type="str"), |
| 555 |
mtu=dict(type="str"), |
| 556 |
target_dscp=dict(type="str", choices=list(TARGET_DSCP_MAP)), |
| 557 |
encapsulation_scope=dict(type="str", choices=["local", "vrf"], aliases=["encap_scope"]), |
| 558 |
encapsulation_type=dict(type="str", choices=["vlan", "vxlan"], aliases=["encap_type"]), |
| 559 |
encapsulation_value=dict(type="int", aliases=["encap", "encapsulation", "encapsulation_id"]), |
| 560 |
encapsulation_mode=dict(type="str", choices=["access", "trunk", "trunk_native"], aliases=["encap_mode"]), |
| 561 |
auto_state=dict(type="str", choices=["enabled", "disabled"]), |
| 562 |
state=dict(type="str", default="query", choices=["absent", "query", "present"]), |
| 563 |
) |
| 564 |
|
| 565 |
module = AnsibleModule( |
| 566 |
argument_spec=argument_spec, |
| 567 |
supports_check_mode=True, |
| 568 |
required_if=[ |
| 569 |
["state", "present", ["path", "port_channel", "virtual_port_channel"], True], |
| 570 |
["state", "absent", ["path", "port_channel", "virtual_port_channel"], True], |
| 571 |
], |
| 572 |
required_one_of=[ |
| 573 |
["template", "template_id"], |
| 574 |
["l3out", "l3out_uuid"], |
| 575 |
], |
| 576 |
required_by={ |
| 577 |
"path": ("node_id", "encapsulation_type", "encapsulation_value"), |
| 578 |
"port_channel": ("encapsulation_type", "encapsulation_value"), |
| 579 |
"virtual_port_channel": ("encapsulation_type", "encapsulation_value"), |
| 580 |
}, |
| 581 |
mutually_exclusive=[ |
| 582 |
["template", "template_id"], |
| 583 |
["l3out", "l3out_uuid"], |
| 584 |
["port_channel", "path"], |
| 585 |
["port_channel", "node_id"], |
| 586 |
["port_channel", "virtual_port_channel"], |
| 587 |
["virtual_port_channel", "path"], |
| 588 |
["virtual_port_channel", "node_id"], |
| 589 |
], |
| 590 |
) |
| 591 |
|
| 592 |
mso = MSOModule(module) |
| 593 |
mso_templates = MSOTemplates(mso) |
| 594 |
|
| 595 |
template_name = mso.params.get("template") |
| 596 |
template_id = mso.params.get("template_id") |
| 597 |
l3out = mso.params.get("l3out") |
| 598 |
l3out_uuid = mso.params.get("l3out_uuid") |
| 599 |
node_id = mso.params.get("node_id") |
| 600 |
node_router_id = mso.params.get("node_router_id") |
| 601 |
node_group_policy = mso.params.get("node_group_policy") |
| 602 |
use_router_id_as_loopback = mso.params.get("use_router_id_as_loopback") |
| 603 |
node_loopback_ip = mso.params.get("node_loopback_ip") |
| 604 |
path = mso.params.get("path") |
| 605 |
port_channel = mso.params.get("port_channel") |
| 606 |
virtual_port_channel = mso.params.get("virtual_port_channel") |
| 607 |
interface_group_policy = mso.params.get("interface_group_policy") |
| 608 |
ipv4_address = mso.params.get("ipv4_address") |
| 609 |
ipv6_address = mso.params.get("ipv6_address") |
| 610 |
ipv6_link_local_address = mso.params.get("ipv6_link_local_address") |
| 611 |
ipv6_dad = mso.params.get("ipv6_dad") |
| 612 |
mac = mso.params.get("mac") |
| 613 |
mtu = mso.params.get("mtu") |
| 614 |
target_dscp = mso.params.get("target_dscp") |
| 615 |
encapsulation_scope = mso.params.get("encapsulation_scope") |
| 616 |
encapsulation_type = mso.params.get("encapsulation_type") |
| 617 |
encapsulation_value = mso.params.get("encapsulation_value") |
| 618 |
encap = None |
| 619 |
if encapsulation_type and encapsulation_value: |
| 620 |
encap = {"encapType": encapsulation_type, "value": encapsulation_value} |
| 621 |
encapsulation_mode = mso.params.get("encapsulation_mode") |
| 622 |
if encapsulation_mode == "trunk_native": |
| 623 |
encapsulation_mode = "access8021p" |
| 624 |
auto_state = mso.params.get("auto_state") |
| 625 |
state = mso.params.get("state") |
| 626 |
|
| 627 |
mso_template = mso_templates.get_template("l3out", template_name, template_id) |
| 628 |
mso_template.validate_template("l3out") |
| 629 |
l3out_object = mso_template.get_l3out_object(l3out_uuid, l3out, True) |
| 630 |
|
| 631 |
port_channel_uuid = None |
| 632 |
if port_channel: |
| 633 |
if port_channel.get("uuid"): |
| 634 |
port_channel_uuid = port_channel.get("uuid") |
| 635 |
port_channel_match = mso_template.get_template_object_by_uuid("portChannel", port_channel_uuid, True) |
| 636 |
else: |
| 637 |
fabric_resource_mso_template = mso_templates.get_template( |
| 638 |
"fabric_resource", |
| 639 |
port_channel.get("reference").get("template"), |
| 640 |
port_channel.get("reference").get("template_id"), |
| 641 |
fail_module=True, |
| 642 |
) |
| 643 |
port_channel_match = fabric_resource_mso_template.get_port_channel( |
| 644 |
port_channel_uuid, |
| 645 |
port_channel.get("reference").get("name"), |
| 646 |
fail_module=True, |
| 647 |
).details |
| 648 |
port_channel_uuid = port_channel_match.get("uuid") |
| 649 |
node_id = port_channel_match.get("node") |
| 650 |
|
| 651 |
virtual_port_channel_uuid = None |
| 652 |
node_id_side_b = None |
| 653 |
if virtual_port_channel: |
| 654 |
if virtual_port_channel.get("uuid"): |
| 655 |
virtual_port_channel_uuid = virtual_port_channel.get("uuid") |
| 656 |
virtual_port_channel_match = mso_template.get_template_object_by_uuid("virtualPortChannel", virtual_port_channel_uuid, True) |
| 657 |
else: |
| 658 |
fabric_resource_mso_template = mso_templates.get_template( |
| 659 |
"fabric_resource", |
| 660 |
virtual_port_channel.get("reference").get("template"), |
| 661 |
virtual_port_channel.get("reference").get("template_id"), |
| 662 |
fail_module=True, |
| 663 |
) |
| 664 |
virtual_port_channel_match = fabric_resource_mso_template.get_virtual_port_channel( |
| 665 |
virtual_port_channel_uuid, |
| 666 |
virtual_port_channel.get("reference").get("name"), |
| 667 |
fail_module=True, |
| 668 |
).details |
| 669 |
virtual_port_channel_uuid = virtual_port_channel_match.get("uuid") |
| 670 |
node_id = virtual_port_channel_match.get("node1Details", {}).get("node") |
| 671 |
node_id_side_b = virtual_port_channel_match.get("node2Details", {}).get("node") |
| 672 |
|
| 673 |
pod_id = None |
| 674 |
if path or port_channel or virtual_port_channel: |
| 675 |
pod_id = mso.get_site_interface_details( |
| 676 |
site_id=mso_template.template.get("l3outTemplate", {}).get("siteId"), |
| 677 |
node=node_id, |
| 678 |
port=path, |
| 679 |
port_channel_uuid=port_channel_uuid, |
| 680 |
virtual_port_channel_uuid=virtual_port_channel_uuid, |
| 681 |
).get("pod") |
| 682 |
|
| 683 |
match = mso_template.get_l3out_svi_interface(l3out_object.details, pod_id, node_id, path, encap, port_channel_uuid or virtual_port_channel_uuid) |
| 684 |
if (path or port_channel or virtual_port_channel) and match: |
| 685 |
set_svi_interface_details(mso_template, match.details, l3out_object) |
| 686 |
mso.existing = mso.previous = copy.deepcopy(match.details) # Query a specific object |
| 687 |
elif match: |
| 688 |
mso.existing = [set_svi_interface_details(mso_template, obj, l3out_object) for obj in match] |
| 689 |
|
| 690 |
l3out_interface_path = "/l3outTemplate/l3outs/{0}/sviInterfaces/{1}".format(l3out_object.index, match.index if match else "-") |
| 691 |
|
| 692 |
ops = [] |
| 693 |
|
| 694 |
l3out_node_side_b = None |
| 695 |
if state != "query": |
| 696 |
l3out_node = L3OutNode(mso.params, mso_template, l3out_object, pod_id, node_id) |
| 697 |
if node_id_side_b: |
| 698 |
node_details_side_b = { |
| 699 |
"node_router_id": virtual_port_channel.get("side_b_node_router_id"), |
| 700 |
"node_group_policy": virtual_port_channel.get("side_b_node_group_policy"), |
| 701 |
"use_router_id_as_loopback": virtual_port_channel.get("side_b_use_router_id_as_loopback"), |
| 702 |
"node_loopback_ip": virtual_port_channel.get("side_b_node_loopback_ip"), |
| 703 |
} |
| 704 |
l3out_node_side_b = L3OutNode(node_details_side_b, mso_template, l3out_object, pod_id, node_id_side_b) |
| 705 |
|
| 706 |
if state == "present": |
| 707 |
|
| 708 |
mso_values = { |
| 709 |
"path": path, |
| 710 |
"pathRef": port_channel_uuid or virtual_port_channel_uuid, |
| 711 |
"pathType": "port" if path else "pc" if port_channel else "vpc", |
| 712 |
"group": interface_group_policy, |
| 713 |
"mac": mac, |
| 714 |
"mtu": mtu, |
| 715 |
"targetDscp": target_dscp, |
| 716 |
"encap": encap, |
| 717 |
} |
| 718 |
|
| 719 |
if path: |
| 720 |
mso_values["nodeID"] = node_id |
| 721 |
mso_values["podID"] = pod_id |
| 722 |
|
| 723 |
if match: |
| 724 |
mso_values[("addresses", "primaryV4")] = ipv4_address |
| 725 |
mso_values[("addresses", "primaryV6")] = ipv6_address |
| 726 |
mso_values[("addresses", "linkLocalV6")] = ipv6_link_local_address |
| 727 |
mso_values[("addresses", "ipV6DAD")] = ipv6_dad |
| 728 |
mso_values[("svi", "encapScope")] = encapsulation_scope |
| 729 |
mso_values[("svi", "mode")] = encapsulation_mode |
| 730 |
mso_values[("svi", "autostate")] = auto_state |
| 731 |
|
| 732 |
if virtual_port_channel: |
| 733 |
mso_values["sideBAddresses"] = { |
| 734 |
"primaryV4": virtual_port_channel.get("side_b_ipv4_address"), |
| 735 |
"primaryV6": virtual_port_channel.get("side_b_ipv6_address"), |
| 736 |
"linkLocalV6": virtual_port_channel.get("side_b_ipv6_link_local_address"), |
| 737 |
"ipV6DAD": virtual_port_channel.get("side_b_ipv6_dad"), |
| 738 |
} |
| 739 |
|
| 740 |
mso_values = delete_none_values(mso_values) |
| 741 |
append_update_ops_data(ops, match.details, l3out_interface_path, mso_values) |
| 742 |
mso.sanitize(match.details, collate=True) |
| 743 |
|
| 744 |
else: |
| 745 |
mso_values["addresses"] = { |
| 746 |
"primaryV4": ipv4_address, |
| 747 |
"primaryV6": ipv6_address, |
| 748 |
"linkLocalV6": ipv6_link_local_address, |
| 749 |
"ipV6DAD": ipv6_dad, |
| 750 |
} |
| 751 |
|
| 752 |
mso_values["svi"] = { |
| 753 |
"encapScope": encapsulation_scope, |
| 754 |
"mode": encapsulation_mode, |
| 755 |
"autostate": auto_state, |
| 756 |
} |
| 757 |
|
| 758 |
if virtual_port_channel: |
| 759 |
mso_values["sideBAddresses"] = { |
| 760 |
"primaryV4": virtual_port_channel.get("side_b_ipv4_address"), |
| 761 |
"primaryV6": virtual_port_channel.get("side_b_ipv6_address"), |
| 762 |
"linkLocalV6": virtual_port_channel.get("side_b_ipv6_link_local_address"), |
| 763 |
"ipV6DAD": virtual_port_channel.get("side_b_ipv6_dad"), |
| 764 |
} |
| 765 |
|
| 766 |
mso_values = delete_none_values(mso_values) |
| 767 |
mso.sanitize(mso_values) |
| 768 |
ops.append(dict(op="add", path=l3out_interface_path, value=mso.sent)) |
| 769 |
|
| 770 |
# update mso.proposed with interface details that are not included in the interface payload and node details |
| 771 |
mso.proposed["node"] = l3out_node.construct_node_payload() |
| 772 |
if node_id_side_b: |
| 773 |
mso.proposed["sideBNode"] = l3out_node_side_b.construct_node_payload() |
| 774 |
|
| 775 |
set_svi_interface_details(mso_template, mso.proposed, l3out_object) |
| 776 |
|
| 777 |
l3out_node.update_ops(ops) |
| 778 |
if node_id_side_b: |
| 779 |
l3out_node_side_b.update_ops(ops) |
| 780 |
|
| 781 |
elif state == "absent": |
| 782 |
if match: |
| 783 |
ops.append(dict(op="remove", path=l3out_interface_path)) |
| 784 |
|
| 785 |
if not mso.module.check_mode and ops: |
| 786 |
ignore_errors = ["node {0}-{1} doesn't have an interface configured".format(pod_id, node_id)] |
| 787 |
if node_id_side_b: |
| 788 |
ignore_errors.append("node {0}-{1} doesn't have an interface configured".format(pod_id, node_id_side_b)) |
| 789 |
|
| 790 |
remove_ops = {ignore_errors[0]: l3out_node.get_node_remove_op()} |
| 791 |
if node_id_side_b: |
| 792 |
remove_ops[ignore_errors[1]] = l3out_node_side_b.get_node_remove_op() |
| 793 |
|
| 794 |
response = mso.l3out_interface_request(mso_template, ops, ignore_errors, state, remove_ops) |
| 795 |
l3out_object = mso_template.get_l3out_object(l3out_uuid, l3out, True, search_object=response) |
| 796 |
match = mso_template.get_l3out_svi_interface(l3out_object.details, pod_id, node_id, path, encap, port_channel_uuid or virtual_port_channel_uuid) |
| 797 |
if match: |
| 798 |
set_svi_interface_details(mso_template, match.details, l3out_object) |
| 799 |
mso.existing = match.details # When the state is present |
| 800 |
else: |
| 801 |
mso.existing = {} # When the state is absent |
| 802 |
elif mso.module.check_mode and state != "query": # When the state is present/absent with check mode |
| 803 |
mso.existing = mso.proposed if state == "present" else {} |
| 804 |
mso.exit_json() |
| 805 |
|
| 806 |
|
| 807 |
def set_svi_interface_details(mso_template, svi_interface, l3out_object): |
| 808 |
mso_template.update_config_with_port_channel_references(svi_interface) |
| 809 |
mso_template.update_config_with_node_references(svi_interface, l3out_object) |
| 810 |
return svi_interface |
| 811 |
|
| 812 |
|
| 813 |
if __name__ == "__main__": |
| 814 |
main() |