Skip to content
Permalink
Browse files

Expose timeout option to Redfish modules

(cherry picked from commit d8536e4)
  • Loading branch information...
billdodd authored and abadger committed Mar 26, 2019
1 parent aa616b4 commit 61643874f2fc21ad23b37890f1f80da4092eeb26
@@ -0,0 +1,2 @@
bugfixes:
- redfish_utils - expose timeout option for redfish implementations that exceed the 10 second default
@@ -19,9 +19,10 @@

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 @@ def get_request(self, uri):
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 @@ def post_request(self, uri, pyld):
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 @@ def patch_request(self, uri, pyld):
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 @@ def delete_request(self, uri, pyld):
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:
@@ -63,6 +63,12 @@
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 @@
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:
@@ -62,6 +62,12 @@
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 @@
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 @@
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,14 +191,18 @@ 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']}

# 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:
@@ -42,6 +42,12 @@
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 @@
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']:

0 comments on commit 6164387

Please sign in to comment.
You can’t perform that action at this time.