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

feat[dcnm_policy]: adding the functions to handle use_desc_as_key #285

Merged
merged 10 commits into from
Jun 18, 2024

Conversation

dsx1123
Copy link

@dsx1123 dsx1123 commented Apr 18, 2024

create the PR to track the changes. Will add test cases and update the document

@dsx1123 dsx1123 requested a review from mmudigon April 18, 2024 00:31
@dsx1123
Copy link
Author

dsx1123 commented Apr 18, 2024

#279

plugins/modules/dcnm_policy.py Outdated Show resolved Hide resolved
plugins/modules/dcnm_policy.py Outdated Show resolved Hide resolved
@dsx1123 dsx1123 changed the title [WIP] adding the functions to handle use_desc_as_key adding the functions to handle use_desc_as_key Apr 19, 2024
@dsx1123 dsx1123 marked this pull request as ready for review April 19, 2024 06:18
@dsx1123 dsx1123 changed the title adding the functions to handle use_desc_as_key feat[dcnm_policy]: adding the functions to handle use_desc_as_key Apr 19, 2024
@@ -943,6 +1098,35 @@ def dcnm_policy_create_policy(self, policy, command):

return resp

def dcnm_policy_update_policy(self, policy, command):
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this necessary. you could have used create_policy with 'PUT' command instead. Any specific reason for having a new routine for update?

Copy link
Author

Choose a reason for hiding this comment

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

I have tried the PUT method using POLICY_BULK_CREATE URL, it didn't work, besides, it is not documented. So prefer to use the documented endpoint for the update.

not pl["deleted"]
and (
(wp["policy_id_given"] is False)
and (pl["templateName"] == wp["templateName"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the template names match even in the case of use_desc_as_key is True. May be in that case we should just compare description alone. Specifically can there be two policies with different template names but same description? If yes, then we should delete policies matching description if use_desc_as_key is True.

Copy link
Author

@dsx1123 dsx1123 May 8, 2024

Choose a reason for hiding this comment

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

the idea of use_desc_as_key is to only use the description as the key, the use case it can support is, that when the user is using a different template for the same description, the module will delete the old one and create a new one with the new template.

# the user must make sure no policies with the same description are created on NDFC out of the playbook.
# If the description is not unique, the module will raise an error.

## Below task will policies with description "policy_radius" on swtich1, switch2 and switch3,
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo, should read as

Below task will create policies ...

Copy link
Author

Choose a reason for hiding this comment

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

will fix it.

@@ -637,12 +716,20 @@ def dcnm_policy_get_have(self):
pl
for pl in plist
for wp in self.want
if (pl["templateName"] == wp["templateName"])
if pl.get("source", "") == ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this check for? Not clear. Can you please add a comment for pl.get("source", "")?

Copy link
Author

Choose a reason for hiding this comment

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

will add the comment, here is the reason:
exclude the policies that have the source
when the user modifies a policy but has not deployed the policy,
a sub-policy might be created with the same description name, but marked as deleted
The signature of this kind of policy is that it has an original policyId as the source
it should be excluded from the match list as the policy will be deleted once the user deploys the configuration

@@ -1251,7 +1437,7 @@ def dcnm_translate_config(self, config):
updated_config.append(cfg)
config = updated_config
else:
config = override_config
config += override_config
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this working? When I checked it said '+=' not supported for dicts. Suggested to use update instead.

Copy link
Author

Choose a reason for hiding this comment

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

config and override_config are lists, not dicts, and yes, it works

@dsx1123 dsx1123 requested a review from mmudigon May 8, 2024 21:05
@mikewiebe
Copy link
Collaborator

@dsx1123 and @mmudigon is there anything pending for this PR?

@dsx1123
Copy link
Author

dsx1123 commented Jun 17, 2024

@dsx1123 and @mmudigon is there anything pending for this PR?

I should have addressed all the comments, but pending review again from @mmudigon

@mikewiebe mikewiebe merged commit 35e926b into CiscoDevNet:develop Jun 18, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants