Skip to content

Commit

Permalink
Fixes to address issues raised in sanity and galaxy import checks in …
Browse files Browse the repository at this point in the history
…HTTPAPI connection plugin, documentation and module library.
  • Loading branch information
lhercot committed Jun 2, 2021
1 parent af3574b commit 53eb80e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
3 changes: 1 addition & 2 deletions plugins/doc_fragments/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ModuleDocFragment(object):
- IP Address or hostname of the Nexus Dashboard (ND) host.
- If the value is not specified in the task, the value of environment variable C(ND_HOST) will be used instead.
type: str
required: yes
aliases: [ hostname ]
port:
description:
Expand All @@ -35,7 +34,6 @@ class ModuleDocFragment(object):
- The password to use for authentication.
- If the value is not specified in the task, the value of environment variables C(ND_PASSWORD) or C(ANSIBLE_NET_PASSWORD) will be used instead.
type: str
required: yes
output_level:
description:
- Influence the output of this ND module.
Expand Down Expand Up @@ -77,6 +75,7 @@ class ModuleDocFragment(object):
- The default value is Local.
- If the value is not specified in the task, the value of environment variable C(ND_LOGIN_DOMAIN) will be used instead.
type: str
default: local
requirements:
- Nexus Dashboard v2.0 or newer
notes:
Expand Down
21 changes: 14 additions & 7 deletions plugins/httpapi/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

DOCUMENTATION = """
---
author:
author:
- Lionel Hercot (lhercot)
httpapi: aci
short_description: Nexus Dashboard Ansible HTTPAPI Plugin.
Expand All @@ -32,7 +32,6 @@
import json
import re
import pickle
import ipaddress
import traceback

from ansible.module_utils.six import PY3
Expand Down Expand Up @@ -119,7 +118,7 @@ def logout(self):
raise ConnectionError(json.dumps(self._verify_response(None, method, self.connection.get_option('host') + path, None)))
self.connection._auth = None

def send_request(self, method, path, data={}):
def send_request(self, method, path, data=None):
''' This method handles all ND REST API requests other than login '''

self.error = None
Expand All @@ -128,13 +127,21 @@ def send_request(self, method, path, data={}):
self.info = {}
self.method = 'GET'

if data is None:
data = {}

self.connection.queue_message('vvvv', 'send_request method called')
# # Case1: List of hosts is provided
# self.backup_hosts = self.set_backup_hosts()
# if not self.backup_hosts:
if self.connection._connected is True and self.params.get('host') != self.connection.get_option('host'):
self.connection._connected = False
self.connection.queue_message('vvvv', 'send_request reseting connection as host has changed from {0} to {1}'.format(self.connection.get_option('host'), self.params.get('host')))
self.connection.queue_message(
'vvvv',
'send_request reseting connection as host has changed from {0} to {1}'.format(
self.connection.get_option('host'), self.params.get('host')
)
)

if self.params.get('host') is not None:
self.connection.set_option('host', self.params.get('host'))
Expand Down Expand Up @@ -177,7 +184,7 @@ def send_request(self, method, path, data={}):
try:
self.connection.queue_message('vvvv', 'send_request() - connection.send({0}, {1}, {2}, {3})'.format(path, data, method, self.headers))
response, rdata = self.connection.send(path, data, method=method, headers=self.headers)
except ConnectionError as conn_e:
except ConnectionError:
self.connection.queue_message('vvvv', 'login() - ConnectionError Exception')
raise
except Exception as e:
Expand Down Expand Up @@ -244,7 +251,7 @@ def _response_to_json(self, response_data):
return

def _get_formated_info(self, response):
''' The code in this function is based out of Ansible fetch_url code at https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py '''
''' The code in this function is based on Ansible fetch_url code at https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py '''
info = dict(msg="OK (%s bytes)" % response.headers.get('Content-Length', 'unknown'), url=response.geturl(), status=response.getcode())
# Lowercase keys, to conform to py2 behavior, so that py3 and py2 are predictable
info.update(dict((k.lower(), v) for k, v in response.info().items()))
Expand All @@ -261,4 +268,4 @@ def _get_formated_info(self, response):
else:
temp_headers[name] = value
info.update(temp_headers)
return info
return info
11 changes: 1 addition & 10 deletions plugins/module_utils/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@
__metaclass__ = type

from copy import deepcopy
import re
import os
import datetime
import shutil
import tempfile
import traceback
from ansible.module_utils.basic import json
from ansible.module_utils.basic import env_fallback
from ansible.module_utils.six import PY3
from ansible.module_utils.six.moves import filterfalse
from ansible.module_utils.six.moves.urllib.parse import urlencode, urljoin
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.connection import Connection
try:
from requests_toolbelt.multipart.encoder import MultipartEncoder
HAS_MULTIPART_ENCODER = True
except ImportError:
HAS_MULTIPART_ENCODER = False


if PY3:
Expand Down

0 comments on commit 53eb80e

Please sign in to comment.