Skip to content

Commit 53eb80e

Browse files
committed
Fixes to address issues raised in sanity and galaxy import checks in HTTPAPI connection plugin, documentation and module library.
1 parent af3574b commit 53eb80e

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

plugins/doc_fragments/modules.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class ModuleDocFragment(object):
1616
- IP Address or hostname of the Nexus Dashboard (ND) host.
1717
- If the value is not specified in the task, the value of environment variable C(ND_HOST) will be used instead.
1818
type: str
19-
required: yes
2019
aliases: [ hostname ]
2120
port:
2221
description:
@@ -35,7 +34,6 @@ class ModuleDocFragment(object):
3534
- The password to use for authentication.
3635
- 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.
3736
type: str
38-
required: yes
3937
output_level:
4038
description:
4139
- Influence the output of this ND module.
@@ -77,6 +75,7 @@ class ModuleDocFragment(object):
7775
- The default value is Local.
7876
- If the value is not specified in the task, the value of environment variable C(ND_LOGIN_DOMAIN) will be used instead.
7977
type: str
78+
default: local
8079
requirements:
8180
- Nexus Dashboard v2.0 or newer
8281
notes:

plugins/httpapi/nd.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
DOCUMENTATION = """
2020
---
21-
author:
21+
author:
2222
- Lionel Hercot (lhercot)
2323
httpapi: aci
2424
short_description: Nexus Dashboard Ansible HTTPAPI Plugin.
@@ -32,7 +32,6 @@
3232
import json
3333
import re
3434
import pickle
35-
import ipaddress
3635
import traceback
3736

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

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

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

130+
if data is None:
131+
data = {}
132+
131133
self.connection.queue_message('vvvv', 'send_request method called')
132134
# # Case1: List of hosts is provided
133135
# self.backup_hosts = self.set_backup_hosts()
134136
# if not self.backup_hosts:
135137
if self.connection._connected is True and self.params.get('host') != self.connection.get_option('host'):
136138
self.connection._connected = False
137-
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')))
139+
self.connection.queue_message(
140+
'vvvv',
141+
'send_request reseting connection as host has changed from {0} to {1}'.format(
142+
self.connection.get_option('host'), self.params.get('host')
143+
)
144+
)
138145

139146
if self.params.get('host') is not None:
140147
self.connection.set_option('host', self.params.get('host'))
@@ -177,7 +184,7 @@ def send_request(self, method, path, data={}):
177184
try:
178185
self.connection.queue_message('vvvv', 'send_request() - connection.send({0}, {1}, {2}, {3})'.format(path, data, method, self.headers))
179186
response, rdata = self.connection.send(path, data, method=method, headers=self.headers)
180-
except ConnectionError as conn_e:
187+
except ConnectionError:
181188
self.connection.queue_message('vvvv', 'login() - ConnectionError Exception')
182189
raise
183190
except Exception as e:
@@ -244,7 +251,7 @@ def _response_to_json(self, response_data):
244251
return
245252

246253
def _get_formated_info(self, response):
247-
''' 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 '''
254+
''' 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 '''
248255
info = dict(msg="OK (%s bytes)" % response.headers.get('Content-Length', 'unknown'), url=response.geturl(), status=response.getcode())
249256
# Lowercase keys, to conform to py2 behavior, so that py3 and py2 are predictable
250257
info.update(dict((k.lower(), v) for k, v in response.info().items()))
@@ -261,4 +268,4 @@ def _get_formated_info(self, response):
261268
else:
262269
temp_headers[name] = value
263270
info.update(temp_headers)
264-
return info
271+
return info

plugins/module_utils/nd.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,16 @@
77
__metaclass__ = type
88

99
from copy import deepcopy
10-
import re
1110
import os
12-
import datetime
1311
import shutil
1412
import tempfile
15-
import traceback
1613
from ansible.module_utils.basic import json
1714
from ansible.module_utils.basic import env_fallback
1815
from ansible.module_utils.six import PY3
1916
from ansible.module_utils.six.moves import filterfalse
20-
from ansible.module_utils.six.moves.urllib.parse import urlencode, urljoin
21-
from ansible.module_utils.urls import fetch_url
17+
from ansible.module_utils.six.moves.urllib.parse import urlencode
2218
from ansible.module_utils._text import to_native, to_text
2319
from ansible.module_utils.connection import Connection
24-
try:
25-
from requests_toolbelt.multipart.encoder import MultipartEncoder
26-
HAS_MULTIPART_ENCODER = True
27-
except ImportError:
28-
HAS_MULTIPART_ENCODER = False
2920

3021

3122
if PY3:

0 commit comments

Comments
 (0)