Skip to content

Commit

Permalink
Merge pull request #97 from CiscoDevNet/1.2.1
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
mikewiebe authored Oct 6, 2021
2 parents 79fcc03 + 9fdb353 commit bab02a1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.1] - 2021-10

### Added

Added support for plain text payloads to `dcnm_rest` module

## [1.2.0] - 2021-07

### Added
Expand Down Expand Up @@ -95,6 +101,7 @@ The Ansible Cisco Data Center Network Manager (DCNM) collection includes modules
* cisco.dcnm.dcnm_network - Add and remove Networks from a DCNM managed VXLAN fabric.
* cisco.dcnm.dcnm_interface - DCNM Ansible Module for managing interfaces.
[1.2.1]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.2.0...1.2.1
[1.2.0]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.1.1...1.2.0
[1.1.1]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.0.0...1.1.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ You can also include it in a `requirements.yml` file and install it with `ansibl
---
collections:
- name: cisco.dcnm
version: 1.2.0
version: 1.2.1
```
## Using this collection
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: cisco
name: dcnm
version: 1.2.0
version: 1.2.1
readme: README.md
authors:
- Shrishail Kariyappanavar <nkshrishail>
Expand Down
61 changes: 47 additions & 14 deletions plugins/modules/dcnm_rest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
# Copyright (c) 2020 Cisco and/or its affiliates.
# Copyright (c) 2020-2021 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,9 +33,12 @@
description:
- 'REST API Path Endpoint'
required: yes
json_data:
type: str
data:
description:
- 'Additional JSON data to include with the REST API call'
- 'Additional data in JSON or TEXT to include with the REST API call'
aliases:
- json_data
required: no
author:
- Mike Wiebe (@mikewiebe)
Expand All @@ -52,6 +55,24 @@
dcnm_rest:
method: GET
path: /rest/control/fabrics
- name: Set deployment to false in lanAttachList for vrf
dcnm_rest:
method: POST
path: /rest/top-down/fabrics/fabric1/vrfs/attachments
json_data: '[{"vrfName":"sales66_vrf1","lanAttachList":[{"fabric":"fabric1","vrfName":"sales66_vrf1","serialNumber":"FDO21392QKM","vlan":2000,"freeformConfig":"","deployment":false,"extensionValues":"","instanceValues":"{\"loopbackId\":\"\",\"loopbackIpAddress\":\"\",\"loopbackIpV6Address\":\"\"}"}]}]'
# Read payload data from file and validate a template
- set_fact:
data: "{{ lookup('file', 'validate_payload') }}"
- name: Validate a template
cisco.dcnm.dcnm_rest:
method: POST
path: /fm/fmrest/config/templates/validate
json_data: "{{ data }}"
register: result
'''

RETURN = '''
Expand All @@ -61,16 +82,21 @@
elements: dict
'''

import json
from json.decoder import JSONDecodeError
from ansible.module_utils.connection import Connection
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.dcnm.plugins.module_utils.network.dcnm.dcnm import (
dcnm_send,
)


def main():
# define available arguments/parameters a user can pass to the module
argument_spec = dict(
method=dict(required=True, choices=['GET', 'POST', 'PUT', 'DELETE']),
path=dict(required=True, type='str'),
json_data=dict(type='raw', required=False, default=None))
data=dict(type='raw', required=False, default=None, aliases=["json_data"]))

# seed the result dict
result = dict(
Expand All @@ -85,16 +111,23 @@ def main():

method = module.params['method']
path = module.params['path']
json_data = {}
if module.params['json_data'] is not None:
json_data = module.params['json_data']

conn = Connection(module._socket_path)
result['response'] = conn.send_request(method, path, json_data)

res = result['response']
if res and res['RETURN_CODE'] >= 400:
module.fail_json(msg=res)
for key in ['json_data', 'data']:
data = module.params.get(key)
if data is not None:
break
if data is None:
data = "{}"

# Determine if this is valid JSON or not
try:
json.loads(data)
result['response'] = dcnm_send(module, method, path, data)
except json.JSONDecodeError:
# Resend data as text since it's not valid JSON
result['response'] = dcnm_send(module, method, path, data, "text")

if result['response']['RETURN_CODE'] >= 400:
module.fail_json(msg=result['response'])

module.exit_json(**result)

Expand Down

0 comments on commit bab02a1

Please sign in to comment.