From b7e6ace4eeaf931cd504b3d3e57360b3c2e0bd0a Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 2 Nov 2016 08:32:19 -0500 Subject: [PATCH] Add timeout option for nxapi (#18074) * 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 --- lib/ansible/module_utils/nxos.py | 5 +++-- lib/ansible/utils/module_docs_fragments/nxos.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 86918f7004..1f6d627405 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -128,6 +128,7 @@ class Nxapi(NxapiConfigMixin): 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 @@ class Nxapi(NxapiConfigMixin): 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') diff --git a/lib/ansible/utils/module_docs_fragments/nxos.py b/lib/ansible/utils/module_docs_fragments/nxos.py index 5cb9e695d8..c209f1d6c4 100644 --- a/lib/ansible/utils/module_docs_fragments/nxos.py +++ b/lib/ansible/utils/module_docs_fragments/nxos.py @@ -73,6 +73,13 @@ options: 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