| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2023, Shreyas Srish <[email protected]> |
| 5 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} |
| 12 |
|
| 13 |
DOCUMENTATION = r""" |
| 14 |
--- |
| 15 |
module: aci_l3out_floating_svi |
| 16 |
short_description: Manage Layer 3 Outside (L3Out) interfaces (l3ext:VirtualLIfP) |
| 17 |
description: |
| 18 |
- Manage L3Out interfaces on Cisco ACI fabrics. |
| 19 |
options: |
| 20 |
tenant: |
| 21 |
description: |
| 22 |
- Name of an existing tenant. |
| 23 |
type: str |
| 24 |
aliases: [ tenant_name ] |
| 25 |
required: true |
| 26 |
l3out: |
| 27 |
description: |
| 28 |
- Name of an existing L3Out. |
| 29 |
type: str |
| 30 |
aliases: [ l3out_name ] |
| 31 |
required: true |
| 32 |
node_profile: |
| 33 |
description: |
| 34 |
- Name of the node profile. |
| 35 |
type: str |
| 36 |
aliases: [ node_profile_name, logical_node ] |
| 37 |
required: true |
| 38 |
interface_profile: |
| 39 |
description: |
| 40 |
- Name of the interface profile. |
| 41 |
type: str |
| 42 |
aliases: [ interface_profile_name, logical_interface ] |
| 43 |
required: true |
| 44 |
pod_id: |
| 45 |
description: |
| 46 |
- Pod ID to build the interface on. |
| 47 |
type: str |
| 48 |
node_id: |
| 49 |
description: |
| 50 |
- Node ID to build the interface on for Port-channels and single ports. |
| 51 |
type: str |
| 52 |
encap: |
| 53 |
description: |
| 54 |
- Encapsulation on the interface (e.g. "vlan-500") |
| 55 |
type: str |
| 56 |
encap_scope: |
| 57 |
description: |
| 58 |
- Encapsulation scope. |
| 59 |
choices: [ vrf, local ] |
| 60 |
type: str |
| 61 |
address: |
| 62 |
description: |
| 63 |
- IP address. |
| 64 |
type: str |
| 65 |
aliases: [ addr, ip_address ] |
| 66 |
mac_address: |
| 67 |
description: |
| 68 |
- The MAC address option of the interface. |
| 69 |
type: str |
| 70 |
link_local_address: |
| 71 |
description: |
| 72 |
- The link local address option of the interface. |
| 73 |
type: str |
| 74 |
mtu: |
| 75 |
description: |
| 76 |
- Interface MTU. |
| 77 |
type: str |
| 78 |
ipv6_dad: |
| 79 |
description: |
| 80 |
- IPv6 Duplicate Address Detection (DAD) feature. |
| 81 |
type: str |
| 82 |
choices: [ enabled, disabled] |
| 83 |
mode: |
| 84 |
description: |
| 85 |
- The mode option for ext-svi interface. |
| 86 |
type: str |
| 87 |
choices: [ regular, native, untagged ] |
| 88 |
dscp: |
| 89 |
description: |
| 90 |
- The target Differentiated Service (DSCP) value. |
| 91 |
- The APIC defaults to C(unspecified) when unset during creation. |
| 92 |
type: str |
| 93 |
choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ] |
| 94 |
aliases: [ target_dscp ] |
| 95 |
external_bridge_group_profile: |
| 96 |
description: |
| 97 |
- The external bridge group profile. |
| 98 |
- Pass "" as the value to remove an existing external bridge group profile (See Examples). |
| 99 |
- This is only supported in APIC v5.0 and above. |
| 100 |
type: str |
| 101 |
state: |
| 102 |
description: |
| 103 |
- Use C(present) or C(absent) for adding or removing. |
| 104 |
- Use C(query) for listing an object or multiple objects. |
| 105 |
type: str |
| 106 |
choices: [ absent, present, query ] |
| 107 |
default: present |
| 108 |
auto_state: |
| 109 |
description: |
| 110 |
- SVI auto state. |
| 111 |
type: str |
| 112 |
choices: [ enabled, disabled ] |
| 113 |
extends_documentation_fragment: |
| 114 |
- cisco.aci.aci |
| 115 |
- cisco.aci.annotation |
| 116 |
|
| 117 |
notes: |
| 118 |
- The C(tenant), C(l3out), C(logical_node_profile) and C(logical_interface_profile) must exist before using this module in your playbook. |
| 119 |
The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out), M(cisco.aci.aci_l3out_logical_node_profile), M(cisco.aci.aci_l3out_logical_interface_profile) \ |
| 120 |
modules can be used for this. |
| 121 |
seealso: |
| 122 |
- module: cisco.aci.aci_tenant |
| 123 |
- module: cisco.aci.aci_l3out |
| 124 |
- module: cisco.aci.aci_l3out_logical_node_profile |
| 125 |
- module: cisco.aci.aci_l3out_logical_interface_profile |
| 126 |
- name: APIC Management Information Model reference |
| 127 |
description: More information about the internal APIC class B(l3ext:VirtualLIfP) |
| 128 |
link: https://developer.cisco.com/docs/apic-mim-ref/ |
| 129 |
author: |
| 130 |
- Shreyas Srish (@shrsr) |
| 131 |
""" |
| 132 |
|
| 133 |
EXAMPLES = r""" |
| 134 |
- name: Create a Floating SVI |
| 135 |
cisco.aci.aci_l3out_floating_svi: |
| 136 |
host: apic |
| 137 |
username: admin |
| 138 |
password: SomeSecretPassword |
| 139 |
tenant: my_tenant |
| 140 |
l3out: my_l3out |
| 141 |
node_profile: my_node_profile |
| 142 |
interface_profile: my_interface_profile |
| 143 |
pod_id: 1 |
| 144 |
node_id: 201 |
| 145 |
encap: vlan-1 |
| 146 |
address: 23.45.67.90/24 |
| 147 |
external_bridge_group_profile: bridge1 |
| 148 |
state: present |
| 149 |
delegate_to: localhost |
| 150 |
|
| 151 |
- name: Remove an external bridge group profile |
| 152 |
cisco.aci.aci_l3out_floating_svi: |
| 153 |
host: apic |
| 154 |
username: admin |
| 155 |
password: SomeSecretPassword |
| 156 |
tenant: my_tenant |
| 157 |
l3out: my_l3out |
| 158 |
node_profile: my_node_profile |
| 159 |
interface_profile: my_interface_profile |
| 160 |
pod_id: 1 |
| 161 |
node_id: 201 |
| 162 |
encap: vlan-1 |
| 163 |
address: 23.45.67.90/24 |
| 164 |
external_bridge_group_profile: "" |
| 165 |
state: present |
| 166 |
delegate_to: localhost |
| 167 |
|
| 168 |
- name: Remove a Floating SVI |
| 169 |
cisco.aci.aci_l3out_floating_svi: |
| 170 |
host: apic |
| 171 |
username: admin |
| 172 |
password: SomeSecretPassword |
| 173 |
tenant: my_tenant |
| 174 |
l3out: my_l3out |
| 175 |
node_profile: my_node_profile |
| 176 |
interface_profile: my_interface_profile |
| 177 |
pod_id: 1 |
| 178 |
node_id: 201 |
| 179 |
encap: vlan-1 |
| 180 |
state: absent |
| 181 |
delegate_to: localhost |
| 182 |
|
| 183 |
- name: Query a Floating SVI |
| 184 |
cisco.aci.aci_l3out_floating_svi: |
| 185 |
host: apic |
| 186 |
username: admin |
| 187 |
password: SomeSecretPassword |
| 188 |
tenant: my_tenant |
| 189 |
l3out: my_l3out |
| 190 |
node_profile: my_node_profile |
| 191 |
interface_profile: my_interface_profile |
| 192 |
pod_id: 1 |
| 193 |
node_id: 201 |
| 194 |
encap: vlan-1 |
| 195 |
state: query |
| 196 |
delegate_to: localhost |
| 197 |
register: query_result |
| 198 |
|
| 199 |
- name: Query all the Floating SVIs under an interface profile |
| 200 |
cisco.aci.aci_l3out_floating_svi: |
| 201 |
host: apic |
| 202 |
username: admin |
| 203 |
password: SomeSecretPassword |
| 204 |
tenant: my_tenant |
| 205 |
l3out: my_l3out |
| 206 |
node_profile: my_node_profile |
| 207 |
interface_profile: my_interface_profile |
| 208 |
state: query |
| 209 |
delegate_to: localhost |
| 210 |
register: query_results |
| 211 |
""" |
| 212 |
|
| 213 |
RETURN = r""" |
| 214 |
current: |
| 215 |
description: The existing configuration from the APIC after the module has finished |
| 216 |
returned: success |
| 217 |
type: list |
| 218 |
sample: |
| 219 |
[ |
| 220 |
{ |
| 221 |
"fvTenant": { |
| 222 |
"attributes": { |
| 223 |
"descr": "Production environment", |
| 224 |
"dn": "uni/tn-production", |
| 225 |
"name": "production", |
| 226 |
"nameAlias": "", |
| 227 |
"ownerKey": "", |
| 228 |
"ownerTag": "" |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
] |
| 233 |
error: |
| 234 |
description: The error information as returned from the APIC |
| 235 |
returned: failure |
| 236 |
type: dict |
| 237 |
sample: |
| 238 |
{ |
| 239 |
"code": "122", |
| 240 |
"text": "unknown managed object class foo" |
| 241 |
} |
| 242 |
raw: |
| 243 |
description: The raw output returned by the APIC REST API (xml or json) |
| 244 |
returned: parse error |
| 245 |
type: str |
| 246 |
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>' |
| 247 |
sent: |
| 248 |
description: The actual/minimal configuration pushed to the APIC |
| 249 |
returned: info |
| 250 |
type: list |
| 251 |
sample: |
| 252 |
{ |
| 253 |
"fvTenant": { |
| 254 |
"attributes": { |
| 255 |
"descr": "Production environment" |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
previous: |
| 260 |
description: The original configuration from the APIC before the module has started |
| 261 |
returned: info |
| 262 |
type: list |
| 263 |
sample: |
| 264 |
[ |
| 265 |
{ |
| 266 |
"fvTenant": { |
| 267 |
"attributes": { |
| 268 |
"descr": "Production", |
| 269 |
"dn": "uni/tn-production", |
| 270 |
"name": "production", |
| 271 |
"nameAlias": "", |
| 272 |
"ownerKey": "", |
| 273 |
"ownerTag": "" |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
] |
| 278 |
proposed: |
| 279 |
description: The assembled configuration from the user-provided parameters |
| 280 |
returned: info |
| 281 |
type: dict |
| 282 |
sample: |
| 283 |
{ |
| 284 |
"fvTenant": { |
| 285 |
"attributes": { |
| 286 |
"descr": "Production environment", |
| 287 |
"name": "production" |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
filter_string: |
| 292 |
description: The filter string used for the request |
| 293 |
returned: failure or debug |
| 294 |
type: str |
| 295 |
sample: ?rsp-prop-include=config-only |
| 296 |
method: |
| 297 |
description: The HTTP method used for the request to the APIC |
| 298 |
returned: failure or debug |
| 299 |
type: str |
| 300 |
sample: POST |
| 301 |
response: |
| 302 |
description: The HTTP response from the APIC |
| 303 |
returned: failure or debug |
| 304 |
type: str |
| 305 |
sample: OK (30 bytes) |
| 306 |
status: |
| 307 |
description: The HTTP status from the APIC |
| 308 |
returned: failure or debug |
| 309 |
type: int |
| 310 |
sample: 200 |
| 311 |
url: |
| 312 |
description: The HTTP url used for the request to the APIC |
| 313 |
returned: failure or debug |
| 314 |
type: str |
| 315 |
sample: https://10.11.12.13/api/mo/uni/tn-production.json |
| 316 |
""" |
| 317 |
|
| 318 |
|
| 319 |
from ansible.module_utils.basic import AnsibleModule |
| 320 |
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_contract_dscp_spec |
| 321 |
|
| 322 |
|
| 323 |
def main(): |
| 324 |
argument_spec = aci_argument_spec() |
| 325 |
argument_spec.update(aci_annotation_spec()) |
| 326 |
argument_spec.update( |
| 327 |
tenant=dict(type="str", aliases=["tenant_name"], required=True), |
| 328 |
l3out=dict(type="str", aliases=["l3out_name"], required=True), |
| 329 |
node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"], required=True), |
| 330 |
interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"], required=True), |
| 331 |
state=dict(type="str", default="present", choices=["absent", "present", "query"]), |
| 332 |
pod_id=dict(type="str"), |
| 333 |
node_id=dict(type="str"), |
| 334 |
address=dict(type="str", aliases=["addr", "ip_address"]), |
| 335 |
link_local_address=dict(type="str"), |
| 336 |
mac_address=dict(type="str"), |
| 337 |
mtu=dict(type="str"), |
| 338 |
ipv6_dad=dict(type="str", choices=["enabled", "disabled"]), |
| 339 |
mode=dict(type="str", choices=["regular", "native", "untagged"]), |
| 340 |
encap=dict(type="str"), |
| 341 |
encap_scope=dict(type="str", choices=["vrf", "local"]), |
| 342 |
auto_state=dict(type="str", choices=["enabled", "disabled"]), |
| 343 |
external_bridge_group_profile=dict(type="str"), |
| 344 |
dscp=aci_contract_dscp_spec(direction="dscp"), |
| 345 |
) |
| 346 |
|
| 347 |
module = AnsibleModule( |
| 348 |
argument_spec=argument_spec, |
| 349 |
supports_check_mode=True, |
| 350 |
required_if=[ |
| 351 |
["state", "present", ["pod_id", "node_id", "encap", "address"]], |
| 352 |
["state", "absent", ["pod_id", "node_id", "encap"]], |
| 353 |
], |
| 354 |
) |
| 355 |
|
| 356 |
tenant = module.params.get("tenant") |
| 357 |
l3out = module.params.get("l3out") |
| 358 |
node_profile = module.params.get("node_profile") |
| 359 |
interface_profile = module.params.get("interface_profile") |
| 360 |
state = module.params.get("state") |
| 361 |
pod_id = module.params.get("pod_id") |
| 362 |
node_id = module.params.get("node_id") |
| 363 |
address = module.params.get("address") |
| 364 |
mtu = module.params.get("mtu") |
| 365 |
ipv6_dad = module.params.get("ipv6_dad") |
| 366 |
link_local_address = module.params.get("link_local_address") |
| 367 |
mac_address = module.params.get("mac_address") |
| 368 |
mode = module.params.get("mode") |
| 369 |
encap = module.params.get("encap") |
| 370 |
encap_scope = "ctx" if module.params.get("encap_scope") == "vrf" else module.params.get("encap_scope") |
| 371 |
auto_state = module.params.get("auto_state") |
| 372 |
external_bridge_group_profile = module.params.get("external_bridge_group_profile") |
| 373 |
|
| 374 |
aci = ACIModule(module) |
| 375 |
|
| 376 |
node_dn = None |
| 377 |
if pod_id and node_id: |
| 378 |
node_dn = "topology/pod-{0}/node-{1}".format(pod_id, node_id) |
| 379 |
|
| 380 |
child_classes = [] |
| 381 |
if external_bridge_group_profile is not None: |
| 382 |
child_classes.append("l3extBdProfileCont") |
| 383 |
|
| 384 |
aci.construct_url( |
| 385 |
root_class=dict( |
| 386 |
aci_class="fvTenant", |
| 387 |
aci_rn="tn-{0}".format(tenant), |
| 388 |
module_object=tenant, |
| 389 |
target_filter={"name": tenant}, |
| 390 |
), |
| 391 |
subclass_1=dict( |
| 392 |
aci_class="l3extOut", |
| 393 |
aci_rn="out-{0}".format(l3out), |
| 394 |
module_object=l3out, |
| 395 |
target_filter={"name": l3out}, |
| 396 |
), |
| 397 |
subclass_2=dict( |
| 398 |
aci_class="l3extLNodeP", |
| 399 |
aci_rn="lnodep-{0}".format(node_profile), |
| 400 |
module_object=node_profile, |
| 401 |
target_filter={"name": node_profile}, |
| 402 |
), |
| 403 |
subclass_3=dict( |
| 404 |
aci_class="l3extLIfP", |
| 405 |
aci_rn="lifp-{0}".format(interface_profile), |
| 406 |
module_object=interface_profile, |
| 407 |
target_filter={"name": interface_profile}, |
| 408 |
), |
| 409 |
subclass_4=dict( |
| 410 |
aci_class="l3extVirtualLIfP", aci_rn="vlifp-[{0}]-[{1}]".format(node_dn, encap), module_object=node_dn, target_filter={"nodeDn": node_dn} |
| 411 |
), |
| 412 |
child_classes=child_classes, |
| 413 |
) |
| 414 |
|
| 415 |
aci.get_existing() |
| 416 |
|
| 417 |
if state == "present": |
| 418 |
child_configs = [] |
| 419 |
if external_bridge_group_profile is not None: |
| 420 |
if external_bridge_group_profile == "" and isinstance(aci.existing, list) and len(aci.existing) > 0: |
| 421 |
if aci.existing[0].get("l3extVirtualLIfP", {}).get("children") is not None: |
| 422 |
child_configs.append( |
| 423 |
dict( |
| 424 |
l3extBdProfileCont=dict( |
| 425 |
attributes=dict(status="deleted"), |
| 426 |
), |
| 427 |
) |
| 428 |
) |
| 429 |
elif external_bridge_group_profile != "": |
| 430 |
child_configs.append( |
| 431 |
dict( |
| 432 |
l3extBdProfileCont=dict( |
| 433 |
attributes=dict(), |
| 434 |
children=[ |
| 435 |
dict( |
| 436 |
l3extRsBdProfile=dict( |
| 437 |
attributes=dict( |
| 438 |
tDn="uni/tn-{0}/bdprofile-{1}".format(tenant, external_bridge_group_profile), |
| 439 |
), |
| 440 |
) |
| 441 |
) |
| 442 |
], |
| 443 |
) |
| 444 |
) |
| 445 |
) |
| 446 |
|
| 447 |
aci.payload( |
| 448 |
aci_class="l3extVirtualLIfP", |
| 449 |
class_config=dict( |
| 450 |
addr=address, |
| 451 |
ipv6Dad=ipv6_dad, |
| 452 |
mtu=mtu, |
| 453 |
ifInstT="ext-svi", |
| 454 |
mode=mode, |
| 455 |
encap=encap, |
| 456 |
encapScope=encap_scope, |
| 457 |
autostate=auto_state, |
| 458 |
llAddr=link_local_address, |
| 459 |
mac=mac_address, |
| 460 |
), |
| 461 |
child_configs=child_configs, |
| 462 |
) |
| 463 |
|
| 464 |
aci.get_diff(aci_class="l3extVirtualLIfP") |
| 465 |
|
| 466 |
aci.post_config() |
| 467 |
|
| 468 |
elif state == "absent": |
| 469 |
aci.delete_config() |
| 470 |
|
| 471 |
aci.exit_json() |
| 472 |
|
| 473 |
|
| 474 |
if __name__ == "__main__": |
| 475 |
main() |