mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
add timeout parameter and increase default timeout for nso modules (#37391)
NSO operations can take much longer than 10 seconds as they operate on real network equipment, set default timeout to 5 minutes and allow for user override.
This commit is contained in:
parent
e166946a0a
commit
458a07d5a4
4 changed files with 22 additions and 15 deletions
|
@ -36,7 +36,8 @@ except NameError:
|
|||
nso_argument_spec = dict(
|
||||
url=dict(required=True),
|
||||
username=dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME']), required=True),
|
||||
password=dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), required=True, no_log=True)
|
||||
password=dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), required=True, no_log=True),
|
||||
timeout=dict(default=300, type=int)
|
||||
)
|
||||
|
||||
|
||||
|
@ -66,8 +67,9 @@ class NsoException(Exception):
|
|||
|
||||
|
||||
class JsonRpc(object):
|
||||
def __init__(self, url):
|
||||
def __init__(self, url, timeout):
|
||||
self._url = url
|
||||
self._timeout = timeout
|
||||
|
||||
self._id = 0
|
||||
self._trans = {}
|
||||
|
@ -219,7 +221,8 @@ class JsonRpc(object):
|
|||
|
||||
data = json.dumps(payload)
|
||||
resp = open_url(
|
||||
self._url, method='POST', data=data, headers=self._headers)
|
||||
self._url, timeout=self._timeout,
|
||||
method='POST', data=data, headers=self._headers)
|
||||
if resp.code != 200:
|
||||
raise NsoException(
|
||||
'NSO returned HTTP code {0}, expected 200'.format(resp.status), {})
|
||||
|
@ -620,7 +623,7 @@ class ValueBuilder(object):
|
|||
|
||||
|
||||
def connect(params):
|
||||
client = JsonRpc(params['url'])
|
||||
client = JsonRpc(params['url'], params['timeout'])
|
||||
client.login(params['username'], params['password'])
|
||||
return client
|
||||
|
||||
|
|
|
@ -32,4 +32,8 @@ options:
|
|||
password:
|
||||
description: NSO password
|
||||
required: true
|
||||
timeout:
|
||||
description: JSON-RPC request timeout in seconds
|
||||
default: 300
|
||||
version_added: "2.6"
|
||||
'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue