Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minor_change] Added new module for IPSLA Track Lists (DCNE-134) #600

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

samiib
Copy link
Collaborator

@samiib samiib commented Jan 22, 2025

Fixes #460

@samiib samiib self-assigned this Jan 22, 2025
@samiib samiib changed the title [minor_change] Added new module for IPSLA Track List. [minor_change] Added new module for IPSLA Track Lists Jan 22, 2025
@github-actions github-actions bot changed the title [minor_change] Added new module for IPSLA Track Lists [minor_change] Added new module for IPSLA Track Lists (DCNE-134) Jan 22, 2025

ops = []
match = None
obj_cache = {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The obj_cache is used so each member does not need to send an API call to get schema/template details multiple times.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you write this as a comment in the code? done something similar in mso_schema_template_anp_epg_contract

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for this issue but, should we explore writing a re-usable cache solution for templates and schemas?

Copy link
Collaborator Author

@samiib samiib Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its a good idea for a future enhancement. We could potentially explore different libraries that may help. eg https://pypi.org/project/cachetools/
However, it would be quite a bit of work. It may also only be useful on modules with lists of dictionaries that need to call APIs for each item, like this module and mso_schema_template_anp_epg_contract. A simple dictionary cache like this is straight forward enough to implement on a case-by-case basis for now.

Also, I added the comment. 👍

@samiib samiib added the jira-sync Sync this issue to Jira label Jan 22, 2025
plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
anvitha-jain
anvitha-jain previously approved these changes Jan 22, 2025
Copy link
Collaborator

@anvitha-jain anvitha-jain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
plugins/modules/ndo_ipsla_track_list.py Show resolved Hide resolved
plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
Comment on lines +423 to +471
def get_bd_uuid(mso, schema_obj, template, bd):
# Get template
templates = [t.get("name") for t in schema_obj.get("templates")]
if template not in templates:
mso.fail_json(msg="Provided template '{0}' does not exist. Existing templates: {1}".format(template, ", ".join(templates)))
template_idx = templates.index(template)
# Get BD
bds = [b.get("name") for b in schema_obj.get("templates")[template_idx]["bds"]]
if bd not in bds:
mso.fail_json(msg="Provided BD '{0}' does not exist. Existing BDs: {1}".format(bd, ", ".join(bds)))
return schema_obj.get("templates")[template_idx]["bds"][bds.index(bd)].get("uuid")


def get_l3out_uuid(l3out_template_object, name):
l3outs = l3out_template_object.template.get("l3outTemplate", {}).get("l3outs", [])
match = l3out_template_object.get_object_by_key_value_pairs(
"L3Out",
l3outs,
[KVPair("name", name)],
fail_module=True,
)
if match:
return match.details.get("uuid")


def get_ipsla_monitoring_policy_uuid(tenant_template_obj, uuid, name):
existing_ipsla_policies = tenant_template_obj.template.get("tenantPolicyTemplate", {}).get("template", {}).get("ipslaMonitoringPolicies", [])
match = tenant_template_obj.get_object_by_key_value_pairs(
"IPSLA Monitoring Policy",
existing_ipsla_policies,
[(KVPair("uuid", uuid) if uuid else KVPair("name", name))],
fail_module=True,
)
if match:
return match.details.get("uuid")
Copy link
Collaborator

@akinross akinross Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make these functions available in schema.py or template.py or utils.py so we can re-use when needed in other modules?

plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved

ops = []
match = None
obj_cache = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you write this as a comment in the code? done something similar in mso_schema_template_anp_epg_contract


ops = []
match = None
obj_cache = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for this issue but, should we explore writing a re-usable cache solution for templates and schemas?

plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
plugins/modules/ndo_ipsla_track_list.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira-sync Sync this issue to Jira
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: New module for IPSLA Track List Policy in Tenant Tenant Policies Template (DCNE-134)
4 participants