Expose timeout option to Redfish modules (#54130)

* added timeout option to Redfish modules

* Apply suggestions from code review

Removed 'required: false' and added 'type: int' to 'timeout' documentation string.

Co-Authored-By: billdodd <billdodd@gmail.com>
pull/54415/head
Bill Dodd 6 years ago committed by John R Barker
parent a47edc9968
commit d8536e47d3

@ -15,9 +15,10 @@ HEADERS = {'content-type': 'application/json'}
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
@ -29,7 +30,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}
@ -49,7 +50,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:
@ -68,7 +69,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:
@ -87,7 +88,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:

@ -41,6 +41,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.8'
author: "Jose Delarosa (@jose-delarosa)"
'''
@ -126,7 +132,8 @@ def main():
command=dict(required=True, type='list'),
baseuri=dict(required=True),
username=dict(required=True),
password=dict(required=True, no_log=True)
password=dict(required=True, no_log=True),
timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@ -138,10 +145,13 @@ def main():
creds = {'user': module.params['username'],
'pswd': module.params['password']}
# timeout
timeout = module.params['timeout']
# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_uri = "/redfish/v1/"
rf_utils = IdracRedfishUtils(creds, root_uri)
rf_utils = IdracRedfishUtils(creds, root_uri, timeout)
# Check that Category is valid
if category not in CATEGORY_COMMANDS_ALL:

@ -68,6 +68,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.8'
author: "Jose Delarosa (@jose-delarosa)"
'''
@ -121,13 +127,14 @@ EXAMPLES = '''
id: "{{ id }}"
new_password: "{{ new_password }}"
- name: Clear Manager Logs
- name: Clear Manager Logs with a timeout of 20 seconds
redfish_command:
category: Manager
command: ClearLogs
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
timeout: 20
'''
RETURN = '''
@ -167,6 +174,7 @@ def main():
new_password=dict(no_log=True),
roleid=dict(),
bootdevice=dict(),
timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@ -184,10 +192,13 @@ def main():
'userpswd': module.params['new_password'],
'userrole': module.params['roleid']}
# 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:

@ -55,6 +55,12 @@ options:
- value of BIOS attribute to update
default: 'null'
version_added: "2.8"
timeout:
description:
- Timeout in seconds for URL requests to OOB controller
default: 10
type: int
version_added: "2.8"
author: "Jose Delarosa (@jose-delarosa)"
'''
@ -90,13 +96,14 @@ EXAMPLES = '''
username: "{{ username }}"
password: "{{ password }}"
- name: Set BIOS default settings
- name: Set BIOS default settings with a timeout of 20 seconds
redfish_config:
category: Systems
command: SetBiosDefaultSettings
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
timeout: 20
'''
RETURN = '''
@ -129,6 +136,7 @@ def main():
password=dict(required=True, no_log=True),
bios_attribute_name=dict(default='null'),
bios_attribute_value=dict(default='null'),
timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@ -140,6 +148,9 @@ def main():
creds = {'user': module.params['username'],
'pswd': module.params['password']}
# timeout
timeout = module.params['timeout']
# BIOS attributes to update
bios_attributes = {'bios_attr_name': module.params['bios_attribute_name'],
'bios_attr_value': module.params['bios_attribute_value']}
@ -147,7 +158,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:

@ -43,6 +43,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.8'
author: "Jose Delarosa (@jose-delarosa)"
'''
@ -68,13 +74,14 @@ EXAMPLES = '''
- debug:
msg: "{{ redfish_facts.cpu.entries.0.Model }}"
- name: Get fan inventory
- name: Get fan inventory with a timeout of 20 seconds
redfish_facts:
category: Chassis
command: GetFanInventory
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
timeout: 20
- name: Get default inventory information
redfish_facts:
@ -172,6 +179,7 @@ def main():
baseuri=dict(required=True),
username=dict(required=True),
password=dict(required=True, no_log=True),
timeout=dict(type='int', default=10)
),
supports_check_mode=False
)
@ -180,10 +188,13 @@ def main():
creds = {'user': module.params['username'],
'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']:

Loading…
Cancel
Save