| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2024, Anvitha Jain (@anvjain) <[email protected]> |
| 5 |
|
| 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: ndo_tenant_igmp_interface_policy |
| 17 |
short_description: Manage Internet Group Management Protocol (IGMP) Interface Policies in Tenant Policy Templates on Cisco Nexus Dashboard Orchestrator (NDO). |
| 18 |
description: |
| 19 |
- Manage IGMP Interface Policies in Tenant Policy Templates on Cisco Nexus Dashboard Orchestrator (NDO). |
| 20 |
- This module is only supported on ND v3.1 (NDO v4.3) and later. |
| 21 |
author: |
| 22 |
- Anvitha Jain (@anvjain) |
| 23 |
options: |
| 24 |
template: |
| 25 |
description: |
| 26 |
- The name of the tenant template. |
| 27 |
- This parameter or O(template_id) is required. |
| 28 |
type: str |
| 29 |
aliases: [ tenant_template ] |
| 30 |
required: true |
| 31 |
template_id: |
| 32 |
description: |
| 33 |
- The ID of the L3Out template. |
| 34 |
- This parameter or O(template) is required. |
| 35 |
type: str |
| 36 |
aliases: [ l3out_template_id ] |
| 37 |
name: |
| 38 |
description: |
| 39 |
- The name of the IGMP Interface Policy. |
| 40 |
type: str |
| 41 |
aliases: [ igmp_interface_policy ] |
| 42 |
uuid: |
| 43 |
description: |
| 44 |
- The UUID of the IGMP Interface Policy. |
| 45 |
- This parameter is required when the IGMP Interface Policy O(name) needs to be updated. |
| 46 |
type: str |
| 47 |
aliases: [ igmp_interface_policy_uuid ] |
| 48 |
description: |
| 49 |
description: |
| 50 |
- The description of the IGMP Interface Policy. |
| 51 |
- Providing an empty string will remove the O(description="") from the IGMP Interface Policy. |
| 52 |
type: str |
| 53 |
version3_asm: |
| 54 |
description: |
| 55 |
- Enable or disable IGMP version 3 ASM. |
| 56 |
- Defaults to C(disabled) when unset during creation. |
| 57 |
type: str |
| 58 |
choices: [ enabled, disabled ] |
| 59 |
aliases: [ allow_version3_asm ] |
| 60 |
fast_leave: |
| 61 |
description: |
| 62 |
- Enable or disable fast leave. |
| 63 |
- Defaults to C(disabled) when unset during creation. |
| 64 |
type: str |
| 65 |
choices: [ enabled, disabled ] |
| 66 |
report_link_local_groups: |
| 67 |
description: |
| 68 |
- Enable or disable reporting link-local groups. |
| 69 |
- Defaults to C(disabled) when unset during creation. |
| 70 |
type: str |
| 71 |
choices: [ enabled, disabled ] |
| 72 |
igmp_version: |
| 73 |
description: |
| 74 |
- The IGMP version of the IGMP Interface Policy. |
| 75 |
- Defaults to C(v2) when unset during creation. |
| 76 |
type: str |
| 77 |
choices: [ v2, v3 ] |
| 78 |
group_timeout: |
| 79 |
description: |
| 80 |
- The group timeout value in seconds. |
| 81 |
- Defaults to 260 when unset during creation. |
| 82 |
- The valid range is from 3 to 65535. |
| 83 |
type: int |
| 84 |
query_interval: |
| 85 |
description: |
| 86 |
- The query interval value in seconds. |
| 87 |
- Defaults to 125 when unset during creation. |
| 88 |
- The valid range is from 1 to 18000. |
| 89 |
type: int |
| 90 |
query_response_interval: |
| 91 |
description: |
| 92 |
- The query response interval value in seconds. |
| 93 |
- Defaults to 10 when unset during creation. |
| 94 |
- The valid range is from 1 to 25. |
| 95 |
type: int |
| 96 |
last_member_count: |
| 97 |
description: |
| 98 |
- The last member query count value. |
| 99 |
- Defaults to 2 when unset during creation. |
| 100 |
- The valid range is from 1 to 5. |
| 101 |
type: int |
| 102 |
last_member_response_time: |
| 103 |
description: |
| 104 |
- The last member query response time value in seconds. |
| 105 |
- Defaults to 1 when unset during creation. |
| 106 |
- The valid range is from 1 to 25. |
| 107 |
type: int |
| 108 |
startup_query_count: |
| 109 |
description: |
| 110 |
- The startup query count value. |
| 111 |
- Defaults to 2 when unset during creation. |
| 112 |
- The valid range is from 1 to 10. |
| 113 |
type: int |
| 114 |
startup_query_interval: |
| 115 |
description: |
| 116 |
- The startup query interval value in seconds. |
| 117 |
- Defaults to 31 when unset during creation. |
| 118 |
- The valid range is from 1 to 18000. |
| 119 |
type: int |
| 120 |
querier_timeout: |
| 121 |
description: |
| 122 |
- The querier timeout value in seconds. |
| 123 |
- Defaults to 255 when unset during creation. |
| 124 |
- The valid range is from 1 to 65535. |
| 125 |
type: int |
| 126 |
robustness_variable: |
| 127 |
description: |
| 128 |
- The robustness variable value. |
| 129 |
- Defaults to 2 when unset during creation. |
| 130 |
- The valid range is from 1 to 7. |
| 131 |
type: int |
| 132 |
state_limit_route_map_uuid: |
| 133 |
description: |
| 134 |
- The UUID of the state limit route map. |
| 135 |
- Providing an empty string will remove the O(state_limit_route_map_uuid="") from IGMP Interface Policy. |
| 136 |
type: str |
| 137 |
aliases: [ state_limit_route_map_for_multicast ] |
| 138 |
state_limit_route_map: |
| 139 |
description: |
| 140 |
- The Route Map Policy for Multicast. |
| 141 |
- This parameter can be used instead of O(state_limit_route_map_uuid). |
| 142 |
- If both parameter are used, O(state_limit_route_map) will be ignored. |
| 143 |
- Providing an empty map will remove the O(state_limit_route_map={}) from IGMP Interface Policy. |
| 144 |
type: dict |
| 145 |
suboptions: |
| 146 |
name: |
| 147 |
description: |
| 148 |
- The name of the Route Map Policy for Multicast. |
| 149 |
type: str |
| 150 |
aliases: [ state_limit_route_map_policy, state_limit_route_map_policy_multicast ] |
| 151 |
report_policy_route_map_uuid: |
| 152 |
description: |
| 153 |
- The UUID of the report policy route map. |
| 154 |
- Providing an empty string will remove the O(report_policy_route_map_uuid="") from IGMP Interface Policy. |
| 155 |
type: str |
| 156 |
aliases: [ report_policy_route_map_for_multicast ] |
| 157 |
report_policy_route_map: |
| 158 |
description: |
| 159 |
- The Route Map Policy for Multicast. |
| 160 |
- This parameter can be used instead of O(report_policy_route_map_uuid). |
| 161 |
- If both parameter are used, O(report_policy_route_map) will be ignored. |
| 162 |
- Providing an empty map will remove the O(report_policy_route_map={}) from IGMP Interface Policy. |
| 163 |
type: dict |
| 164 |
suboptions: |
| 165 |
name: |
| 166 |
description: |
| 167 |
- The name of the Route Map Policy for Multicast. |
| 168 |
type: str |
| 169 |
aliases: [ report_policy_route_map_policy, report_policy_route_map_policy_multicast ] |
| 170 |
static_report_route_map_uuid: |
| 171 |
description: |
| 172 |
- The UUID of the static report route map. |
| 173 |
- Providing an empty string will remove the O(static_report_route_map_uuid="") from IGMP Interface Policy. |
| 174 |
type: str |
| 175 |
aliases: [ static_report_route_map_for_multicast ] |
| 176 |
static_report_route_map: |
| 177 |
description: |
| 178 |
- The Route Map Policy for Multicast. |
| 179 |
- This parameter can be used instead of O(static_report_route_map_uuid). |
| 180 |
- If both parameter are used, O(static_report_route_map) will be ignored. |
| 181 |
- Providing an empty map will remove the O(static_report_route_map={}) from IGMP Interface Policy. |
| 182 |
type: dict |
| 183 |
suboptions: |
| 184 |
name: |
| 185 |
description: |
| 186 |
- The name of the Route Map Policy for Multicast. |
| 187 |
type: str |
| 188 |
aliases: [ static_report_route_map_policy, static_report_route_map_policy_multicast ] |
| 189 |
maximum_multicast_entries: |
| 190 |
description: |
| 191 |
- The maximum multicast entries value. |
| 192 |
- Defaults to 4294967295 when unset during creation. |
| 193 |
- The valid range is from 1 to 4294967295. |
| 194 |
- This parameter is only applicable when the O(state_limit_route_map_uuid) or O(state_limit_route_map) is not empty. |
| 195 |
type: int |
| 196 |
reserved_multicast_entries: |
| 197 |
description: |
| 198 |
- The reserved multicast entries value. |
| 199 |
- Defaults to 0 when unset during creation. |
| 200 |
- The valid range is from 0 to 4294967295. |
| 201 |
type: int |
| 202 |
state: |
| 203 |
description: |
| 204 |
- Use C(absent) for removing. |
| 205 |
- Use C(query) for listing an object or multiple objects. |
| 206 |
- Use C(present) for creating or updating. |
| 207 |
type: str |
| 208 |
choices: [ absent, query, present ] |
| 209 |
default: query |
| 210 |
notes: |
| 211 |
- The O(template) must exist before using this module in your playbook. |
| 212 |
Use M(cisco.mso.ndo_template) to create the Tenant template. |
| 213 |
- The O(state_limit_route_map_uuid) or O(state_limit_route_map) requires Route Map Policy for Multicast. |
| 214 |
The O(report_policy_route_map_uuid) or O(report_policy_route_map) requires Route Map Policy for Multicast. |
| 215 |
The O(static_report_route_map_uuid) or O(static_report_route_map) requires Route Map Policy for Multicast. |
| 216 |
Use M(cisco.mso.ndo_route_map_policy_multicast) to create the Route Map Policy for Multicast. |
| 217 |
seealso: |
| 218 |
- module: cisco.mso.ndo_template |
| 219 |
- module: cisco.mso.ndo_route_map_policy_multicast |
| 220 |
extends_documentation_fragment: cisco.mso.modules |
| 221 |
""" |
| 222 |
|
| 223 |
EXAMPLES = r""" |
| 224 |
- name: Create an IGMP Interface Policy |
| 225 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 226 |
template: ansible_tenant_template |
| 227 |
name: test_igmp_interface_policy |
| 228 |
description: Test Description |
| 229 |
version3_asm: enabled |
| 230 |
fast_leave: enabled |
| 231 |
report_link_local_groups: enabled |
| 232 |
igmp_version: v3 |
| 233 |
group_timeout: 260 |
| 234 |
query_interval: 125 |
| 235 |
query_response_interval: 10 |
| 236 |
last_member_count: 2 |
| 237 |
last_member_response_time: 1 |
| 238 |
startup_query_count: 2 |
| 239 |
startup_query_interval: 31 |
| 240 |
querier_timeout: 255 |
| 241 |
robustness_variable: 2 |
| 242 |
state_limit_route_map_uuid: "2be2b2e6-727d-4534-9d09-4abc36ed0194" |
| 243 |
report_policy_route_map_uuid: "{{ route_map_policy_for_multicast.current.uuid }}" |
| 244 |
static_report_route_map: |
| 245 |
name: TestStaticReportRouteMap |
| 246 |
maximum_multicast_entries: 4294967295 |
| 247 |
reserved_multicast_entries: 4294967 |
| 248 |
state: present |
| 249 |
register: igmp_interface_policy |
| 250 |
|
| 251 |
- name: Update an IGMP Interface Policy name with the UUID |
| 252 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 253 |
host: mso_host |
| 254 |
username: admin |
| 255 |
password: SomeSecretPassword |
| 256 |
template: ansible_tenant_template |
| 257 |
name: test_igmp_interface_policy_updated |
| 258 |
uuid: "{{ igmp_interface_policy.current.uuid }}" |
| 259 |
state: present |
| 260 |
register: igmp_interface_policy_update |
| 261 |
|
| 262 |
- name: Query an IGMP Interface Policy with the name |
| 263 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 264 |
host: mso_host |
| 265 |
username: admin |
| 266 |
password: SomeSecretPassword |
| 267 |
template: ansible_tenant_template |
| 268 |
name: test_igmp_interface_policy |
| 269 |
state: query |
| 270 |
register: query |
| 271 |
|
| 272 |
- name: Query an IGMP Interface Policy with the UUID |
| 273 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 274 |
host: mso_host |
| 275 |
username: admin |
| 276 |
password: SomeSecretPassword |
| 277 |
template: ansible_tenant_template |
| 278 |
uuid: "{{ igmp_interface_policy.current.uuid }}" |
| 279 |
state: query |
| 280 |
register: query_uuid |
| 281 |
|
| 282 |
- name: Query all IGMP Interface Policies in the template |
| 283 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 284 |
host: mso_host |
| 285 |
username: admin |
| 286 |
password: SomeSecretPassword |
| 287 |
template: ansible_tenant_template |
| 288 |
state: query |
| 289 |
register: query_all |
| 290 |
|
| 291 |
- name: Delete an IGMP Interface Policy with the name |
| 292 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 293 |
host: mso_host |
| 294 |
username: admin |
| 295 |
password: SomeSecretPassword |
| 296 |
template: ansible_tenant_template |
| 297 |
name: test_igmp_interface_policy |
| 298 |
state: absent |
| 299 |
|
| 300 |
- name: Delete an IGMP Interface Policy with the UUID |
| 301 |
cisco.mso.ndo_tenant_igmp_interface_policy: |
| 302 |
host: mso_host |
| 303 |
username: admin |
| 304 |
password: SomeSecretPassword |
| 305 |
template: ansible_tenant_template |
| 306 |
uuid: "{{ igmp_interface_policy.current.uuid }}" |
| 307 |
state: absent |
| 308 |
""" |
| 309 |
|
| 310 |
RETURN = r""" |
| 311 |
""" |
| 312 |
|
| 313 |
import copy |
| 314 |
from ansible.module_utils.basic import AnsibleModule |
| 315 |
from ansible_collections.cisco.mso.plugins.module_utils.mso import MSOModule, mso_argument_spec |
| 316 |
from ansible_collections.cisco.mso.plugins.module_utils.template import MSOTemplate, KVPair |
| 317 |
from ansible_collections.cisco.mso.plugins.module_utils.constants import ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP |
| 318 |
from ansible_collections.cisco.mso.plugins.module_utils.utils import ( |
| 319 |
append_update_ops_data, |
| 320 |
check_if_all_elements_are_none, |
| 321 |
) |
| 322 |
|
| 323 |
|
| 324 |
def main(): |
| 325 |
argument_spec = mso_argument_spec() |
| 326 |
argument_spec.update( |
| 327 |
template=dict(type="str", required=True, aliases=["tenant_template"]), |
| 328 |
template_id=dict(type="str", aliases=["l3out_template_id"]), |
| 329 |
name=dict(type="str", aliases=["igmp_interface_policy"]), |
| 330 |
uuid=dict(type="str", aliases=["igmp_interface_policy_uuid"]), |
| 331 |
description=dict(type="str"), |
| 332 |
version3_asm=dict(type="str", aliases=["allow_version3_asm"], choices=["enabled", "disabled"]), |
| 333 |
fast_leave=dict(type="str", choices=["enabled", "disabled"]), |
| 334 |
report_link_local_groups=dict(type="str", choices=["enabled", "disabled"]), |
| 335 |
igmp_version=dict(type="str", choices=["v2", "v3"]), |
| 336 |
group_timeout=dict(type="int"), |
| 337 |
query_interval=dict(type="int"), |
| 338 |
query_response_interval=dict(type="int"), |
| 339 |
last_member_count=dict(type="int"), |
| 340 |
last_member_response_time=dict(type="int"), |
| 341 |
startup_query_count=dict(type="int"), |
| 342 |
startup_query_interval=dict(type="int"), |
| 343 |
querier_timeout=dict(type="int"), |
| 344 |
robustness_variable=dict(type="int"), |
| 345 |
state_limit_route_map_uuid=dict(type="str", aliases=["state_limit_route_map_for_multicast"]), |
| 346 |
state_limit_route_map=dict( |
| 347 |
type="dict", |
| 348 |
options=dict( |
| 349 |
name=dict(type="str"), |
| 350 |
), |
| 351 |
aliases=["state_limit_route_map_policy", "state_limit_route_map_policy_multicast"], |
| 352 |
), |
| 353 |
report_policy_route_map_uuid=dict(type="str", aliases=["report_policy_route_map_for_multicast"]), |
| 354 |
report_policy_route_map=dict( |
| 355 |
type="dict", |
| 356 |
options=dict( |
| 357 |
name=dict(type="str"), |
| 358 |
), |
| 359 |
aliases=["report_policy_route_map_policy", "report_policy_route_map_policy_multicast"], |
| 360 |
), |
| 361 |
static_report_route_map_uuid=dict(type="str", aliases=["static_report_route_map_for_multicast"]), |
| 362 |
static_report_route_map=dict( |
| 363 |
type="dict", |
| 364 |
options=dict( |
| 365 |
name=dict(type="str"), |
| 366 |
), |
| 367 |
aliases=["static_report_route_map_policy", "static_report_route_map_policy_multicast"], |
| 368 |
), |
| 369 |
maximum_multicast_entries=dict(type="int"), |
| 370 |
reserved_multicast_entries=dict(type="int"), |
| 371 |
state=dict(type="str", default="query", choices=["absent", "query", "present"]), |
| 372 |
) |
| 373 |
|
| 374 |
module = AnsibleModule( |
| 375 |
argument_spec=argument_spec, |
| 376 |
supports_check_mode=True, |
| 377 |
required_if=[ |
| 378 |
["state", "absent", ["name", "uuid"], True], |
| 379 |
["state", "present", ["name", "uuid"], True], |
| 380 |
], |
| 381 |
mutually_exclusive=[ |
| 382 |
["template", "template_id"], |
| 383 |
["state_limit_route_map_uuid", "state_limit_route_map"], |
| 384 |
["report_policy_route_map_uuid", "report_policy_route_map"], |
| 385 |
["static_report_route_map_uuid", "static_report_route_map"], |
| 386 |
], |
| 387 |
required_one_of=[ |
| 388 |
["template", "template_id"], |
| 389 |
], |
| 390 |
) |
| 391 |
|
| 392 |
mso = MSOModule(module) |
| 393 |
|
| 394 |
template = module.params.get("template") |
| 395 |
template_id = module.params.get("template_id") |
| 396 |
name = module.params.get("name") |
| 397 |
uuid = module.params.get("uuid") |
| 398 |
description = module.params.get("description") |
| 399 |
version3_asm = ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(module.params.get("version3_asm")) |
| 400 |
fast_leave = ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(module.params.get("fast_leave")) |
| 401 |
report_link_local_groups = ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(module.params.get("report_link_local_groups")) |
| 402 |
igmp_version = module.params.get("igmp_version") |
| 403 |
group_timeout = module.params.get("group_timeout") |
| 404 |
query_interval = module.params.get("query_interval") |
| 405 |
query_response_interval = module.params.get("query_response_interval") |
| 406 |
last_member_count = module.params.get("last_member_count") |
| 407 |
last_member_response_time = module.params.get("last_member_response_time") |
| 408 |
startup_query_count = module.params.get("startup_query_count") |
| 409 |
startup_query_interval = module.params.get("startup_query_interval") |
| 410 |
querier_timeout = module.params.get("querier_timeout") |
| 411 |
robustness_variable = module.params.get("robustness_variable") |
| 412 |
state_limit_route_map_uuid = module.params.get("state_limit_route_map_uuid") |
| 413 |
state_limit_route_map = module.params.get("state_limit_route_map") |
| 414 |
report_policy_route_map_uuid = module.params.get("report_policy_route_map_uuid") |
| 415 |
report_policy_route_map = module.params.get("report_policy_route_map") |
| 416 |
static_report_route_map_uuid = module.params.get("static_report_route_map_uuid") |
| 417 |
static_report_route_map = module.params.get("static_report_route_map") |
| 418 |
maximum_multicast_entries = module.params.get("maximum_multicast_entries") |
| 419 |
reserved_multicast_entries = module.params.get("reserved_multicast_entries") |
| 420 |
state = module.params.get("state") |
| 421 |
|
| 422 |
mso_template = MSOTemplate(mso, "tenant", template, template_id) |
| 423 |
mso_template.validate_template("tenantPolicy") |
| 424 |
ops = [] |
| 425 |
empty_state_limit_route_map = False |
| 426 |
empty_report_policy_route_map = False |
| 427 |
empty_static_report_route_map = False |
| 428 |
|
| 429 |
existing_igmp_interface_policies = mso_template.template.get("tenantPolicyTemplate", {}).get("template", {}).get("igmpInterfacePolicies", []) |
| 430 |
object_description = "IGMP Interface Policy" |
| 431 |
path = "/tenantPolicyTemplate/template/igmpInterfacePolicies" |
| 432 |
|
| 433 |
reference_dict = { |
| 434 |
"stateLimitRouteMap": {"name": "stateLimitRouteMapName", "reference": "stateLimitRouteMapRef", "type": "mcastRouteMap"}, |
| 435 |
"reportPolicyRouteMap": {"name": "reportPolicyRouteMapName", "reference": "reportPolicyRouteMapRef", "type": "mcastRouteMap"}, |
| 436 |
"staticReportRouteMap": {"name": "staticReportRouteMapName", "reference": "staticReportRouteMapRef", "type": "mcastRouteMap"}, |
| 437 |
} |
| 438 |
|
| 439 |
if uuid or name: |
| 440 |
match = mso_template.get_object_by_key_value_pairs( |
| 441 |
object_description, |
| 442 |
existing_igmp_interface_policies, |
| 443 |
[KVPair("uuid", uuid) if uuid else KVPair("name", name)], |
| 444 |
) |
| 445 |
if match: |
| 446 |
mso_template.update_config_with_template_and_references(match.details, reference_dict) |
| 447 |
mso.existing = mso.previous = copy.deepcopy(match.details) |
| 448 |
else: |
| 449 |
mso.existing = mso.previous = [ |
| 450 |
mso_template.update_config_with_template_and_references(igmp_interface_policy, reference_dict) |
| 451 |
for igmp_interface_policy in existing_igmp_interface_policies |
| 452 |
] |
| 453 |
|
| 454 |
if state == "present": |
| 455 |
if uuid and not mso.existing: |
| 456 |
mso.fail_json(msg="{0} with the UUID: '{1}' not found".format(object_description, uuid)) |
| 457 |
|
| 458 |
mso_values = dict( |
| 459 |
name=name, |
| 460 |
description=description, |
| 461 |
enableV3Asm=version3_asm, |
| 462 |
enableFastLeaveControl=fast_leave, |
| 463 |
enableReportLinkLocalGroups=report_link_local_groups, |
| 464 |
igmpQuerierVersion=igmp_version, |
| 465 |
groupTimeout=group_timeout, |
| 466 |
queryInterval=query_interval, |
| 467 |
queryResponseInterval=query_response_interval, |
| 468 |
lastMemberCount=last_member_count, |
| 469 |
lastMemberResponseInterval=last_member_response_time, |
| 470 |
startQueryCount=startup_query_count, |
| 471 |
startQueryInterval=startup_query_interval, |
| 472 |
querierTimeout=querier_timeout, |
| 473 |
robustnessFactor=robustness_variable, |
| 474 |
maximumMulticastEntries=maximum_multicast_entries, |
| 475 |
reservedMulticastEntries=reserved_multicast_entries, |
| 476 |
stateLimitRouteMapRef=state_limit_route_map_uuid, |
| 477 |
reportPolicyRouteMapRef=report_policy_route_map_uuid, |
| 478 |
staticReportRouteMapRef=static_report_route_map_uuid, |
| 479 |
) |
| 480 |
|
| 481 |
if state_limit_route_map: |
| 482 |
empty_state_limit_route_map = check_if_all_elements_are_none(list(state_limit_route_map.values())) |
| 483 |
if not empty_state_limit_route_map: |
| 484 |
mso_values["stateLimitRouteMapRef"] = mso_template.get_route_map_policy_for_multicast_uuid(state_limit_route_map.get("name")) |
| 485 |
|
| 486 |
if report_policy_route_map: |
| 487 |
empty_report_policy_route_map = check_if_all_elements_are_none(list(report_policy_route_map.values())) |
| 488 |
if not empty_report_policy_route_map: |
| 489 |
mso_values["reportPolicyRouteMapRef"] = mso_template.get_route_map_policy_for_multicast_uuid(report_policy_route_map.get("name")) |
| 490 |
|
| 491 |
if static_report_route_map: |
| 492 |
empty_static_report_route_map = check_if_all_elements_are_none(list(static_report_route_map.values())) |
| 493 |
if not empty_static_report_route_map: |
| 494 |
mso_values["staticReportRouteMapRef"] = mso_template.get_route_map_policy_for_multicast_uuid(static_report_route_map.get("name")) |
| 495 |
|
| 496 |
if match: |
| 497 |
mso_values_remove = list() |
| 498 |
|
| 499 |
if (state_limit_route_map_uuid == "" or empty_state_limit_route_map) and match.details.get("stateLimitRouteMapRef"): |
| 500 |
mso_values_remove.append("stateLimitRouteMapRef") |
| 501 |
if (report_policy_route_map_uuid == "" or empty_report_policy_route_map) and match.details.get("reportPolicyRouteMapRef"): |
| 502 |
mso_values_remove.append("reportPolicyRouteMapRef") |
| 503 |
if (static_report_route_map_uuid == "" or empty_static_report_route_map) and match.details.get("staticReportRouteMapRef"): |
| 504 |
mso_values_remove.append("staticReportRouteMapRef") |
| 505 |
|
| 506 |
append_update_ops_data(ops, match.details, "{0}/{1}".format(path, match.index), mso_values, mso_values_remove) |
| 507 |
mso.sanitize(match.details, collate=True) |
| 508 |
else: |
| 509 |
mso.sanitize(mso_values) |
| 510 |
ops.append(dict(op="add", path="{0}/-".format(path), value=mso.sent)) |
| 511 |
|
| 512 |
elif state == "absent": |
| 513 |
if mso.existing: |
| 514 |
ops.append(dict(op="remove", path="{0}/{1}".format(path, match.index))) |
| 515 |
|
| 516 |
if not module.check_mode and ops: |
| 517 |
response_object = mso.request(mso_template.template_path, method="PATCH", data=ops) |
| 518 |
existing_igmp_interface_policies = response_object.get("tenantPolicyTemplate", {}).get("template", {}).get("igmpInterfacePolicies", []) |
| 519 |
match = mso_template.get_object_by_key_value_pairs( |
| 520 |
object_description, existing_igmp_interface_policies, [KVPair("uuid", uuid) if uuid else KVPair("name", name)] |
| 521 |
) |
| 522 |
if match: |
| 523 |
mso_template.update_config_with_template_and_references(match.details, reference_dict) |
| 524 |
mso.existing = match.details # When the state is present |
| 525 |
else: |
| 526 |
mso.existing = {} # When the state is absent |
| 527 |
elif module.check_mode and state != "query": # When the state is present/absent with check mode |
| 528 |
mso_template.update_config_with_template_and_references(mso.proposed, reference_dict) |
| 529 |
mso.existing = mso.proposed if state == "present" else {} |
| 530 |
|
| 531 |
mso.exit_json() |
| 532 |
|
| 533 |
|
| 534 |
if __name__ == "__main__": |
| 535 |
main() |