Skip to content

Commit

Permalink
Merge pull request #130 from CiscoDevNet/2.0.1
Browse files Browse the repository at this point in the history
Release 2.0.1
  • Loading branch information
mikewiebe authored Jan 28, 2022
2 parents e7a84d4 + 392abd4 commit ddec6f9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 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/).

## Unreleased

## [2.0.1] - 2022-01-28

Fixed httpapi plugin issue preventing connections to latest version of NDFC (Version: `12.0.2f`)

## [2.0.0] - 2021-12-13

### Added
Expand Down Expand Up @@ -139,6 +145,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.
[2.0.1]: https://github.com/CiscoDevNet/ansible-dcnm/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.2.4...2.0.0
[1.2.4]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.2.3...1.2.4
[1.2.3]: https://github.com/CiscoDevNet/ansible-dcnm/compare/1.2.2...1.2.3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You can also include it in a `requirements.yml` file and install it with `ansibl
---
collections:
- name: cisco.dcnm
version: 2.0.0
version: 2.0.1
```
## Using this collection
Expand Down Expand Up @@ -178,7 +178,7 @@ We welcome community contributions to this collection. If you find problems, ple

## Licensing

Copyright (c) 2020-2021 Cisco and/or its affiliates.
Copyright (c) 2020-2022 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
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: 2.0.0
version: 2.0.1
readme: README.md
authors:
- Shrishail Kariyappanavar <nkshrishail>
Expand Down
29 changes: 27 additions & 2 deletions plugins/httpapi/dcnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _login_old(self, username, password, method, path):
except Exception as e:
self.login_fail_msg.append('Error on attempt to connect and authenticate with DCNM controller: {}'.format(e))

def _login_latest(self, username, password, method, path):
def _login_latestv1(self, username, password, method, path):
''' Nexus Dashboard NDFC Helper Function to login to NDFC version 12 or later.
'''
login_domain = 'DefaultAuth'
Expand All @@ -99,6 +99,27 @@ def _login_latest(self, username, password, method, path):
except Exception as e:
self.login_fail_msg.append('Error on attempt to connect and authenticate with NDFC controller: {}'.format(e))

def _login_latestv2(self, username, password, method, path):
''' Nexus Dashboard NDFC Helper Function to login to NDFC version 12 or later.
'''
login_domain = 'DefaultAuth'
# login_domain = 'local'
payload = {'userName': self.connection.get_option('remote_user'), 'userPasswd': self.connection.get_option('password'), 'domain': login_domain}
data = json.dumps(payload)
try:
response, response_data = self.connection.send(path, data, method=method, headers=self.headers)
vrd = self._verify_response(response, method, path, response_data)
if vrd['RETURN_CODE'] != 200:
self.login_fail_msg.append('Error on attempt to connect and authenticate with NDFC controller: {}'.format(vrd))
return

self.connection._auth = {'Authorization': 'Bearer {0}'.format(self._response_to_json12(response_data).get('token'))}
self.login_succeeded = True
self.set_version(12)

except Exception as e:
self.login_fail_msg.append('Error on attempt to connect and authenticate with NDFC controller: {}'.format(e))

def login(self, username, password):
''' DCNM/NDFC Login Method. This method is automatically called by the
Ansible plugin architecture if an active Token is not already
Expand All @@ -108,13 +129,17 @@ def login(self, username, password):
self.login_fail_msg = []
method = 'POST'
path = {'dcnm': '/rest/logon', 'ndfc': '/login'}
login12Func = [self._login_latestv2, self._login_latestv1]

# Attempt to login to DCNM version 11
self._login_old(username, password, method, path['dcnm'])

# If login attempt failed then try NDFC version 12
if not self.login_succeeded:
self._login_latest(username, password, method, path['ndfc'])
for func in login12Func:
func(username, password, method, path['ndfc'])
if self.login_succeeded:
break

# If both login attemps fail, raise ConnectionError
if not self.login_succeeded:
Expand Down

0 comments on commit ddec6f9

Please sign in to comment.