From d8536e47d3fe1d31412f192ce567a9780ae0d521 Mon Sep 17 00:00:00 2001 From: Bill Dodd Date: Tue, 26 Mar 2019 12:19:24 -0500 Subject: [PATCH] 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 --- lib/ansible/module_utils/redfish_utils.py | 11 ++++++----- .../redfish/idrac_redfish_command.py | 14 ++++++++++++-- .../remote_management/redfish/redfish_command.py | 15 +++++++++++++-- .../remote_management/redfish/redfish_config.py | 15 +++++++++++++-- .../remote_management/redfish/redfish_facts.py | 15 +++++++++++++-- 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/lib/ansible/module_utils/redfish_utils.py b/lib/ansible/module_utils/redfish_utils.py index 7d7b234a1c5..fe8c13ec348 100644 --- a/lib/ansible/module_utils/redfish_utils.py +++ b/lib/ansible/module_utils/redfish_utils.py @@ -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: diff --git a/lib/ansible/modules/remote_management/redfish/idrac_redfish_command.py b/lib/ansible/modules/remote_management/redfish/idrac_redfish_command.py index 52a06c4c50a..52cbe3f829d 100644 --- a/lib/ansible/modules/remote_management/redfish/idrac_redfish_command.py +++ b/lib/ansible/modules/remote_management/redfish/idrac_redfish_command.py @@ -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: diff --git a/lib/ansible/modules/remote_management/redfish/redfish_command.py b/lib/ansible/modules/remote_management/redfish/redfish_command.py index 2b9a07aa90b..e018d6e84d0 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_command.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_command.py @@ -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: diff --git a/lib/ansible/modules/remote_management/redfish/redfish_config.py b/lib/ansible/modules/remote_management/redfish/redfish_config.py index 2c3f839d5a1..3830dc2e344 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_config.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_config.py @@ -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: diff --git a/lib/ansible/modules/remote_management/redfish/redfish_facts.py b/lib/ansible/modules/remote_management/redfish/redfish_facts.py index b40b1194e42..9330d1711e9 100644 --- a/lib/ansible/modules/remote_management/redfish/redfish_facts.py +++ b/lib/ansible/modules/remote_management/redfish/redfish_facts.py @@ -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']: