-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: master
Are you sure you want to change the base?
Conversation
|
||
ops = [] | ||
match = None | ||
obj_cache = {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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") |
There was a problem hiding this comment.
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?
|
||
ops = [] | ||
match = None | ||
obj_cache = {} |
There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
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?
2c1cdce
to
02aa230
Compare
Fixes #460