55
55
threshold_up:
56
56
description:
57
57
- The IPSLA Track List percentage or weight up threshold.
58
- - The value must be in the range 0 - 100 when O(type) is C( percentage).
59
- - The value must be in the range 0 - 255 when O(type) is C( weight).
58
+ - The value must be in the range 0 - 100 when O(type= percentage).
59
+ - The value must be in the range 0 - 255 when O(type= weight).
60
60
- The value must be greater than or equal to O(threshold_down).
61
61
- The default value is 1.
62
62
type: int
63
63
aliases: [ up ]
64
64
threshold_down:
65
65
description:
66
66
- The IPSLA Track List percentage or weight down threshold.
67
- - The value must be in the range 0 - 100 when O(type) is C( percentage).
68
- - The value must be in the range 0 - 255 when O(type) is C( weight).
67
+ - The value must be in the range 0 - 100 when O(type= percentage).
68
+ - The value must be in the range 0 - 255 when O(type= weight).
69
69
- The value must be less than or equal to O(threshold_up).
70
70
- The default value is 0.
71
71
type: int
93
93
ipsla_monitoring_policy_uuid:
94
94
description:
95
95
- The UUID of the IPSLA Monitoring Policy to use for the member.
96
+ - This parameter can be used instead of O(members.ipsla_monitoring_policy).
96
97
type: str
97
98
ipsla_monitoring_policy:
98
99
description:
99
- - The IPSLA Monitoring Policy to use for the member.
100
+ - The name IPSLA Monitoring Policy to use for the member.
100
101
- This parameter can be used instead of O(members.ipsla_monitoring_policy_uuid).
101
- type: dict
102
- suboptions:
103
- name:
104
- description:
105
- - The name of the IPSLA Monitoring Policy.
106
- type: str
107
- required: true
108
- template:
109
- description:
110
- - The name of the Template associated with the IPSLA Monitoring Policy.
111
- type: str
112
- required: true
102
+ type: str
103
+ aliases: [ ipsla_monitoring_policy_name ]
113
104
scope_type:
114
105
description:
115
106
- The scope type of the member.
119
110
scope_uuid:
120
111
description:
121
112
- The UUID of the BD or L3Out used as the scope for the member.
113
+ - This parameter can be used instead of O(members.scope).
122
114
type: str
123
115
scope:
124
116
description:
184
176
name: ansible_test_bd
185
177
template: ansible_test_template
186
178
schema: ansible_test_schema
187
- ipsla_monitoring_policy:
188
- name: ansible_test_ipsla_monitoring_policy
189
- template: ansible_tenant_template
179
+ ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy
190
180
- destination_ip: 2001:0000:130F:0000:0000:09C0:876A:130B
191
181
scope_type: l3out
192
182
scope:
193
183
name: ansible_test_l3out
194
184
template: ansible_test_template
195
- ipsla_monitoring_policy:
196
- name: ansible_test_ipsla_monitoring_policy
197
- template: ansible_tenant_template
185
+ ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy
198
186
- destination_ip: 1.1.1.2
199
187
scope_type: l3out
200
188
scope_uuid: "{{ l3out.current.uuid }}"
201
189
ipsla_monitoring_policy_uuid: "{{ ipsla_monitoring_policy.current.uuid }}"
202
190
state: present
191
+ register: ipsla_track_list
192
+
193
+ - name: Update an IPSLA Track List name with UUID
194
+ cisco.mso.ndo_ipsla_track_list:
195
+ host: mso_host
196
+ username: admin
197
+ password: SomeSecretPassword
198
+ template: ansible_tenant_template
199
+ ipsla_track_list: ansible_test_ipsla_track_list_updated
200
+ ipsla_track_list_uuid: "{{ ipsla_track_list.current.uuid }}"
201
+ state: present
202
+ register: ipsla_track_list_update
203
203
204
204
- name: Query an IPSLA Track List with name
205
205
cisco.mso.ndo_ipsla_track_list:
@@ -295,13 +295,7 @@ def main():
295
295
options = dict (
296
296
destination_ip = dict (type = "str" , aliases = ["ip" ], required = True ),
297
297
ipsla_monitoring_policy_uuid = dict (type = "str" ),
298
- ipsla_monitoring_policy = dict (
299
- type = "dict" ,
300
- options = dict (
301
- name = dict (type = "str" , required = True ),
302
- template = dict (type = "str" , required = True ),
303
- ),
304
- ),
298
+ ipsla_monitoring_policy = dict (type = "str" , aliases = ["ipsla_monitoring_policy_name" ]),
305
299
scope_uuid = dict (type = "str" ),
306
300
scope = dict (
307
301
type = "dict" ,
@@ -343,7 +337,7 @@ def main():
343
337
ipsla_track_list = module .params .get ("ipsla_track_list" )
344
338
description = module .params .get ("description" )
345
339
ipsla_track_list_uuid = module .params .get ("ipsla_track_list_uuid" )
346
- type = module .params .get ("type" )
340
+ list_type = module .params .get ("type" )
347
341
thresholds = {
348
342
"down" : module .params .get ("threshold_down" ),
349
343
"up" : module .params .get ("threshold_up" ),
@@ -354,7 +348,7 @@ def main():
354
348
# Validate
355
349
valid_upper = 100
356
350
valid_lower = 0
357
- if type == "weight" :
351
+ if list_type == "weight" :
358
352
valid_upper = 255
359
353
for threshold_key , threshold_value in thresholds .items ():
360
354
if threshold_value is not None and threshold_value not in range (valid_lower , valid_upper ):
@@ -374,6 +368,9 @@ def main():
374
368
375
369
ops = []
376
370
match = None
371
+
372
+ # The object dictionary is used as a cache store for schema & template data.
373
+ # This is done to limit the amount of API calls when UUID is not specified for member scope references.
377
374
obj_cache = {}
378
375
379
376
mso_template = MSOTemplate (mso , "tenant" , template )
@@ -402,15 +399,14 @@ def main():
402
399
mso_values = {
403
400
"name" : ipsla_track_list ,
404
401
"description" : description ,
405
- "type" : type ,
406
- type + " Up" : thresholds ["up" ],
407
- type + " Down" : thresholds ["down" ],
402
+ "type" : list_type ,
403
+ "{0} Up". format ( list_type ) : thresholds ["up" ],
404
+ "{0} Down". format ( list_type ) : thresholds ["down" ],
408
405
}
409
406
if members is not None :
410
- mso_values ["trackListMembers" ] = format_track_list_members (mso , members , obj_cache )
407
+ mso_values ["trackListMembers" ] = format_track_list_members (mso , mso_template , members , obj_cache )
411
408
if match :
412
- update_path = "{0}/{1}" .format (path , match .index )
413
- append_update_ops_data (ops , match .details , update_path , mso_values )
409
+ append_update_ops_data (ops , match .details , "{0}/{1}" .format (path , match .index ), mso_values )
414
410
mso .sanitize (match .details , collate = True )
415
411
else :
416
412
mso .sanitize (mso_values )
@@ -463,71 +459,63 @@ def get_l3out_uuid(l3out_template_object, name):
463
459
return match .details .get ("uuid" )
464
460
465
461
466
- def get_ipsla_monitoring_policy_uuid (tenant_template_obj , name ):
462
+ def get_ipsla_monitoring_policy_uuid (tenant_template_obj , uuid , name ):
467
463
existing_ipsla_policies = tenant_template_obj .template .get ("tenantPolicyTemplate" , {}).get ("template" , {}).get ("ipslaMonitoringPolicies" , [])
468
464
match = tenant_template_obj .get_object_by_key_value_pairs (
469
465
"IPSLA Monitoring Policy" ,
470
466
existing_ipsla_policies ,
471
- [KVPair ("name" , name )],
467
+ [( KVPair ("uuid" , uuid ) if uuid else KVPair ( " name" , name ) )],
472
468
fail_module = True ,
473
469
)
474
470
if match :
475
471
return match .details .get ("uuid" )
476
472
477
473
478
- def format_track_list_members (mso , members , obj_cache ):
474
+ def format_track_list_members (mso , mso_template , members , obj_cache ):
479
475
track_list_members = []
480
476
481
- def get_obj_uuid ( type , uuid , obj ):
477
+ def get_scope_obj_uuid ( scope_type , uuid , obj ):
482
478
if uuid :
483
479
return uuid
484
480
485
481
name = obj .get ("name" )
486
482
template = obj .get ("template" )
487
483
488
- if type == "bd" :
484
+ if scope_type == "bd" :
489
485
schema_name = obj .get ("schema" )
490
486
if not schema_name :
491
487
mso .fail_json (msg = "A member scope_type is bd and scope is used but the schema option is missing." )
492
- schema_obj = obj_cache .get ("schema-{0}-{1}" .format (type , schema_name ))
488
+ key = "schema-{0}-{1}" .format (scope_type , schema_name )
489
+ schema_obj = obj_cache .get (key )
493
490
if not schema_obj :
494
491
id , path , schema_obj = mso .query_schema (schema_name )
495
- obj_cache [schema_name ] = schema_obj
492
+ obj_cache [key ] = schema_obj
496
493
return get_bd_uuid (mso , schema_obj , template , name )
497
494
498
- key = "template-{0}-{1}" .format (type , template )
499
- mso_template = obj_cache .get (key )
500
-
501
- if type == "l3out" :
495
+ if scope_type == "l3out" :
496
+ key = "template-{0}-{1}" .format (scope_type , template )
497
+ mso_template = obj_cache .get (key )
502
498
if not mso_template :
503
- mso_template = MSOTemplate (mso , type , template )
504
- mso_template .validate_template (type )
499
+ mso_template = MSOTemplate (mso , scope_type , template )
500
+ mso_template .validate_template (scope_type )
505
501
obj_cache [key ] = mso_template
506
502
return get_l3out_uuid (mso_template , name )
507
503
508
- elif type == "tenant" :
509
- if not mso_template :
510
- mso_template = MSOTemplate (mso , type , template )
511
- mso_template .validate_template ("tenantPolicy" )
512
- obj_cache [key ] = mso_template
513
- return get_ipsla_monitoring_policy_uuid (mso_template , name )
514
-
515
504
for member in members :
516
505
scope_type = member .get ("scope_type" )
517
506
track_member = {
518
- "destIP" : member .get ("destination_ip" ),
519
- "scope" : get_obj_uuid (scope_type , member .get ("scope_uuid" ), member .get ("scope" )),
520
- "scopeType" : scope_type ,
521
- "ipslaMonitoringRef" : get_obj_uuid (
522
- "tenant" ,
523
- member .get ("ipsla_monitoring_policy_uuid" ),
524
- member .get ("ipsla_monitoring_policy" ),
525
- ),
507
+ "trackMember" : {
508
+ "destIP" : member .get ("destination_ip" ),
509
+ "scope" : get_scope_obj_uuid (scope_type , member .get ("scope_uuid" ), member .get ("scope" )),
510
+ "scopeType" : scope_type ,
511
+ "ipslaMonitoringRef" : get_ipsla_monitoring_policy_uuid (
512
+ mso_template ,
513
+ member .get ("ipsla_monitoring_policy_uuid" ),
514
+ member .get ("ipsla_monitoring_policy" ),
515
+ ),
516
+ },
517
+ "weight" : member .get ("weight" ),
526
518
}
527
- track_member = {"trackMember" : track_member }
528
- weight = member .get ("weight" )
529
- if weight is not None :
530
- track_member ["weight" ] = weight
531
519
track_list_members .append (track_member )
532
520
return track_list_members
533
521
0 commit comments