| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2023, Tim Cragg (@timcragg) |
| 5 |
# Copyright: (c) 2023, Akini Ross (@akinross) |
| 6 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} |
| 13 |
|
| 14 |
DOCUMENTATION = r""" |
| 15 |
--- |
| 16 |
module: aci_vrf_multicast |
| 17 |
short_description: Manage VRF Multicast objects (pim:CtxP) |
| 18 |
description: |
| 19 |
- Manage VRF Multicast objects on Cisco ACI fabrics. |
| 20 |
- Creating I(state=present) enables Protocol Independent Multicast (PIM) on a VRF |
| 21 |
- Deleting I(state=absent) disables Protocol Independent Multicast (PIM) on a VRF. |
| 22 |
options: |
| 23 |
tenant: |
| 24 |
description: |
| 25 |
- The name of an existing tenant. |
| 26 |
type: str |
| 27 |
aliases: [ tenant_name ] |
| 28 |
vrf: |
| 29 |
description: |
| 30 |
- The name of an existing VRF. |
| 31 |
type: str |
| 32 |
aliases: [ vrf_name ] |
| 33 |
pim_setting: |
| 34 |
description: Configuration container for Protocol Independent Multicast (PIM) settings. |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
mtu: |
| 38 |
description: |
| 39 |
- The MTU size supported for multicast. |
| 40 |
- The APIC defaults to C(1500) when unset during creation. |
| 41 |
type: int |
| 42 |
control_state: |
| 43 |
description: |
| 44 |
- The action(s) to take when a loop is detected. |
| 45 |
- Specify C([]) to remove the control state configuration. |
| 46 |
type: list |
| 47 |
elements: str |
| 48 |
aliases: [ control, ctrl ] |
| 49 |
choices: [ fast, strict ] |
| 50 |
resource_policy: |
| 51 |
description: Configuration container for Protocol Independent Multicast (PIM) resource policy. |
| 52 |
type: dict |
| 53 |
suboptions: |
| 54 |
maximum_limit: |
| 55 |
description: |
| 56 |
- The Max Multicast Entries. |
| 57 |
- The APIC defaults to C(unlimited) when unset during creation. |
| 58 |
- Specify C(0) to reset to C(unlimited). |
| 59 |
type: int |
| 60 |
aliases: [ max ] |
| 61 |
reserved_multicast_entries: |
| 62 |
description: |
| 63 |
- The Reserved Multicast Entries. |
| 64 |
- The APIC defaults to C(undefined) when unset during creation. |
| 65 |
- Required when C(reserved_route_map) is provided. |
| 66 |
type: int |
| 67 |
aliases: [ rsvd ] |
| 68 |
reserved_route_map: |
| 69 |
description: |
| 70 |
- The DN of the Route Map. |
| 71 |
- Specify C("") to remove the Route Map configuration. |
| 72 |
- Required when C(reserved_multicast_entries) is provided. |
| 73 |
type: str |
| 74 |
aliases: [ route_map, route_map_dn ] |
| 75 |
any_source_multicast: |
| 76 |
description: Configuration container for Protocol Independent Multicast (PIM) Any Source Multicast (ASM) settings. |
| 77 |
type: dict |
| 78 |
aliases: [ asm, any_source ] |
| 79 |
suboptions: |
| 80 |
shared_range_route_map: |
| 81 |
description: |
| 82 |
- The DN of the Route Map. |
| 83 |
- Specify C("") to remove the Route Map configuration. |
| 84 |
type: str |
| 85 |
aliases: [ shared_range_policy ] |
| 86 |
source_group_expiry_route_map: |
| 87 |
description: |
| 88 |
- The DN of the Route Map. |
| 89 |
- Specify C("") to remove the Route Map configuration. |
| 90 |
type: str |
| 91 |
aliases: [ sg_expiry_route_map ] |
| 92 |
expiry: |
| 93 |
description: |
| 94 |
- The expiry time in seconds. |
| 95 |
- The APIC defaults to C(default-timeout) when unset during creation. |
| 96 |
- Specify C(0) to reset to C(default-timeout). |
| 97 |
type: int |
| 98 |
aliases: [ expiry_seconds ] |
| 99 |
max_rate: |
| 100 |
description: |
| 101 |
- The maximum rate per second. |
| 102 |
- The APIC defaults to C(65535) when unset during creation. |
| 103 |
type: int |
| 104 |
aliases: [ max_rate_per_second ] |
| 105 |
source_ip: |
| 106 |
description: |
| 107 |
- The source IP address. |
| 108 |
type: str |
| 109 |
aliases: [ source, source_ip_address ] |
| 110 |
source_specific_multicast: |
| 111 |
description: Configuration container for Protocol Independent Multicast (PIM) Source Specific Multicast (SSM) settings. |
| 112 |
type: dict |
| 113 |
aliases: [ ssm, specific_source ] |
| 114 |
suboptions: |
| 115 |
group_range_route_map: |
| 116 |
description: |
| 117 |
- The DN of the Route Map. |
| 118 |
- Specify C("") to remove the Route Map configuration. |
| 119 |
type: str |
| 120 |
aliases: [ group_range_policy ] |
| 121 |
bootstrap_router: |
| 122 |
description: Configuration container for Protocol Independent Multicast (PIM) Bootstrap Router (BSR) settings. |
| 123 |
type: dict |
| 124 |
aliases: [ bsr, bootstrap ] |
| 125 |
suboptions: |
| 126 |
bsr_filter: |
| 127 |
description: |
| 128 |
- The DN of the Route Map. |
| 129 |
- Specify C("") to remove the Route Map configuration. |
| 130 |
type: str |
| 131 |
aliases: [ filter, route_map, route_map_dn ] |
| 132 |
rp_updates: |
| 133 |
description: |
| 134 |
- The control state of the Bootstrap Router (BSR) policy. |
| 135 |
- Specify C([]) to remove the control state configuration. |
| 136 |
type: list |
| 137 |
elements: str |
| 138 |
aliases: [ control, ctrl ] |
| 139 |
choices: [ forward, listen ] |
| 140 |
auto_rp: |
| 141 |
description: Configuration container for Protocol Independent Multicast (PIM) Auto-Rendezvous Point (Auto-RP) settings. |
| 142 |
type: dict |
| 143 |
aliases: [ auto ] |
| 144 |
suboptions: |
| 145 |
ma_filter: |
| 146 |
description: |
| 147 |
- The DN of the Route Map. |
| 148 |
- Specify C("") to remove the Route Map configuration. |
| 149 |
type: str |
| 150 |
aliases: [ filter, route_map, route_map_dn ] |
| 151 |
rp_updates: |
| 152 |
description: |
| 153 |
- The control state of the Auto-Rendezvous Point (Auto-RP) policy. |
| 154 |
- Specify C([]) to remove the control state configuration. |
| 155 |
type: list |
| 156 |
elements: str |
| 157 |
aliases: [ control, ctrl ] |
| 158 |
choices: [ forward, listen ] |
| 159 |
state: |
| 160 |
description: |
| 161 |
- Use C(present) or C(absent) for adding or removing. |
| 162 |
- Use C(query) for listing an object or multiple objects. |
| 163 |
type: str |
| 164 |
choices: [ absent, present, query ] |
| 165 |
default: present |
| 166 |
extends_documentation_fragment: |
| 167 |
- cisco.aci.aci |
| 168 |
- cisco.aci.annotation |
| 169 |
- cisco.aci.owner |
| 170 |
|
| 171 |
notes: |
| 172 |
- The I(tenant) and I(vrf) must exist before using this module in your playbook. |
| 173 |
The M(cisco.aci.aci_tenant) and M(cisco.aci.aci_vrf) modules can be used for this. |
| 174 |
seealso: |
| 175 |
- name: APIC Management Information Model reference |
| 176 |
description: More information about the internal APIC class B(pim:CtxP). |
| 177 |
link: https://developer.cisco.com/docs/apic-mim-ref/ |
| 178 |
author: |
| 179 |
- Tim Cragg (@timcragg) |
| 180 |
- Akini Ross (@akinross) |
| 181 |
""" |
| 182 |
|
| 183 |
EXAMPLES = r""" |
| 184 |
- name: Enable Multicast on a VRF |
| 185 |
cisco.aci.aci_vrf_multicast: |
| 186 |
host: apic |
| 187 |
username: admin |
| 188 |
password: SomeSecretePassword |
| 189 |
tenant: ansible_tenant |
| 190 |
vrf: ansible_vrf |
| 191 |
state: present |
| 192 |
delegate_to: localhost |
| 193 |
|
| 194 |
- name: Change Multicast PIM Settings on a VRF |
| 195 |
cisco.aci.aci_vrf_multicast: |
| 196 |
host: apic |
| 197 |
username: admin |
| 198 |
password: SomeSecretePassword |
| 199 |
tenant: ansible_tenant |
| 200 |
vrf: ansible_vrf |
| 201 |
pim_setting: |
| 202 |
mtu: 2000 |
| 203 |
control_state: [fast, strict] |
| 204 |
state: present |
| 205 |
delegate_to: localhost |
| 206 |
|
| 207 |
- name: Change Multicast Resource Policy on a VRF |
| 208 |
cisco.aci.aci_vrf_multicast: |
| 209 |
host: apic |
| 210 |
username: admin |
| 211 |
password: SomeSecretePassword |
| 212 |
tenant: ansible_tenant |
| 213 |
vrf: ansible_vrf |
| 214 |
resource_policy: |
| 215 |
maximum_limit: 100 |
| 216 |
reserved_multicast_entries: 20 |
| 217 |
reserved_route_map: uni/tn-ansible_test/rtmap-ansible_test |
| 218 |
state: present |
| 219 |
delegate_to: localhost |
| 220 |
|
| 221 |
- name: Remove Route-Map from Multicast Resource Policy on a VRF |
| 222 |
cisco.aci.aci_vrf_multicast: |
| 223 |
host: apic |
| 224 |
username: admin |
| 225 |
password: SomeSecretePassword |
| 226 |
tenant: ansible_tenant |
| 227 |
vrf: ansible_vrf |
| 228 |
resource_policy: |
| 229 |
reserved_route_map: "" |
| 230 |
state: present |
| 231 |
delegate_to: localhost |
| 232 |
|
| 233 |
- name: Change Multicast Any Source Multicast (ASM) Settings on a VRF |
| 234 |
cisco.aci.aci_vrf_multicast: |
| 235 |
host: apic |
| 236 |
username: admin |
| 237 |
password: SomeSecretePassword |
| 238 |
tenant: ansible_tenant |
| 239 |
vrf: ansible_vrf |
| 240 |
any_source_multicast: |
| 241 |
shared_range_route_map: uni/tn-ansible_test/rtmap-ansible_test |
| 242 |
source_group_expiry_route_map: uni/tn-ansible_test/rtmap-ansible_test |
| 243 |
expiry: 500 |
| 244 |
max_rate: 64000 |
| 245 |
source_ip: 1.1.1.1 |
| 246 |
state: present |
| 247 |
delegate_to: localhost |
| 248 |
|
| 249 |
- name: Change Multicast Source Specific Multicast (SSM) Settings on a VRF |
| 250 |
cisco.aci.aci_vrf_multicast: |
| 251 |
host: apic |
| 252 |
username: admin |
| 253 |
password: SomeSecretePassword |
| 254 |
tenant: ansible_tenant |
| 255 |
vrf: ansible_vrf |
| 256 |
source_specific_multicast: |
| 257 |
group_range_route_map: uni/tn-ansible_test/rtmap-ansible_test |
| 258 |
state: present |
| 259 |
delegate_to: localhost |
| 260 |
|
| 261 |
- name: Change Multicast Bootstrap Router (BSR) Settings on a VRF |
| 262 |
cisco.aci.aci_vrf_multicast: |
| 263 |
host: apic |
| 264 |
username: admin |
| 265 |
password: SomeSecretePassword |
| 266 |
tenant: ansible_tenant |
| 267 |
vrf: ansible_vrf |
| 268 |
bootstrap_router: |
| 269 |
bsr_filter: uni/tn-ansible_test/rtmap-ansible_test |
| 270 |
rp_updates: [forward, listen] |
| 271 |
state: present |
| 272 |
delegate_to: localhost |
| 273 |
|
| 274 |
- name: Change Multicast Auto-Rendezvous Point (Auto-RP) Settings on a VRF |
| 275 |
cisco.aci.aci_vrf_multicast: |
| 276 |
host: apic |
| 277 |
username: admin |
| 278 |
password: SomeSecretePassword |
| 279 |
tenant: ansible_tenant |
| 280 |
vrf: ansible_vrf |
| 281 |
auto_rp: |
| 282 |
ma_filter: uni/tn-ansible_test/rtmap-ansible_test |
| 283 |
rp_updates: [forward, listen] |
| 284 |
state: present |
| 285 |
delegate_to: localhost |
| 286 |
|
| 287 |
- name: Disable Multicast on a VRF |
| 288 |
cisco.aci.aci_vrf_multicast: |
| 289 |
host: apic |
| 290 |
username: admin |
| 291 |
password: SomeSecretePassword |
| 292 |
tenant: ansible_tenant |
| 293 |
vrf: ansible_vrf |
| 294 |
state: absent |
| 295 |
delegate_to: localhost |
| 296 |
|
| 297 |
- name: Query Multicast Settings for a VRF |
| 298 |
cisco.aci.aci_vrf_multicast: |
| 299 |
host: apic |
| 300 |
username: admin |
| 301 |
password: SomeSecretePassword |
| 302 |
tenant: ansible_tenant |
| 303 |
vrf: ansible_vrf |
| 304 |
state: query |
| 305 |
delegate_to: localhost |
| 306 |
register: query_result |
| 307 |
|
| 308 |
- name: Query Multicast Settings for all VRFs |
| 309 |
cisco.aci.aci_vrf_multicast: |
| 310 |
host: apic |
| 311 |
username: admin |
| 312 |
password: SomeSecretePassword |
| 313 |
state: query |
| 314 |
delegate_to: localhost |
| 315 |
register: query_result |
| 316 |
""" |
| 317 |
|
| 318 |
RETURN = r""" |
| 319 |
current: |
| 320 |
description: The existing configuration from the APIC after the module has finished |
| 321 |
returned: success |
| 322 |
type: list |
| 323 |
sample: |
| 324 |
[ |
| 325 |
{ |
| 326 |
"fvTenant": { |
| 327 |
"attributes": { |
| 328 |
"descr": "Production environment", |
| 329 |
"dn": "uni/tn-production", |
| 330 |
"name": "production", |
| 331 |
"nameAlias": "", |
| 332 |
"ownerKey": "", |
| 333 |
"ownerTag": "" |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
] |
| 338 |
error: |
| 339 |
description: The error information as returned from the APIC |
| 340 |
returned: failure |
| 341 |
type: dict |
| 342 |
sample: |
| 343 |
{ |
| 344 |
"code": "122", |
| 345 |
"text": "unknown managed object class foo" |
| 346 |
} |
| 347 |
raw: |
| 348 |
description: The raw output returned by the APIC REST API (xml or json) |
| 349 |
returned: parse error |
| 350 |
type: str |
| 351 |
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>' |
| 352 |
sent: |
| 353 |
description: The actual/minimal configuration pushed to the APIC |
| 354 |
returned: info |
| 355 |
type: list |
| 356 |
sample: |
| 357 |
{ |
| 358 |
"fvTenant": { |
| 359 |
"attributes": { |
| 360 |
"descr": "Production environment" |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
previous: |
| 365 |
description: The original configuration from the APIC before the module has started |
| 366 |
returned: info |
| 367 |
type: list |
| 368 |
sample: |
| 369 |
[ |
| 370 |
{ |
| 371 |
"fvTenant": { |
| 372 |
"attributes": { |
| 373 |
"descr": "Production", |
| 374 |
"dn": "uni/tn-production", |
| 375 |
"name": "production", |
| 376 |
"nameAlias": "", |
| 377 |
"ownerKey": "", |
| 378 |
"ownerTag": "" |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
] |
| 383 |
proposed: |
| 384 |
description: The assembled configuration from the user-provided parameters |
| 385 |
returned: info |
| 386 |
type: dict |
| 387 |
sample: |
| 388 |
{ |
| 389 |
"fvTenant": { |
| 390 |
"attributes": { |
| 391 |
"descr": "Production environment", |
| 392 |
"name": "production" |
| 393 |
} |
| 394 |
} |
| 395 |
} |
| 396 |
filter_string: |
| 397 |
description: The filter string used for the request |
| 398 |
returned: failure or debug |
| 399 |
type: str |
| 400 |
sample: ?rsp-prop-include=config-only |
| 401 |
method: |
| 402 |
description: The HTTP method used for the request to the APIC |
| 403 |
returned: failure or debug |
| 404 |
type: str |
| 405 |
sample: POST |
| 406 |
response: |
| 407 |
description: The HTTP response from the APIC |
| 408 |
returned: failure or debug |
| 409 |
type: str |
| 410 |
sample: OK (30 bytes) |
| 411 |
status: |
| 412 |
description: The HTTP status from the APIC |
| 413 |
returned: failure or debug |
| 414 |
type: int |
| 415 |
sample: 200 |
| 416 |
url: |
| 417 |
description: The HTTP url used for the request to the APIC |
| 418 |
returned: failure or debug |
| 419 |
type: str |
| 420 |
sample: https://10.11.12.13/api/mo/uni/tn-production.json |
| 421 |
""" |
| 422 |
|
| 423 |
from ansible.module_utils.basic import AnsibleModule |
| 424 |
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec |
| 425 |
from ansible_collections.cisco.aci.plugins.module_utils.constants import PIM_SETTING_CONTROL_STATE_MAPPING |
| 426 |
|
| 427 |
|
| 428 |
def main(): |
| 429 |
argument_spec = aci_argument_spec() |
| 430 |
argument_spec.update(aci_annotation_spec()) |
| 431 |
argument_spec.update(aci_owner_spec()) |
| 432 |
argument_spec.update( |
| 433 |
tenant=dict(type="str", aliases=["tenant_name"]), |
| 434 |
vrf=dict(type="str", aliases=["vrf_name"]), |
| 435 |
pim_setting=dict( |
| 436 |
type="dict", |
| 437 |
options=dict( |
| 438 |
mtu=dict(type="int"), |
| 439 |
control_state=dict(type="list", elements="str", choices=["fast", "strict"], aliases=["control", "ctrl"]), |
| 440 |
), |
| 441 |
), |
| 442 |
resource_policy=dict( |
| 443 |
type="dict", |
| 444 |
options=dict( |
| 445 |
maximum_limit=dict(type="int", aliases=["max"]), |
| 446 |
reserved_multicast_entries=dict(type="int", aliases=["rsvd"]), |
| 447 |
reserved_route_map=dict(type="str", aliases=["route_map", "route_map_dn"]), |
| 448 |
), |
| 449 |
), |
| 450 |
any_source_multicast=dict( |
| 451 |
type="dict", |
| 452 |
options=dict( |
| 453 |
shared_range_route_map=dict(type="str", aliases=["shared_range_policy"]), |
| 454 |
source_group_expiry_route_map=dict(type="str", aliases=["sg_expiry_route_map"]), |
| 455 |
expiry=(dict(type="int", aliases=["expiry_seconds"])), |
| 456 |
max_rate=(dict(type="int", aliases=["max_rate_per_second"])), |
| 457 |
source_ip=(dict(type="str", aliases=["source", "source_ip_address"])), |
| 458 |
), |
| 459 |
aliases=["asm", "any_source"], |
| 460 |
), |
| 461 |
source_specific_multicast=dict( |
| 462 |
type="dict", |
| 463 |
options=dict( |
| 464 |
group_range_route_map=dict(type="str", aliases=["group_range_policy"]), |
| 465 |
), |
| 466 |
aliases=["ssm", "specific_source"], |
| 467 |
), |
| 468 |
bootstrap_router=dict( |
| 469 |
type="dict", |
| 470 |
options=dict( |
| 471 |
bsr_filter=dict(type="str", aliases=["filter", "route_map", "route_map_dn"]), |
| 472 |
rp_updates=dict(type="list", elements="str", choices=["forward", "listen"], aliases=["control", "ctrl"]), |
| 473 |
), |
| 474 |
aliases=["bsr", "bootstrap"], |
| 475 |
), |
| 476 |
auto_rp=dict( |
| 477 |
type="dict", |
| 478 |
options=dict( |
| 479 |
ma_filter=dict(type="str", aliases=["filter", "route_map", "route_map_dn"]), |
| 480 |
rp_updates=dict(type="list", elements="str", choices=["forward", "listen"], aliases=["control", "ctrl"]), |
| 481 |
), |
| 482 |
aliases=["auto"], |
| 483 |
), |
| 484 |
state=dict(type="str", default="present", choices=["absent", "present", "query"]), |
| 485 |
) |
| 486 |
|
| 487 |
module = AnsibleModule( |
| 488 |
argument_spec=argument_spec, |
| 489 |
supports_check_mode=True, |
| 490 |
required_if=[ |
| 491 |
["state", "absent", ["tenant", "vrf"]], |
| 492 |
["state", "present", ["tenant", "vrf"]], |
| 493 |
], |
| 494 |
) |
| 495 |
|
| 496 |
aci = ACIModule(module) |
| 497 |
|
| 498 |
tenant = module.params.get("tenant") |
| 499 |
vrf = module.params.get("vrf") |
| 500 |
pim_setting = module.params.get("pim_setting") |
| 501 |
resource_policy = module.params.get("resource_policy") |
| 502 |
any_source_multicast = module.params.get("any_source_multicast") |
| 503 |
source_specific_multicast = module.params.get("source_specific_multicast") |
| 504 |
bootstrap_router = module.params.get("bootstrap_router") |
| 505 |
auto_rp = module.params.get("auto_rp") |
| 506 |
state = module.params.get("state") |
| 507 |
|
| 508 |
if resource_policy and resource_policy.get("reserved_multicast_entries") and resource_policy.get("reserved_route_map") is None: |
| 509 |
aci.fail_json(msg="C(reserved_route_map) must be provided when C(reserved_multicast_entries) are provided") |
| 510 |
elif resource_policy and resource_policy.get("reserved_route_map") and not resource_policy.get("reserved_multicast_entries"): |
| 511 |
aci.fail_json(msg="C(reserved_multicast_entries) must be provided and greater than 0 when C(reserved_route_map) is provided") |
| 512 |
|
| 513 |
aci.construct_url( |
| 514 |
root_class=dict( |
| 515 |
aci_class="fvTenant", |
| 516 |
aci_rn="tn-{0}".format(tenant), |
| 517 |
module_object=tenant, |
| 518 |
target_filter={"name": tenant}, |
| 519 |
), |
| 520 |
subclass_1=dict( |
| 521 |
aci_class="fvCtx", |
| 522 |
aci_rn="ctx-{0}".format(vrf), |
| 523 |
module_object=vrf, |
| 524 |
target_filter={"name": vrf}, |
| 525 |
), |
| 526 |
subclass_2=dict( |
| 527 |
aci_class="pimCtxP", |
| 528 |
aci_rn="pimctxp", |
| 529 |
target_filter={"name": ""}, |
| 530 |
), |
| 531 |
child_classes=["pimResPol", "pimASMPatPol", "pimSSMPatPol", "pimAutoRPPol", "pimBSRPPol"], |
| 532 |
) |
| 533 |
|
| 534 |
aci.get_existing() |
| 535 |
|
| 536 |
if state == "present": |
| 537 |
existing_config = aci.existing[0] if aci.existing else {} |
| 538 |
child_configs = [] |
| 539 |
|
| 540 |
resource_policy_config = dict(pimResPol=dict(attributes=dict(name=""), children=[])) |
| 541 |
if resource_policy: |
| 542 |
max = "unlimited" if resource_policy.get("maximum_limit") == 0 else resource_policy.get("maximum_limit") |
| 543 |
if max is not None: |
| 544 |
resource_policy_config["pimResPol"]["attributes"]["max"] = str(max) |
| 545 |
|
| 546 |
reserved_route_map = resource_policy.get("reserved_route_map") |
| 547 |
if reserved_route_map is not None: |
| 548 |
existing_rrm = get_child_from_existing_config(existing_config, ["pimCtxP", "pimResPol", "rtdmcRsFilterToRtMapPol"]) |
| 549 |
rsvd = resource_policy.get("reserved_multicast_entries") |
| 550 |
|
| 551 |
if (existing_rrm or reserved_route_map != "") and rsvd: |
| 552 |
resource_policy_config["pimResPol"]["attributes"]["rsvd"] = str(rsvd) |
| 553 |
elif existing_rrm and reserved_route_map == "": |
| 554 |
resource_policy_config["pimResPol"]["attributes"]["rsvd"] = "undefined" |
| 555 |
|
| 556 |
set_route_map_config( |
| 557 |
existing_config, |
| 558 |
resource_policy_config["pimResPol"]["children"], |
| 559 |
["pimCtxP", "pimResPol", "rtdmcRsFilterToRtMapPol"], |
| 560 |
reserved_route_map, |
| 561 |
) |
| 562 |
|
| 563 |
child_configs.append(resource_policy_config) |
| 564 |
|
| 565 |
any_source_multicast_config = dict( |
| 566 |
pimASMPatPol=dict( |
| 567 |
attributes=dict(name=""), |
| 568 |
children=[ |
| 569 |
dict(pimSharedRangePol=dict(attributes=dict(name=""), children=[])), |
| 570 |
dict(pimSGRangeExpPol=dict(attributes=dict(name=""), children=[])), |
| 571 |
dict(pimRegTrPol=dict(attributes=dict(name=""), children=[])), |
| 572 |
], |
| 573 |
) |
| 574 |
) |
| 575 |
if any_source_multicast: |
| 576 |
if any_source_multicast.get("shared_range_route_map") is not None: |
| 577 |
set_route_map_config( |
| 578 |
existing_config, |
| 579 |
any_source_multicast_config["pimASMPatPol"]["children"][0]["pimSharedRangePol"]["children"], |
| 580 |
["pimCtxP", "pimASMPatPol", "pimSharedRangePol", "rtdmcRsFilterToRtMapPol"], |
| 581 |
any_source_multicast.get("shared_range_route_map"), |
| 582 |
) |
| 583 |
|
| 584 |
if any_source_multicast.get("source_group_expiry_route_map") is not None: |
| 585 |
set_route_map_config( |
| 586 |
existing_config, |
| 587 |
any_source_multicast_config["pimASMPatPol"]["children"][1]["pimSGRangeExpPol"]["children"], |
| 588 |
["pimCtxP", "pimASMPatPol", "pimSGRangeExpPol", "rtdmcRsFilterToRtMapPol"], |
| 589 |
any_source_multicast.get("source_group_expiry_route_map"), |
| 590 |
) |
| 591 |
|
| 592 |
expiry = any_source_multicast.get("expiry") |
| 593 |
if expiry is not None: |
| 594 |
sg_expiry_config = "default-timeout" if any_source_multicast.get("expiry") == 0 else any_source_multicast.get("expiry") |
| 595 |
any_source_multicast_config["pimASMPatPol"]["children"][1]["pimSGRangeExpPol"]["attributes"]["sgExpItvl"] = str(sg_expiry_config) |
| 596 |
|
| 597 |
if any_source_multicast.get("max_rate") is not None: |
| 598 |
any_source_multicast_config["pimASMPatPol"]["children"][2]["pimRegTrPol"]["attributes"]["maxRate"] = str(any_source_multicast.get("max_rate")) |
| 599 |
|
| 600 |
if any_source_multicast.get("source_ip") is not None: |
| 601 |
any_source_multicast_config["pimASMPatPol"]["children"][2]["pimRegTrPol"]["attributes"]["srcIp"] = any_source_multicast.get("source_ip") |
| 602 |
|
| 603 |
child_configs.append(any_source_multicast_config) |
| 604 |
|
| 605 |
source_specific_multicast_config = dict( |
| 606 |
pimSSMPatPol=dict( |
| 607 |
attributes=dict(name=""), |
| 608 |
children=[ |
| 609 |
dict(pimSSMRangePol=dict(attributes=dict(name=""), children=[])), |
| 610 |
], |
| 611 |
) |
| 612 |
) |
| 613 |
if source_specific_multicast and source_specific_multicast.get("group_range_route_map") is not None: |
| 614 |
set_route_map_config( |
| 615 |
existing_config, |
| 616 |
source_specific_multicast_config["pimSSMPatPol"]["children"][0]["pimSSMRangePol"]["children"], |
| 617 |
["pimCtxP", "pimSSMPatPol", "pimSSMRangePol", "rtdmcRsFilterToRtMapPol"], |
| 618 |
source_specific_multicast.get("group_range_route_map"), |
| 619 |
) |
| 620 |
|
| 621 |
child_configs.append(source_specific_multicast_config) |
| 622 |
|
| 623 |
if bootstrap_router: |
| 624 |
bsr_config = dict(pimBSRPPol=dict(attributes=dict(name=""), children=[dict(pimBSRFilterPol=dict(attributes=dict(name=""), children=[]))])) |
| 625 |
if bootstrap_router.get("bsr_filter") is not None: |
| 626 |
set_route_map_config( |
| 627 |
existing_config, |
| 628 |
bsr_config["pimBSRPPol"]["children"][0]["pimBSRFilterPol"]["children"], |
| 629 |
["pimCtxP", "pimBSRPPol", "pimBSRFilterPol", "rtdmcRsFilterToRtMapPol"], |
| 630 |
bootstrap_router.get("bsr_filter"), |
| 631 |
) |
| 632 |
|
| 633 |
rp_updates = bootstrap_router.get("rp_updates") |
| 634 |
if rp_updates is not None: |
| 635 |
bsr_config["pimBSRPPol"]["attributes"]["ctrl"] = ",".join(sorted(rp_updates)) |
| 636 |
|
| 637 |
child_configs.append(bsr_config) |
| 638 |
|
| 639 |
if auto_rp: |
| 640 |
auto_rp_config = dict(pimAutoRPPol=dict(attributes=dict(name=""), children=[dict(pimMAFilterPol=dict(attributes=dict(name=""), children=[]))])) |
| 641 |
|
| 642 |
if auto_rp.get("ma_filter") is not None: |
| 643 |
set_route_map_config( |
| 644 |
existing_config, |
| 645 |
auto_rp_config["pimAutoRPPol"]["children"][0]["pimMAFilterPol"]["children"], |
| 646 |
["pimCtxP", "pimAutoRPPol", "pimMAFilterPol", "rtdmcRsFilterToRtMapPol"], |
| 647 |
auto_rp.get("ma_filter"), |
| 648 |
) |
| 649 |
|
| 650 |
rp_updates = auto_rp.get("rp_updates") |
| 651 |
if rp_updates is not None: |
| 652 |
auto_rp_config["pimAutoRPPol"]["attributes"]["ctrl"] = ",".join(sorted(rp_updates)) |
| 653 |
|
| 654 |
child_configs.append(auto_rp_config) |
| 655 |
|
| 656 |
mtu = None |
| 657 |
control_state = None |
| 658 |
if pim_setting: |
| 659 |
mtu = pim_setting.get("mtu") |
| 660 |
control_state = ( |
| 661 |
",".join(sorted([PIM_SETTING_CONTROL_STATE_MAPPING.get(v) for v in pim_setting.get("control_state")])) |
| 662 |
if pim_setting.get("control_state") is not None |
| 663 |
else None |
| 664 |
) |
| 665 |
|
| 666 |
aci.payload( |
| 667 |
aci_class="pimCtxP", |
| 668 |
class_config=dict(mtu=mtu, ctrl=control_state), |
| 669 |
child_configs=child_configs, |
| 670 |
) |
| 671 |
|
| 672 |
aci.get_diff(aci_class="pimCtxP") |
| 673 |
|
| 674 |
aci.post_config() |
| 675 |
|
| 676 |
elif state == "absent": |
| 677 |
aci.delete_config() |
| 678 |
|
| 679 |
aci.exit_json() |
| 680 |
|
| 681 |
|
| 682 |
def get_child_from_existing_config(config, class_names): |
| 683 |
parent = class_names[0] |
| 684 |
class_names.remove(parent) |
| 685 |
|
| 686 |
for child in config.get(parent, {}).get("children", []): |
| 687 |
if len(class_names) == 1 and class_names[0] in child.keys(): |
| 688 |
return child |
| 689 |
elif child.get(class_names[0], {}).get("children"): |
| 690 |
return get_child_from_existing_config(child, class_names) |
| 691 |
|
| 692 |
|
| 693 |
def set_route_map_config(existing_config, new_config, class_names, route_map): |
| 694 |
existing_route_map = get_child_from_existing_config(existing_config, class_names) |
| 695 |
if route_map == "" and existing_route_map: |
| 696 |
new_config.append(dict(rtdmcRsFilterToRtMapPol=dict(attributes=dict(tDn=route_map, status="deleted")))) |
| 697 |
elif route_map: |
| 698 |
new_config.append(dict(rtdmcRsFilterToRtMapPol=dict(attributes=dict(tDn=route_map)))) |
| 699 |
|
| 700 |
|
| 701 |
if __name__ == "__main__": |
| 702 |
main() |