mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
49c15c8137
commit
633b16d116
1 changed files with 19 additions and 16 deletions
|
@ -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,20 +109,22 @@ class Nxapi(object):
|
|||
response = self.module.from_json(response.read())
|
||||
result = list()
|
||||
|
||||
output = response['ins_api']['outputs']['output']
|
||||
if isinstance(output, list):
|
||||
for item in response['ins_api']['outputs']['output']:
|
||||
if item['code'] != '200':
|
||||
self.module.fail_json(msg=item['msg'], command=item['input'],
|
||||
code=item['code'])
|
||||
else:
|
||||
result.append(item['body'])
|
||||
elif output['code'] != '200':
|
||||
self.module.fail_json(msg=item['msg'], command=item['input'],
|
||||
code=item['code'])
|
||||
else:
|
||||
result.append(output['body'])
|
||||
|
||||
try:
|
||||
output = response['ins_api']['outputs']['output']
|
||||
if isinstance(output, list):
|
||||
for item in response['ins_api']['outputs']['output']:
|
||||
if item['code'] != '200':
|
||||
self.module.fail_json(msg=item['msg'], command=item['input'],
|
||||
code=item['code'])
|
||||
else:
|
||||
result.append(item['body'])
|
||||
elif output['code'] != '200':
|
||||
self.module.fail_json(msg=item['msg'], command=item['input'],
|
||||
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…
Add table
Reference in a new issue