Skip to content

Commit

Permalink
Add timeout option for nxapi (ansible#18074)
Browse files Browse the repository at this point in the history
* Changes to be committed:
	modified:   lib/ansible/module_utils/nxos.py
    - added configurable timeout to module paramaters
	modified:   lib/ansible/utils/module_docs_fragments/nxos.py
    - added documentation for timeout

* Changes to be committed:
    modified:   ansible/module_utils/nxos.py
    - added timeout option for nxapi transport and added documentation
    - option works with CLI or NXAPI transport

*  Changes to be committed:
	modified:   lib/ansible/utils/module_docs_fragments/nxos.py
    - Changed per comments in PR 18074

*  Changes to be committed:
	modified:   lib/ansible/module_utils/nxos.py
    - added try/except block to test for timeout

* Changes to be committed:
modified:   lib/ansible/module_utils/nxos.py
 - tweaked timeout
dgjustice authored and gundalow committed Nov 2, 2016
1 parent 333f6d4 commit b7e6ace
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ansible/module_utils/nxos.py
Original file line number Diff line number Diff line change
@@ -128,6 +128,7 @@ def connect(self, params, **kwargs):
self.url_args.params['url_username'] = params['username']
self.url_args.params['url_password'] = params['password']
self.url_args.params['validate_certs'] = params['validate_certs']
self.url_args.params['timeout'] = params['timeout']

if params['use_ssl']:
proto = 'https'
@@ -170,13 +171,13 @@ def execute(self, commands, output=None, **kwargs):

headers = {'Content-Type': 'application/json'}
result = list()

timeout = self.url_args.params['timeout']
for req in requests:
if self._nxapi_auth:
headers['Cookie'] = self._nxapi_auth

response, headers = fetch_url(
self.url_args, self.url, data=data, headers=headers, method='POST'
self.url_args, self.url, data=data, headers=headers, timeout=timeout, method='POST'
)
self._nxapi_auth = headers.get('set-cookie')

7 changes: 7 additions & 0 deletions lib/ansible/utils/module_docs_fragments/nxos.py
Original file line number Diff line number Diff line change
@@ -73,6 +73,13 @@ class ModuleDocFragment(object):
required: false
default: no
choices: ['yes', 'no']
timeout:
description:
- Specifies idle timeout in seconds. NX-API can be slow to
return on long-running commands (sh mac, sh bgp, etc).
required: false
default: 10
version_added: 2.3
provider:
description:
- Convenience method that allows all I(nxos) arguments to be passed as

0 comments on commit b7e6ace

Please sign in to comment.