-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: master
Are you sure you want to change the base?
Conversation
b5a4cdf
to
1af8cb5
Compare
…and file as input for the module. Add new tests.
…ection for nd_rest module.
- 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": "" | ||
} | ||
] | ||
} | ||
] |
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.
are these paths we like to expose in nd repository? since these are ndo and not nd/ndi?
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 did not find any other paths or endpoints on which we can use PATCH operations, I only found ndo examples for PATCH operations.
- name: Create a Fabric Policy Template on NDO with POST method | ||
cisco.nd.nd_rest: | ||
<<: *nd_info | ||
path: /mso/api/v1/templates |
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.
are there no other endpoints to test PATCH for besides mso ones?
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.
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): |
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 leverage pathlib library for file handling?
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.
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: |
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.
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.
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.
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.
Fixes #107
Addition of a new module
nd_rest
to handle generic ND REST API requests.