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] Add nd_rest as a new generic ND REST API module. (DCNE-242) #109

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

Conversation

gmicol
Copy link
Collaborator

@gmicol gmicol commented Dec 12, 2024

Fixes #107

Addition of a new module nd_rest to handle generic ND REST API requests.

@gmicol gmicol added enhancement New feature or request jira-sync Sync this issue to Jira labels Dec 12, 2024
@gmicol gmicol self-assigned this Dec 12, 2024
@github-actions github-actions bot changed the title [minor_change] Add nd_rest as a new generic ND REST API module. (DNCE-242) [minor_change] Add nd_rest as a new generic ND REST API module. (DNCE-242) (DCNE-242) Dec 12, 2024
@gmicol gmicol changed the title [minor_change] Add nd_rest as a new generic ND REST API module. (DNCE-242) (DCNE-242) [minor_change] Add nd_rest as a new generic ND REST API module. (DCNE-242) Dec 12, 2024
@gmicol gmicol force-pushed the nd_rest branch 2 times, most recently from b5a4cdf to 1af8cb5 Compare December 16, 2024 17:35
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
tests/integration/inventory.networking Outdated Show resolved Hide resolved
tests/integration/inventory.networking Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Show resolved Hide resolved
…and file as input for the module. Add new tests.
@gmicol gmicol requested review from samiib and akinross January 10, 2025 18:46
plugins/module_utils/nd.py Show resolved Hide resolved
plugins/modules/nd_rest.py Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
@gmicol gmicol requested review from akinross and shrsr January 15, 2025 17:55
Comment on lines +114 to +149
- name: Create a Fabric Policy Template on NDO using POST method
cisco.nd.nd_rest:
host: nd
username: admin
password: SomeSecretPassword
path: /mso/api/v1/templates
method: post
content:
{
"displayName": "ansible_nd_rest_fabric_policies_template",
"fabricPolicyTemplate": {},
"templateType": "fabricPolicy"
}
register: create_fabric_policies_template

- name: Update Fabric Policy Template on NDO using PATCH method
cisco.nd.nd_rest:
host: nd
username: admin
password: SomeSecretPassword
path: "/mso/api/v1/templates/{{ create_fabric_policies_template.current.templateId }}"
method: patch
content:
[
{
"op": "replace",
"path": "/fabricPolicyTemplate/template/domains",
"value": [
{
"name": "ansible_nd_rest_physical_domain",
"description": "Ansible nd_rest Physical Domain test for PATCH",
"pool": ""
}
]
}
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these paths we like to expose in nd repository? since these are ndo and not nd/ndi?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not find any other paths or endpoints on which we can use PATCH operations, I only found ndo examples for PATCH operations.

plugins/modules/nd_rest.py Outdated Show resolved Hide resolved
- name: Create a Fabric Policy Template on NDO with POST method
cisco.nd.nd_rest:
<<: *nd_info
path: /mso/api/v1/templates
Copy link
Collaborator

Choose a reason for hiding this comment

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

are there no other endpoints to test PATCH for besides mso ones?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sadly I did not find any on nd side, don't know about ndi cause I do not have access to an nd cluster with ndi

nd = NDModule(module)

# Report missing file
if file_path and not os.path.isfile(file_path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we leverage pathlib library for file handling?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it could be interesting but I don't see what better improvement we can make leveraging pathlib library. I'm open to suggestions


if content and isinstance(content, str):
try:
if HAS_YAML:
Copy link
Collaborator

Choose a reason for hiding this comment

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

So if I understand correctly when the import works of yaml library the code assumes it is a yaml file? So if in your environment you have yaml library installed but pass in a json file the module will fail? Think this likely should behave differently.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, actually PyYAML library is also intended for that: it has a method safe_load to read YAML as well as JSON file/object. So in our case, when we have the library installed but want to safe load a JSON object, it will work perfectly. That's what happened when I tested, I have PyYAML installed and yet the module worked perfectly with JSON objects because this method allows us to read this type of data.

@gmicol gmicol requested a review from akinross January 22, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jira-sync Sync this issue to Jira
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic ND REST API Module (DCNE-242)
4 participants