mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add SetSessionService to redfish_config (#5009)
* Add SetSessionService to redfish_config adding SetSessionService command to redfish_config to set BMC default session timeout policy. Fixes #5008 * fix white space issues * Making Requested changes: - changed category from SessionService to Sessions - changed set_sessionservice() to set_session_service() - other misc. changes for cleanup * Apply suggestions from code review Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Fix issues with checks * Fix issues with checks part 2 * Fix issues with checks part 3 * Update plugins/modules/remote_management/redfish/redfish_config.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
fb1cf91ebd
commit
d9d830a168
3 changed files with 92 additions and 1 deletions
2
changelogs/fragments/5008-addSetSessionService.yml
Normal file
2
changelogs/fragments/5008-addSetSessionService.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- redfish_config - add ``SetSessionService`` to set default session timeout policy (https://github.com/ansible-collections/community.general/issues/5008).
|
|
@ -240,6 +240,7 @@ class RedfishUtils(object):
|
||||||
return {'ret': False, 'msg': "SessionService resource not found"}
|
return {'ret': False, 'msg': "SessionService resource not found"}
|
||||||
else:
|
else:
|
||||||
session_service = data["SessionService"]["@odata.id"]
|
session_service = data["SessionService"]["@odata.id"]
|
||||||
|
self.session_service_uri = session_service
|
||||||
response = self.get_request(self.root_uri + session_service)
|
response = self.get_request(self.root_uri + session_service)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
|
@ -3081,3 +3082,60 @@ class RedfishUtils(object):
|
||||||
|
|
||||||
def get_multi_manager_inventory(self):
|
def get_multi_manager_inventory(self):
|
||||||
return self.aggregate_managers(self.get_manager_inventory)
|
return self.aggregate_managers(self.get_manager_inventory)
|
||||||
|
|
||||||
|
def set_session_service(self, sessions_config):
|
||||||
|
result = {}
|
||||||
|
response = self.get_request(self.root_uri + self.session_service_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
current_sessions_config = response['data']
|
||||||
|
payload = {}
|
||||||
|
for property, value in sessions_config.items():
|
||||||
|
value = sessions_config[property]
|
||||||
|
if property not in current_sessions_config:
|
||||||
|
return {'ret': False, 'msg': "Property %s in sessions_config is invalid" % property}
|
||||||
|
if isinstance(value, dict):
|
||||||
|
if isinstance(current_sessions_config[property], dict):
|
||||||
|
payload[property] = value
|
||||||
|
elif isinstance(current_sessions_config[property], list):
|
||||||
|
payload[property] = [value]
|
||||||
|
else:
|
||||||
|
return {'ret': False, 'msg': "Value of property %s in sessions_config is invalid" % property}
|
||||||
|
else:
|
||||||
|
payload[property] = value
|
||||||
|
|
||||||
|
need_change = False
|
||||||
|
for property, set_value in payload.items():
|
||||||
|
cur_value = current_sessions_config[property]
|
||||||
|
if not isinstance(set_value, (dict, list)):
|
||||||
|
if set_value != cur_value:
|
||||||
|
need_change = True
|
||||||
|
if isinstance(set_value, dict):
|
||||||
|
for subprop in set_value.keys():
|
||||||
|
if subprop not in current_sessions_config[property]:
|
||||||
|
need_change = True
|
||||||
|
break
|
||||||
|
sub_set_value = set_value[subprop]
|
||||||
|
sub_cur_value = current_sessions_config[property][subprop]
|
||||||
|
if sub_set_value != sub_cur_value:
|
||||||
|
need_change = True
|
||||||
|
if isinstance(set_value, list):
|
||||||
|
if len(set_value) != len(cur_value):
|
||||||
|
need_change = True
|
||||||
|
continue
|
||||||
|
for i in range(len(set_value)):
|
||||||
|
for subprop in set_value[i].keys():
|
||||||
|
if subprop not in current_sessions_config[property][i]:
|
||||||
|
need_change = True
|
||||||
|
break
|
||||||
|
sub_set_value = set_value[i][subprop]
|
||||||
|
sub_cur_value = current_sessions_config[property][i][subprop]
|
||||||
|
if sub_set_value != sub_cur_value:
|
||||||
|
need_change = True
|
||||||
|
if not need_change:
|
||||||
|
return {'ret': True, 'changed': False, 'msg': "SessionService already configured"}
|
||||||
|
|
||||||
|
response = self.patch_request(self.root_uri + self.session_service_uri, payload)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
return {'ret': True, 'changed': True, 'msg': "Modified SessionService"}
|
||||||
|
|
|
@ -113,6 +113,12 @@ options:
|
||||||
- Redfish HostInterface instance ID if multiple HostInterfaces are present.
|
- Redfish HostInterface instance ID if multiple HostInterfaces are present.
|
||||||
type: str
|
type: str
|
||||||
version_added: '4.1.0'
|
version_added: '4.1.0'
|
||||||
|
sessions_config:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- Setting dict of Sessions.
|
||||||
|
type: dict
|
||||||
|
version_added: '5.7.0'
|
||||||
|
|
||||||
author: "Jose Delarosa (@jose-delarosa)"
|
author: "Jose Delarosa (@jose-delarosa)"
|
||||||
'''
|
'''
|
||||||
|
@ -235,6 +241,16 @@ EXAMPLES = '''
|
||||||
baseuri: "{{ baseuri }}"
|
baseuri: "{{ baseuri }}"
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
|
||||||
|
- name: Set SessionService Session Timeout to 30 minutes
|
||||||
|
community.general.redfish_config:
|
||||||
|
category: Sessions
|
||||||
|
command: SetSessionService
|
||||||
|
sessions_config:
|
||||||
|
SessionTimeout: 1800
|
||||||
|
baseuri: "{{ baseuri }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ password }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -254,7 +270,8 @@ from ansible.module_utils.common.text.converters import to_native
|
||||||
CATEGORY_COMMANDS_ALL = {
|
CATEGORY_COMMANDS_ALL = {
|
||||||
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
|
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
|
||||||
"SetDefaultBootOrder"],
|
"SetDefaultBootOrder"],
|
||||||
"Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"]
|
"Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"],
|
||||||
|
"Sessions": ["SetSessionService"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,6 +301,7 @@ def main():
|
||||||
strip_etag_quotes=dict(type='bool', default=False),
|
strip_etag_quotes=dict(type='bool', default=False),
|
||||||
hostinterface_config=dict(type='dict', default={}),
|
hostinterface_config=dict(type='dict', default={}),
|
||||||
hostinterface_id=dict(),
|
hostinterface_id=dict(),
|
||||||
|
sessions_config=dict(type='dict', default={}),
|
||||||
),
|
),
|
||||||
required_together=[
|
required_together=[
|
||||||
('username', 'password'),
|
('username', 'password'),
|
||||||
|
@ -330,6 +348,9 @@ def main():
|
||||||
# HostInterface instance ID
|
# HostInterface instance ID
|
||||||
hostinterface_id = module.params['hostinterface_id']
|
hostinterface_id = module.params['hostinterface_id']
|
||||||
|
|
||||||
|
# Sessions config options
|
||||||
|
sessions_config = module.params['sessions_config']
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
||||||
|
@ -376,6 +397,16 @@ def main():
|
||||||
elif command == "SetHostInterface":
|
elif command == "SetHostInterface":
|
||||||
result = rf_utils.set_hostinterface_attributes(hostinterface_config, hostinterface_id)
|
result = rf_utils.set_hostinterface_attributes(hostinterface_config, hostinterface_id)
|
||||||
|
|
||||||
|
elif category == "Sessions":
|
||||||
|
# execute only if we find a Sessions resource
|
||||||
|
result = rf_utils._find_sessionservice_resource()
|
||||||
|
if result['ret'] is False:
|
||||||
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
for command in command_list:
|
||||||
|
if command == "SetSessionService":
|
||||||
|
result = rf_utils.set_session_service(sessions_config)
|
||||||
|
|
||||||
# Return data back or fail with proper message
|
# Return data back or fail with proper message
|
||||||
if result['ret'] is True:
|
if result['ret'] is True:
|
||||||
if result.get('warning'):
|
if result.get('warning'):
|
||||||
|
|
Loading…
Reference in a new issue