129
129
state_limit_route_map_uuid:
130
130
description:
131
131
- The UUID of the state limit route map.
132
+ - Providing an empty string will remove the O(state_limit_route_map_uuid="") from IGMP Interface Policy.
132
133
type: str
133
134
aliases: [ state_limit_route_map_for_multicast ]
134
135
state_limit_route_map:
135
136
description:
136
137
- The Route Map Policy for Multicast.
137
138
- This parameter can be used instead of O(state_limit_route_map_uuid).
138
139
- If both parameter are used, O(state_limit_route_map) will be ignored.
140
+ - Providing an empty map will remove the O(state_limit_route_map={}) from IGMP Interface Policy.
139
141
type: dict
140
142
suboptions:
141
143
name:
142
144
description:
143
145
- The name of the Route Map Policy for Multicast.
144
146
type: str
145
- required: true
146
147
aliases: [ state_limit_route_map_policy, state_limit_route_map_policy_multicast ]
147
148
report_policy_route_map_uuid:
148
149
description:
149
150
- The UUID of the report policy route map.
151
+ - Providing an empty string will remove the O(report_policy_route_map_uuid="") from IGMP Interface Policy.
150
152
type: str
151
153
aliases: [ report_policy_route_map_for_multicast ]
152
154
report_policy_route_map:
153
155
description:
154
156
- The Route Map Policy for Multicast.
155
157
- This parameter can be used instead of O(report_policy_route_map_uuid).
156
158
- If both parameter are used, O(report_policy_route_map) will be ignored.
159
+ - Providing an empty map will remove the O(report_policy_route_map={}) from IGMP Interface Policy.
157
160
type: dict
158
161
suboptions:
159
162
name:
160
163
description:
161
164
- The name of the Route Map Policy for Multicast.
162
165
type: str
163
- required: true
164
166
aliases: [ report_policy_route_map_policy, report_policy_route_map_policy_multicast ]
165
167
static_report_route_map_uuid:
166
168
description:
167
169
- The UUID of the static report route map.
170
+ - Providing an empty string will remove the O(static_report_route_map_uuid="") from IGMP Interface Policy.
168
171
type: str
169
172
aliases: [ static_report_route_map_for_multicast ]
170
173
static_report_route_map:
171
174
description:
172
175
- The Route Map Policy for Multicast.
173
176
- This parameter can be used instead of O(static_report_route_map_uuid).
174
177
- If both parameter are used, O(static_report_route_map) will be ignored.
178
+ - Providing an empty map will remove the O(static_report_route_map={}) from IGMP Interface Policy.
175
179
type: dict
176
180
suboptions:
177
181
name:
178
182
description:
179
183
- The name of the Route Map Policy for Multicast.
180
184
type: str
181
- required: true
182
185
aliases: [ static_report_route_map_policy, static_report_route_map_policy_multicast ]
183
186
maximum_multicast_entries:
184
187
description:
311
314
from ansible_collections .cisco .mso .plugins .module_utils .constants import ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP
312
315
from ansible_collections .cisco .mso .plugins .module_utils .utils import (
313
316
append_update_ops_data ,
314
- get_object_identifier ,
317
+ check_if_all_elements_are_none ,
318
+ get_template_object_name_by_uuid ,
315
319
)
316
320
317
321
@@ -340,23 +344,23 @@ def main():
340
344
state_limit_route_map = dict (
341
345
type = "dict" ,
342
346
options = dict (
343
- name = dict (type = "str" , required = True ),
347
+ name = dict (type = "str" ),
344
348
),
345
349
aliases = ["state_limit_route_map_policy" , "state_limit_route_map_policy_multicast" ],
346
350
),
347
351
report_policy_route_map_uuid = dict (type = "str" , aliases = ["report_policy_route_map_for_multicast" ]),
348
352
report_policy_route_map = dict (
349
353
type = "dict" ,
350
354
options = dict (
351
- name = dict (type = "str" , required = True ),
355
+ name = dict (type = "str" ),
352
356
),
353
357
aliases = ["report_policy_route_map_policy" , "report_policy_route_map_policy_multicast" ],
354
358
),
355
359
static_report_route_map_uuid = dict (type = "str" , aliases = ["static_report_route_map_for_multicast" ]),
356
360
static_report_route_map = dict (
357
361
type = "dict" ,
358
362
options = dict (
359
- name = dict (type = "str" , required = True ),
363
+ name = dict (type = "str" ),
360
364
),
361
365
aliases = ["static_report_route_map_policy" , "static_report_route_map_policy_multicast" ],
362
366
),
@@ -385,7 +389,8 @@ def main():
385
389
386
390
mso = MSOModule (module )
387
391
388
- template_identifier = get_object_identifier (module .params .get ("template_id" ), module .params .get ("template" ))
392
+ template = module .params .get ("template" )
393
+ template_id = module .params .get ("template_id" )
389
394
name = module .params .get ("name" )
390
395
uuid = module .params .get ("uuid" )
391
396
description = module .params .get ("description" )
@@ -412,38 +417,35 @@ def main():
412
417
reserved_multicast_entries = module .params .get ("reserved_multicast_entries" )
413
418
state = module .params .get ("state" )
414
419
415
- mso_template = MSOTemplate (mso , "tenant" , template_identifier . get ( "name" ), template_identifier . get ( "uuid" ) )
420
+ mso_template = MSOTemplate (mso , "tenant" , template , template_id )
416
421
mso_template .validate_template ("tenantPolicy" )
417
422
ops = []
423
+ empty_state_limit_route_map = False
424
+ empty_report_policy_route_map = False
425
+ empty_static_report_route_map = False
418
426
419
427
existing_igmp_interface_policies = mso_template .template .get ("tenantPolicyTemplate" , {}).get ("template" , {}).get ("igmpInterfacePolicies" , [])
420
428
object_description = "IGMP Interface Policy"
429
+ path = "/tenantPolicyTemplate/template/igmpInterfacePolicies"
421
430
422
- if name or uuid :
431
+ if uuid or name :
423
432
match = mso_template .get_object_by_key_value_pairs (
424
433
object_description ,
425
434
existing_igmp_interface_policies ,
426
435
[KVPair ("uuid" , uuid ) if uuid else KVPair ("name" , name )],
427
436
)
428
437
if match :
429
- igmp_interface_policy_attrs_path = "/tenantPolicyTemplate/template/igmpInterfacePolicies/{0}" .format (match .index )
438
+ igmp_interface_policy_attrs_path = "{0}/{1}" .format (path , match .index )
439
+ set_names_for_references (mso , match .details )
430
440
mso .existing = mso .previous = copy .deepcopy (match .details )
431
441
else :
432
- mso .existing = mso .previous = existing_igmp_interface_policies
442
+ mso .existing = mso .previous = [set_names_for_references (mso , igmp_interface_policy ) for igmp_interface_policy in existing_igmp_interface_policies ]
443
+ # existing_igmp_interface_policies
433
444
434
445
if state == "present" :
435
446
if uuid and not mso .existing :
436
447
mso .fail_json (msg = "{0} with the UUID: '{1}' not found" .format (object_description , uuid ))
437
448
438
- if state_limit_route_map and not state_limit_route_map_uuid :
439
- state_limit_route_map_uuid = mso_template .get_route_map_policy_for_multicast_uuid (state_limit_route_map .get ("name" ))
440
-
441
- if report_policy_route_map and not report_policy_route_map_uuid :
442
- report_policy_route_map_uuid = mso_template .get_route_map_policy_for_multicast_uuid (report_policy_route_map .get ("name" ))
443
-
444
- if static_report_route_map and not static_report_route_map_uuid :
445
- static_report_route_map_uuid = mso_template .get_route_map_policy_for_multicast_uuid (static_report_route_map .get ("name" ))
446
-
447
449
mso_values = dict (
448
450
name = name ,
449
451
description = description ,
@@ -460,23 +462,48 @@ def main():
460
462
startQueryInterval = startup_query_interval ,
461
463
querierTimeout = querier_timeout ,
462
464
robustnessFactor = robustness_variable ,
465
+ maximumMulticastEntries = maximum_multicast_entries ,
466
+ reservedMulticastEntries = reserved_multicast_entries ,
463
467
stateLimitRouteMapRef = state_limit_route_map_uuid ,
464
468
reportPolicyRouteMapRef = report_policy_route_map_uuid ,
465
469
staticReportRouteMapRef = static_report_route_map_uuid ,
466
- maximumMulticastEntries = maximum_multicast_entries ,
467
- reservedMulticastEntries = reserved_multicast_entries ,
468
470
)
469
471
472
+ if state_limit_route_map :
473
+ empty_state_limit_route_map = check_if_all_elements_are_none (list (state_limit_route_map .values ()))
474
+ if not empty_state_limit_route_map :
475
+ mso_values ["stateLimitRouteMapRef" ] = mso_template .get_route_map_policy_for_multicast_uuid (state_limit_route_map .get ("name" ))
476
+
477
+ if report_policy_route_map :
478
+ empty_report_policy_route_map = check_if_all_elements_are_none (list (report_policy_route_map .values ()))
479
+ if not empty_report_policy_route_map :
480
+ mso_values ["reportPolicyRouteMapRef" ] = mso_template .get_route_map_policy_for_multicast_uuid (report_policy_route_map .get ("name" ))
481
+
482
+ if static_report_route_map :
483
+ empty_static_report_route_map = check_if_all_elements_are_none (list (static_report_route_map .values ()))
484
+ if not empty_static_report_route_map :
485
+ mso_values ["staticReportRouteMapRef" ] = mso_template .get_route_map_policy_for_multicast_uuid (static_report_route_map .get ("name" ))
486
+
487
+ if match :
488
+ mso_values_remove = list ()
489
+
490
+ if (state_limit_route_map_uuid == "" or empty_state_limit_route_map ) and match .details .get ("stateLimitRouteMapRef" ):
491
+ mso_values_remove .append ("stateLimitRouteMapRef" )
492
+ if (report_policy_route_map_uuid == "" or empty_report_policy_route_map ) and match .details .get ("reportPolicyRouteMapRef" ):
493
+ mso_values_remove .append ("reportPolicyRouteMapRef" )
494
+ if (static_report_route_map_uuid == "" or empty_static_report_route_map ) and match .details .get ("staticReportRouteMapRef" ):
495
+ mso_values_remove .append ("staticReportRouteMapRef" )
496
+
470
497
if mso .existing :
471
- append_update_ops_data (ops , match .details , igmp_interface_policy_attrs_path , mso_values )
498
+ append_update_ops_data (ops , match .details , "{0}/{1}" . format ( path , match . index ), mso_values , mso_values_remove )
472
499
mso .sanitize (match .details , collate = True )
473
500
else :
474
501
mso .sanitize (mso_values )
475
- ops .append (dict (op = "add" , path = "/tenantPolicyTemplate/template/igmpInterfacePolicies/-" , value = mso .sent ))
502
+ ops .append (dict (op = "add" , path = "{0}/-" . format ( path ) , value = mso .sent ))
476
503
477
504
elif state == "absent" :
478
505
if mso .existing :
479
- ops .append (dict (op = "remove" , path = igmp_interface_policy_attrs_path ))
506
+ ops .append (dict (op = "remove" , path = "{0}/{1}" . format ( path , match . index ) ))
480
507
481
508
if not module .check_mode and ops :
482
509
response_object = mso .request (mso_template .template_path , method = "PATCH" , data = ops )
@@ -485,14 +512,27 @@ def main():
485
512
object_description , existing_igmp_interface_policies , [KVPair ("uuid" , uuid ) if uuid else KVPair ("name" , name )]
486
513
)
487
514
if match :
515
+ set_names_for_references (mso , match .details )
488
516
mso .existing = match .details # When the state is present
489
517
else :
490
518
mso .existing = {} # When the state is absent
491
519
elif module .check_mode and state != "query" : # When the state is present/absent with check mode
520
+ set_names_for_references (mso , mso .proposed )
492
521
mso .existing = mso .proposed if state == "present" else {}
493
522
494
523
mso .exit_json ()
495
524
496
525
526
+ def set_names_for_references (mso , route_map_dict ):
527
+ if route_map_dict .get ("stateLimitRouteMapRef" ):
528
+ route_map_dict ["stateLimitRouteMapName" ] = get_template_object_name_by_uuid (mso , "mcastRouteMap" , route_map_dict .get ("stateLimitRouteMapRef" ))
529
+ if route_map_dict .get ("reportPolicyRouteMapRef" ):
530
+ route_map_dict ["reportPolicyRouteMapName" ] = get_template_object_name_by_uuid (mso , "mcastRouteMap" , route_map_dict .get ("reportPolicyRouteMapRef" ))
531
+ if route_map_dict .get ("staticReportRouteMapRef" ):
532
+ route_map_dict ["staticReportRouteMapName" ] = get_template_object_name_by_uuid (mso , "mcastRouteMap" , route_map_dict .get ("staticReportRouteMapRef" ))
533
+
534
+ return route_map_dict
535
+
536
+
497
537
if __name__ == "__main__" :
498
538
main ()
0 commit comments