summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Dodd <billdodd@gmail.com>2019-03-26 12:19:24 -0500
committerToshio Kuratomi <a.badger@gmail.com>2019-05-20 18:33:27 -0700
commit61643874f2fc21ad23b37890f1f80da4092eeb26 (patch)
treed3834776799b91f981fc886c849dbb1181afe335
parentaa616b436c5ba443de4685ba496464fb25a896da (diff)
downloadansible-61643874f2fc21ad23b37890f1f80da4092eeb26.tar.gz
Expose timeout option to Redfish modules
(cherry picked from commit d8536e47d3fe1d31412f192ce567a9780ae0d521)
-rw-r--r--changelogs/fragments/54130-fix-missing-timeout-in-redfish_utils.yaml2
-rw-r--r--lib/ansible/module_utils/redfish_utils.py11
-rw-r--r--lib/ansible/modules/remote_management/redfish/redfish_command.py15
-rw-r--r--lib/ansible/modules/remote_management/redfish/redfish_config.py16
-rw-r--r--lib/ansible/modules/remote_management/redfish/redfish_facts.py15
5 files changed, 48 insertions, 11 deletions
diff --git a/changelogs/fragments/54130-fix-missing-timeout-in-redfish_utils.yaml b/changelogs/fragments/54130-fix-missing-timeout-in-redfish_utils.yaml
new file mode 100644
index 0000000000..a4d3709e62
--- /dev/null
+++ b/changelogs/fragments/54130-fix-missing-timeout-in-redfish_utils.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - redfish_utils - expose timeout option for redfish implementations that exceed the 10 second default
diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py
index 47fb6b0868..001b5aa464 100644
--- a/lib/ansible/module_utils/redfish_utils.py
+++ b/lib/ansible/module_utils/redfish_utils.py
@@ -19,9 +19,10 @@ DELETE_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
class RedfishUtils(object):
- def __init__(self, creds, root_uri):
+ def __init__(self, creds, root_uri, timeout):
self.root_uri = root_uri
self.creds = creds
+ self.timeout = timeout
self._init_session()
return
@@ -33,7 +34,7 @@ class RedfishUtils(object):
url_password=self.creds['pswd'],
force_basic_auth=True, validate_certs=False,
follow_redirects='all',
- use_proxy=False)
+ use_proxy=False, timeout=self.timeout)
data = json.loads(resp.read())
except HTTPError as e:
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
@@ -52,7 +53,7 @@ class RedfishUtils(object):
url_password=self.creds['pswd'],
force_basic_auth=True, validate_certs=False,
follow_redirects='all',
- use_proxy=False)
+ use_proxy=False, timeout=self.timeout)
except HTTPError as e:
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
except URLError as e:
@@ -70,7 +71,7 @@ class RedfishUtils(object):
url_password=self.creds['pswd'],
force_basic_auth=True, validate_certs=False,
follow_redirects='all',
- use_proxy=False)
+ use_proxy=False, timeout=self.timeout)
except HTTPError as e:
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
except URLError as e:
@@ -88,7 +89,7 @@ class RedfishUtils(object):
url_password=self.creds['pswd'],
force_basic_auth=True, validate_certs=False,
follow_redirects='all',
- use_proxy=False)
+ use_proxy=False, timeout=self.timeout)
except HTTPError as e:
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
except URLError as e:
diff --git a/lib/ansible/modules/remote_management/redfish/redfish_command.py b/lib/ansible/modules/remote_management/redfish/redfish_command.py
index 6508d5e994..ea7715ae25 100644
--- a/lib/ansible/modules/remote_management/redfish/redfish_command.py
+++ b/lib/ansible/modules/remote_management/redfish/redfish_command.py
@@ -63,6 +63,12 @@ options:
required: false
description:
- bootdevice when setting boot configuration
+ timeout:
+ description:
+ - Timeout in seconds for URL requests to OOB controller
+ default: 10
+ type: int
+ version_added: '2.7.11'
author: "Jose Delarosa (github: jose-delarosa)"
'''
@@ -116,13 +122,14 @@ EXAMPLES = '''
userid: "{{ userid }}"
userpswd: "{{ userpswd }}"
- - name: Clear Manager Logs
+ - name: Clear Manager Logs with a timeout of 20 seconds
redfish_command:
category: Manager
command: ClearLogs
baseuri: "{{ baseuri }}"
user: "{{ user }}"
password: "{{ password }}"
+ timeout: 20
'''
RETURN = '''
@@ -163,6 +170,7 @@ def main():
userpswd=dict(no_log=True),
userrole=dict(),
bootdevice=dict(),
+ timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@@ -180,10 +188,13 @@ def main():
'userpswd': module.params['userpswd'],
'userrole': module.params['userrole']}
+ # timeout
+ timeout = module.params['timeout']
+
# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_uri = "/redfish/v1/"
- rf_utils = RedfishUtils(creds, root_uri)
+ rf_utils = RedfishUtils(creds, root_uri, timeout)
# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL:
diff --git a/lib/ansible/modules/remote_management/redfish/redfish_config.py b/lib/ansible/modules/remote_management/redfish/redfish_config.py
index 16eae01671..c8514e5eb0 100644
--- a/lib/ansible/modules/remote_management/redfish/redfish_config.py
+++ b/lib/ansible/modules/remote_management/redfish/redfish_config.py
@@ -62,6 +62,12 @@ options:
description:
- value of Manager attribute to update
default: 'null'
+ timeout:
+ description:
+ - Timeout in seconds for URL requests to OOB controller
+ default: 10
+ type: int
+ version_added: "2.7.11"
author: "Jose Delarosa (github: jose-delarosa)"
'''
@@ -97,7 +103,7 @@ EXAMPLES = '''
user: "{{ user }}"
password: "{{ password }}"
- - name: Set BIOS default settings
+ - name: Set BIOS default settings with a timeout of 20 seconds
redfish_config:
category: Systems
command: SetBiosDefaultSettings
@@ -134,6 +140,7 @@ EXAMPLES = '''
baseuri: "{{ baseuri }}"
user: "{{ user}}"
password: "{{ password }}"
+ timeout: 20
'''
RETURN = '''
@@ -169,6 +176,7 @@ def main():
mgr_attr_value=dict(default='null'),
bios_attr_name=dict(default='null'),
bios_attr_value=dict(default='null'),
+ timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@@ -183,6 +191,10 @@ def main():
# Manager attributes to update
mgr_attributes = {'mgr_attr_name': module.params['mgr_attr_name'],
'mgr_attr_value': module.params['mgr_attr_value']}
+
+ # timeout
+ timeout = module.params['timeout']
+
# BIOS attributes to update
bios_attributes = {'bios_attr_name': module.params['bios_attr_name'],
'bios_attr_value': module.params['bios_attr_value']}
@@ -190,7 +202,7 @@ def main():
# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_uri = "/redfish/v1/"
- rf_utils = RedfishUtils(creds, root_uri)
+ rf_utils = RedfishUtils(creds, root_uri, timeout)
# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL:
diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py
index ce783ddd0a..fa863f33be 100644
--- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py
+++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py
@@ -42,6 +42,12 @@ options:
required: true
description:
- Password for authentication with OOB controller
+ timeout:
+ description:
+ - Timeout in seconds for URL requests to OOB controller
+ default: 10
+ type: int
+ version_added: '2.7.11'
author: "Jose Delarosa (github: jose-delarosa)"
'''
@@ -55,13 +61,14 @@ EXAMPLES = '''
user: "{{ user }}"
password: "{{ password }}"
- - name: Get fan inventory
+ - name: Get fan inventory with a timeout of 20 seconds
redfish_facts:
category: Chassis
command: GetFanInventory
baseuri: "{{ baseuri }}"
user: "{{ user }}"
password: "{{ password }}"
+ timeout: 20
- name: Get default inventory information
redfish_facts:
@@ -149,6 +156,7 @@ def main():
baseuri=dict(required=True),
user=dict(required=True),
password=dict(required=True, no_log=True),
+ timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@@ -157,10 +165,13 @@ def main():
creds = {'user': module.params['user'],
'pswd': module.params['password']}
+ # timeout
+ timeout = module.params['timeout']
+
# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_uri = "/redfish/v1"
- rf_utils = RedfishUtils(creds, root_uri)
+ rf_utils = RedfishUtils(creds, root_uri, timeout)
# Build Category list
if "all" in module.params['category']: