Skip to content

Commit 02aa230

Browse files
committed
[ignore] Fix IPSLA monitoring policy spec and rename type variable.
1 parent ce92e2c commit 02aa230

File tree

2 files changed

+63
-85
lines changed

2 files changed

+63
-85
lines changed

plugins/modules/ndo_ipsla_track_list.py

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@
5555
threshold_up:
5656
description:
5757
- 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).
6060
- The value must be greater than or equal to O(threshold_down).
6161
- The default value is 1.
6262
type: int
6363
aliases: [ up ]
6464
threshold_down:
6565
description:
6666
- 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).
6969
- The value must be less than or equal to O(threshold_up).
7070
- The default value is 0.
7171
type: int
@@ -93,23 +93,14 @@
9393
ipsla_monitoring_policy_uuid:
9494
description:
9595
- 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).
9697
type: str
9798
ipsla_monitoring_policy:
9899
description:
99-
- The IPSLA Monitoring Policy to use for the member.
100+
- The name IPSLA Monitoring Policy to use for the member.
100101
- 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 ]
113104
scope_type:
114105
description:
115106
- The scope type of the member.
@@ -119,6 +110,7 @@
119110
scope_uuid:
120111
description:
121112
- 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).
122114
type: str
123115
scope:
124116
description:
@@ -184,22 +176,30 @@
184176
name: ansible_test_bd
185177
template: ansible_test_template
186178
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
190180
- destination_ip: 2001:0000:130F:0000:0000:09C0:876A:130B
191181
scope_type: l3out
192182
scope:
193183
name: ansible_test_l3out
194184
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
198186
- destination_ip: 1.1.1.2
199187
scope_type: l3out
200188
scope_uuid: "{{ l3out.current.uuid }}"
201189
ipsla_monitoring_policy_uuid: "{{ ipsla_monitoring_policy.current.uuid }}"
202190
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
203203
204204
- name: Query an IPSLA Track List with name
205205
cisco.mso.ndo_ipsla_track_list:
@@ -295,13 +295,7 @@ def main():
295295
options=dict(
296296
destination_ip=dict(type="str", aliases=["ip"], required=True),
297297
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"]),
305299
scope_uuid=dict(type="str"),
306300
scope=dict(
307301
type="dict",
@@ -343,7 +337,7 @@ def main():
343337
ipsla_track_list = module.params.get("ipsla_track_list")
344338
description = module.params.get("description")
345339
ipsla_track_list_uuid = module.params.get("ipsla_track_list_uuid")
346-
type = module.params.get("type")
340+
list_type = module.params.get("type")
347341
thresholds = {
348342
"down": module.params.get("threshold_down"),
349343
"up": module.params.get("threshold_up"),
@@ -354,7 +348,7 @@ def main():
354348
# Validate
355349
valid_upper = 100
356350
valid_lower = 0
357-
if type == "weight":
351+
if list_type == "weight":
358352
valid_upper = 255
359353
for threshold_key, threshold_value in thresholds.items():
360354
if threshold_value is not None and threshold_value not in range(valid_lower, valid_upper):
@@ -374,6 +368,9 @@ def main():
374368

375369
ops = []
376370
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.
377374
obj_cache = {}
378375

379376
mso_template = MSOTemplate(mso, "tenant", template)
@@ -402,15 +399,14 @@ def main():
402399
mso_values = {
403400
"name": ipsla_track_list,
404401
"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"],
408405
}
409406
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)
411408
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)
414410
mso.sanitize(match.details, collate=True)
415411
else:
416412
mso.sanitize(mso_values)
@@ -463,71 +459,63 @@ def get_l3out_uuid(l3out_template_object, name):
463459
return match.details.get("uuid")
464460

465461

466-
def get_ipsla_monitoring_policy_uuid(tenant_template_obj, name):
462+
def get_ipsla_monitoring_policy_uuid(tenant_template_obj, uuid, name):
467463
existing_ipsla_policies = tenant_template_obj.template.get("tenantPolicyTemplate", {}).get("template", {}).get("ipslaMonitoringPolicies", [])
468464
match = tenant_template_obj.get_object_by_key_value_pairs(
469465
"IPSLA Monitoring Policy",
470466
existing_ipsla_policies,
471-
[KVPair("name", name)],
467+
[(KVPair("uuid", uuid) if uuid else KVPair("name", name))],
472468
fail_module=True,
473469
)
474470
if match:
475471
return match.details.get("uuid")
476472

477473

478-
def format_track_list_members(mso, members, obj_cache):
474+
def format_track_list_members(mso, mso_template, members, obj_cache):
479475
track_list_members = []
480476

481-
def get_obj_uuid(type, uuid, obj):
477+
def get_scope_obj_uuid(scope_type, uuid, obj):
482478
if uuid:
483479
return uuid
484480

485481
name = obj.get("name")
486482
template = obj.get("template")
487483

488-
if type == "bd":
484+
if scope_type == "bd":
489485
schema_name = obj.get("schema")
490486
if not schema_name:
491487
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)
493490
if not schema_obj:
494491
id, path, schema_obj = mso.query_schema(schema_name)
495-
obj_cache[schema_name] = schema_obj
492+
obj_cache[key] = schema_obj
496493
return get_bd_uuid(mso, schema_obj, template, name)
497494

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)
502498
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)
505501
obj_cache[key] = mso_template
506502
return get_l3out_uuid(mso_template, name)
507503

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-
515504
for member in members:
516505
scope_type = member.get("scope_type")
517506
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"),
526518
}
527-
track_member = {"trackMember": track_member}
528-
weight = member.get("weight")
529-
if weight is not None:
530-
track_member["weight"] = weight
531519
track_list_members.append(track_member)
532520
return track_list_members
533521

tests/integration/targets/ndo_ipsla_track_list/tasks/main.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,13 @@
160160
name: ansible_test_bd
161161
template: ansible_test
162162
schema: ansible_test
163-
ipsla_monitoring_policy:
164-
name: ansible_test_ipsla_monitoring_policy
165-
template: ansible_tenant_template
163+
ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy
166164
- destination_ip: 2001:0000:130F:0000:0000:09C0:876A:130B
167165
scope_type: l3out
168166
scope:
169167
name: ansible_test_l3out
170168
template: ansible_test
171-
ipsla_monitoring_policy:
172-
name: ansible_test_ipsla_monitoring_policy
173-
template: ansible_tenant_template
169+
ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy
174170
- destination_ip: 1.1.1.3
175171
scope_type: l3out
176172
scope_uuid: "{{ nm_ansible_test_l3out.current.uuid }}"
@@ -298,18 +294,14 @@
298294
name: ansible_test_bd
299295
template: ansible_test
300296
schema: ansible_test
301-
ipsla_monitoring_policy:
302-
name: ansible_test_ipsla_monitoring_policy
303-
template: ansible_tenant_template
297+
ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy
304298
- destination_ip: 2001:0000:130F:0000:0000:09C0:876A:130C
305299
scope_type: l3out
306300
weight: 20
307301
scope:
308302
name: ansible_test_l3out
309303
template: ansible_test
310-
ipsla_monitoring_policy:
311-
name: ansible_test_ipsla_monitoring_policy
312-
template: ansible_tenant_template
304+
ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy
313305
- destination_ip: 1.1.1.3
314306
scope_type: l3out
315307
scope_uuid: "{{ nm_ansible_test_l3out.current.uuid }}"
@@ -610,9 +602,7 @@
610602
- destination_ip: 2001:0000:130F:0000:0000:09C0:876A:130C
611603
scope_uuid: "{{ nm_ansible_test_l3out.current.uuid }}"
612604
scope_type: l3out
613-
ipsla_monitoring_policy:
614-
name: ansible_test_ipsla_monitoring_policy_invalid
615-
template: ansible_tenant_template
605+
ipsla_monitoring_policy: ansible_test_ipsla_monitoring_policy_invalid
616606
register: err_invalid_ipsla_monitoring_policy
617607
ignore_errors: true
618608

0 commit comments

Comments
 (0)