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>
This commit is contained in:
parent
a47edc9968
commit
d8536e47d3
5 changed files with 57 additions and 13 deletions
|
@ -15,9 +15,10 @@ HEADERS = {'content-type': 'application/json'}
|
||||||
|
|
||||||
class RedfishUtils(object):
|
class RedfishUtils(object):
|
||||||
|
|
||||||
def __init__(self, creds, root_uri):
|
def __init__(self, creds, root_uri, timeout):
|
||||||
self.root_uri = root_uri
|
self.root_uri = root_uri
|
||||||
self.creds = creds
|
self.creds = creds
|
||||||
|
self.timeout = timeout
|
||||||
self._init_session()
|
self._init_session()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ class RedfishUtils(object):
|
||||||
url_password=self.creds['pswd'],
|
url_password=self.creds['pswd'],
|
||||||
force_basic_auth=True, validate_certs=False,
|
force_basic_auth=True, validate_certs=False,
|
||||||
follow_redirects='all',
|
follow_redirects='all',
|
||||||
use_proxy=False)
|
use_proxy=False, timeout=self.timeout)
|
||||||
data = json.loads(resp.read())
|
data = json.loads(resp.read())
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
||||||
|
@ -49,7 +50,7 @@ class RedfishUtils(object):
|
||||||
url_password=self.creds['pswd'],
|
url_password=self.creds['pswd'],
|
||||||
force_basic_auth=True, validate_certs=False,
|
force_basic_auth=True, validate_certs=False,
|
||||||
follow_redirects='all',
|
follow_redirects='all',
|
||||||
use_proxy=False)
|
use_proxy=False, timeout=self.timeout)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
|
@ -68,7 +69,7 @@ class RedfishUtils(object):
|
||||||
url_password=self.creds['pswd'],
|
url_password=self.creds['pswd'],
|
||||||
force_basic_auth=True, validate_certs=False,
|
force_basic_auth=True, validate_certs=False,
|
||||||
follow_redirects='all',
|
follow_redirects='all',
|
||||||
use_proxy=False)
|
use_proxy=False, timeout=self.timeout)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
|
@ -87,7 +88,7 @@ class RedfishUtils(object):
|
||||||
url_password=self.creds['pswd'],
|
url_password=self.creds['pswd'],
|
||||||
force_basic_auth=True, validate_certs=False,
|
force_basic_auth=True, validate_certs=False,
|
||||||
follow_redirects='all',
|
follow_redirects='all',
|
||||||
use_proxy=False)
|
use_proxy=False, timeout=self.timeout)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
return {'ret': False, 'msg': "HTTP Error: %s" % e.code}
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
|
|
|
@ -41,6 +41,12 @@ options:
|
||||||
required: true
|
required: true
|
||||||
description:
|
description:
|
||||||
- Password for authentication with OOB controller
|
- 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)"
|
author: "Jose Delarosa (@jose-delarosa)"
|
||||||
'''
|
'''
|
||||||
|
@ -126,7 +132,8 @@ def main():
|
||||||
command=dict(required=True, type='list'),
|
command=dict(required=True, type='list'),
|
||||||
baseuri=dict(required=True),
|
baseuri=dict(required=True),
|
||||||
username=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
|
supports_check_mode=False
|
||||||
)
|
)
|
||||||
|
@ -138,10 +145,13 @@ def main():
|
||||||
creds = {'user': module.params['username'],
|
creds = {'user': module.params['username'],
|
||||||
'pswd': module.params['password']}
|
'pswd': module.params['password']}
|
||||||
|
|
||||||
|
# timeout
|
||||||
|
timeout = module.params['timeout']
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_uri = "/redfish/v1/"
|
||||||
rf_utils = IdracRedfishUtils(creds, root_uri)
|
rf_utils = IdracRedfishUtils(creds, root_uri, timeout)
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
|
|
@ -68,6 +68,12 @@ options:
|
||||||
required: false
|
required: false
|
||||||
description:
|
description:
|
||||||
- bootdevice when setting boot configuration
|
- 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)"
|
author: "Jose Delarosa (@jose-delarosa)"
|
||||||
'''
|
'''
|
||||||
|
@ -121,13 +127,14 @@ EXAMPLES = '''
|
||||||
id: "{{ id }}"
|
id: "{{ id }}"
|
||||||
new_password: "{{ new_password }}"
|
new_password: "{{ new_password }}"
|
||||||
|
|
||||||
- name: Clear Manager Logs
|
- name: Clear Manager Logs with a timeout of 20 seconds
|
||||||
redfish_command:
|
redfish_command:
|
||||||
category: Manager
|
category: Manager
|
||||||
command: ClearLogs
|
command: ClearLogs
|
||||||
baseuri: "{{ baseuri }}"
|
baseuri: "{{ baseuri }}"
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
timeout: 20
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -167,6 +174,7 @@ def main():
|
||||||
new_password=dict(no_log=True),
|
new_password=dict(no_log=True),
|
||||||
roleid=dict(),
|
roleid=dict(),
|
||||||
bootdevice=dict(),
|
bootdevice=dict(),
|
||||||
|
timeout=dict(type='int', default=10)
|
||||||
),
|
),
|
||||||
supports_check_mode=False
|
supports_check_mode=False
|
||||||
)
|
)
|
||||||
|
@ -184,10 +192,13 @@ def main():
|
||||||
'userpswd': module.params['new_password'],
|
'userpswd': module.params['new_password'],
|
||||||
'userrole': module.params['roleid']}
|
'userrole': module.params['roleid']}
|
||||||
|
|
||||||
|
# timeout
|
||||||
|
timeout = module.params['timeout']
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_uri = "/redfish/v1/"
|
||||||
rf_utils = RedfishUtils(creds, root_uri)
|
rf_utils = RedfishUtils(creds, root_uri, timeout)
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
|
|
@ -55,6 +55,12 @@ options:
|
||||||
- value of BIOS attribute to update
|
- value of BIOS attribute to update
|
||||||
default: 'null'
|
default: 'null'
|
||||||
version_added: "2.8"
|
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)"
|
author: "Jose Delarosa (@jose-delarosa)"
|
||||||
'''
|
'''
|
||||||
|
@ -90,13 +96,14 @@ EXAMPLES = '''
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
|
||||||
- name: Set BIOS default settings
|
- name: Set BIOS default settings with a timeout of 20 seconds
|
||||||
redfish_config:
|
redfish_config:
|
||||||
category: Systems
|
category: Systems
|
||||||
command: SetBiosDefaultSettings
|
command: SetBiosDefaultSettings
|
||||||
baseuri: "{{ baseuri }}"
|
baseuri: "{{ baseuri }}"
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
timeout: 20
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -129,6 +136,7 @@ def main():
|
||||||
password=dict(required=True, no_log=True),
|
password=dict(required=True, no_log=True),
|
||||||
bios_attribute_name=dict(default='null'),
|
bios_attribute_name=dict(default='null'),
|
||||||
bios_attribute_value=dict(default='null'),
|
bios_attribute_value=dict(default='null'),
|
||||||
|
timeout=dict(type='int', default=10)
|
||||||
),
|
),
|
||||||
supports_check_mode=False
|
supports_check_mode=False
|
||||||
)
|
)
|
||||||
|
@ -140,6 +148,9 @@ def main():
|
||||||
creds = {'user': module.params['username'],
|
creds = {'user': module.params['username'],
|
||||||
'pswd': module.params['password']}
|
'pswd': module.params['password']}
|
||||||
|
|
||||||
|
# timeout
|
||||||
|
timeout = module.params['timeout']
|
||||||
|
|
||||||
# BIOS attributes to update
|
# BIOS attributes to update
|
||||||
bios_attributes = {'bios_attr_name': module.params['bios_attribute_name'],
|
bios_attributes = {'bios_attr_name': module.params['bios_attribute_name'],
|
||||||
'bios_attr_value': module.params['bios_attribute_value']}
|
'bios_attr_value': module.params['bios_attribute_value']}
|
||||||
|
@ -147,7 +158,7 @@ def main():
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_uri = "/redfish/v1/"
|
||||||
rf_utils = RedfishUtils(creds, root_uri)
|
rf_utils = RedfishUtils(creds, root_uri, timeout)
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
|
|
@ -43,6 +43,12 @@ options:
|
||||||
required: true
|
required: true
|
||||||
description:
|
description:
|
||||||
- Password for authentication with OOB controller
|
- 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)"
|
author: "Jose Delarosa (@jose-delarosa)"
|
||||||
'''
|
'''
|
||||||
|
@ -68,13 +74,14 @@ EXAMPLES = '''
|
||||||
- debug:
|
- debug:
|
||||||
msg: "{{ redfish_facts.cpu.entries.0.Model }}"
|
msg: "{{ redfish_facts.cpu.entries.0.Model }}"
|
||||||
|
|
||||||
- name: Get fan inventory
|
- name: Get fan inventory with a timeout of 20 seconds
|
||||||
redfish_facts:
|
redfish_facts:
|
||||||
category: Chassis
|
category: Chassis
|
||||||
command: GetFanInventory
|
command: GetFanInventory
|
||||||
baseuri: "{{ baseuri }}"
|
baseuri: "{{ baseuri }}"
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
timeout: 20
|
||||||
|
|
||||||
- name: Get default inventory information
|
- name: Get default inventory information
|
||||||
redfish_facts:
|
redfish_facts:
|
||||||
|
@ -172,6 +179,7 @@ def main():
|
||||||
baseuri=dict(required=True),
|
baseuri=dict(required=True),
|
||||||
username=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
|
supports_check_mode=False
|
||||||
)
|
)
|
||||||
|
@ -180,10 +188,13 @@ def main():
|
||||||
creds = {'user': module.params['username'],
|
creds = {'user': module.params['username'],
|
||||||
'pswd': module.params['password']}
|
'pswd': module.params['password']}
|
||||||
|
|
||||||
|
# timeout
|
||||||
|
timeout = module.params['timeout']
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_uri = "/redfish/v1/"
|
||||||
rf_utils = RedfishUtils(creds, root_uri)
|
rf_utils = RedfishUtils(creds, root_uri, timeout)
|
||||||
|
|
||||||
# Build Category list
|
# Build Category list
|
||||||
if "all" in module.params['category']:
|
if "all" in module.params['category']:
|
||||||
|
|
Loading…
Reference in a new issue