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

Added mso_schema_template_anp_epg_annotation to manage EPG annotations (DCNE-60) #588

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

Conversation

samiib
Copy link
Collaborator

@samiib samiib commented Dec 18, 2024

Fixes #509

@samiib samiib added the enhancement New feature or request label Dec 18, 2024
@samiib samiib self-assigned this Dec 18, 2024
@github-actions github-actions bot changed the title Added mso_schema_template_anp_epg_annotation to manage EPG annotations Added mso_schema_template_anp_epg_annotation to manage EPG annotations (DCNE-60) Dec 18, 2024
extends_documentation_fragment: cisco.mso.modules
notes:
- The O(schema) and O(template) must exist before using this module in your playbook.
Use M(cisco.mso.mso_schema_template) to create the schema template.
Copy link
Collaborator

Choose a reason for hiding this comment

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

-> Use M(cisco.mso.mso_schema_template) to create the schema and template.

Use M(cisco.mso.mso_schema_template) to create the schema template.
- The O(anp) must exist before using this module in your playbook.
Use M(cisco.mso.mso_schema_template_anp) to create the ANP.
- The O(epg) must exist before using this module in your playbook.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we actually combine all of them?

  • The O(schema), O(template), O(anp) and O(epg) must exist before using this module in your playbook.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done 👍

template: Template 1
anp: ANP 1
epg: EPG 1
annotation_key: "annotation_key_1_updated"
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotation_key: annotation_key_1_updated

template: Template 1
anp: ANP 1
epg: EPG 1
annotation_key: "annotation_key_1_updated"
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotation_key: annotation_key_1_updated

template: Template 1
anp: ANP 1
epg: EPG 1
annotation_key: "annotation_key_1_updated"
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotation_key: annotation_key_1_updated

anp: ANP 1
epg: EPG 1
annotation_key: "annotation_key_1_updated"
annotation_value: "annotation_value_1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotation_value: annotation_value_1

template: Template 1
anp: ANP 1
epg: EPG 1
annotation_key: "annotation_key_1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotation_key: annotation_key_1

anp: ANP 1
epg: EPG 1
annotation_key: "annotation_key_1"
annotation_value: "annotation_value_1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotation_value: annotation_value_1

@samiib samiib requested a review from shrsr December 19, 2024 09:39
mso_values = {"tagKey": annotation_key, "tagValue": annotation_value}
mso.sanitize(mso_values)
if mso.existing:
# An error from MSO prevents the "replace" operation from updating existing annotation values.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity, what errors do you get from this exactly? on which MSO versions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MSO Error 400: json: cannot unmarshal string into Go struct field Schema2.templates of type common.Epg2
Version 4.3.1 - This is the only version I have access to right now.
However, I have found a way to use the replace op instead.

Comment on lines 220 to 225
def append_add_op(ops, path, mso_values):
ops.append({"op": "add", "path": "{0}/-".format(path), "value": mso_values})


def append_remove_op(ops, path, index):
ops.append({"op": "remove", "path": "{0}/{1}".format(path, index)})
Copy link
Collaborator

Choose a reason for hiding this comment

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

These could be moved to one of the files in module_utils folder, probably something like in utils.py.
Nonetheless, to be honest, I don't think these functions are very useful, I think they don't specially make the code easier to read.

Copy link
Collaborator Author

@samiib samiib Dec 20, 2024

Choose a reason for hiding this comment

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

Yes, these could be moved if anyone would like to use them. However, most modules will use append_update_ops_data instead and only remove op once and there is no need to encapsulate it.
I had to construct the same dictionary for add and remove ops twice in this module. These functions are useful when added to reduce code duplication not necessarily to increase code readability, which can be subjective.

Copy link
Collaborator Author

@samiib samiib Dec 20, 2024

Choose a reason for hiding this comment

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

However, now that I have found a way to use the replace op, the code duplication doesn't exist anymore and the functions aren't needed.

@samiib samiib requested a review from gmicol December 20, 2024 06:21
Copy link
Collaborator

@akinross akinross left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@shrsr shrsr left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@gmicol gmicol left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Annotation with new module mso_schema_template_anp_epg_annotation (DCNE-60)
5 participants