add exeception handling for invalid commands over nxapi

This commit will catch invalid commands being send over nxapi and call
fail_json on the module.  The nxos shared module will now return the
failure
pull/14234/head
Peter Sprygada 9 years ago
parent 49c15c8137
commit 633b16d116

@ -100,8 +100,8 @@ class Nxapi(object):
headers = {'Content-Type': 'application/json'}
response, headers = fetch_url(self.module, self.url, data=data, headers=headers,
method='POST')
response, headers = fetch_url(self.module, self.url, data=data,
headers=headers, method='POST')
if headers['status'] != 200:
self.module.fail_json(**headers)
@ -109,6 +109,7 @@ class Nxapi(object):
response = self.module.from_json(response.read())
result = list()
try:
output = response['ins_api']['outputs']['output']
if isinstance(output, list):
for item in response['ins_api']['outputs']['output']:
@ -122,7 +123,8 @@ class Nxapi(object):
code=item['code'])
else:
result.append(output['body'])
except Exception:
self.module.fail_json(**headers)
return result
@ -200,6 +202,7 @@ class NetworkModule(AnsibleModule):
cmd = 'show running-config'
if self.params.get('include_defaults'):
cmd += ' all'
if self.params['transport'] == 'cli':
return self.execute(cmd)[0]
else:

Loading…
Cancel
Save