Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SetSessionService to redfish_config #5009

Merged
merged 8 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/5008-addSetSessionService.yml
Original file line number Diff line number Diff line change
@@ -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).
60 changes: 60 additions & 0 deletions plugins/module_utils/redfish_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def _find_sessionservice_resource(self):
return {'ret': False, 'msg': "SessionService resource not found"}
else:
session_service = data["SessionService"]["@odata.id"]
self.session_service_uri = session_service
response = self.get_request(self.root_uri + session_service)
if response['ret'] is False:
return response
Expand Down Expand Up @@ -3051,3 +3052,62 @@ def get_manager_inventory(self, manager_uri):

def get_multi_manager_inventory(self):
return self.aggregate_managers(self.get_manager_inventory)

def set_sessionservice(self, sessionservice_config):
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
result = {}
response = self.get_request(self.root_uri + self.session_service_uri)
if response['ret'] is False:
return response
current_sessionservice_config = response['data']
payload = {}
for property in sessionservice_config.keys():
value = sessionservice_config[property]
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
if property not in current_sessionservice_config:
return {'ret': False, 'msg': "Property %s in sessionservice_config is invalid" % property}
if isinstance(value, dict):
if isinstance(current_sessionservice_config[property], dict):
payload[property] = value
elif isinstance(current_sessionservice_config[property], list):
payload[property] = list()
payload[property].append(value)
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
else:
return {'ret': False, 'msg': "Value of property %s in sessionservice_config is invalid" % property}
else:
payload[property] = value
felixfontein marked this conversation as resolved.
Show resolved Hide resolved

need_change = False
for property in payload.keys():
set_value = payload[property]
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
cur_value = current_sessionservice_config[property]
if not isinstance(set_value, dict) and not isinstance(set_value, list):
tejabailey marked this conversation as resolved.
Show resolved Hide resolved
if set_value != cur_value:
need_change = True
if isinstance(set_value, dict):
for subprop in payload[property].keys():
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
if subprop not in current_sessionservice_config[property]:
need_change = True
break
sub_set_value = payload[property][subprop]
sub_cur_value = current_sessionservice_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 payload[property][i].keys():
tejabailey marked this conversation as resolved.
Show resolved Hide resolved
if subprop not in current_sessionservice_config[property][i]:
need_change = True
break
sub_set_value = payload[property][i][subprop]
sub_cur_value = current_sessionservice_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"}
33 changes: 32 additions & 1 deletion plugins/modules/remote_management/redfish/redfish_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
- Redfish HostInterface instance ID if multiple HostInterfaces are present.
type: str
version_added: '4.1.0'
sessionservice_config:
required: false
description:
- Setting dict of SessionService.
type: dict
version_added: '5.4.0'
tejabailey marked this conversation as resolved.
Show resolved Hide resolved

author: "Jose Delarosa (@jose-delarosa)"
'''
Expand Down Expand Up @@ -234,6 +240,16 @@
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"

- name: Set SessionService Session Timeout to 30 minutes
community.general.redfish_config:
category: SessionService
command: SetSessionService
sessionservice_config:
SessionTimeout: 1800
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
'''

RETURN = '''
Expand All @@ -253,7 +269,8 @@
CATEGORY_COMMANDS_ALL = {
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
"SetDefaultBootOrder"],
"Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"]
"Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"],
"SessionService": ["SetSessionService"]
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down Expand Up @@ -283,6 +300,7 @@ def main():
strip_etag_quotes=dict(type='bool', default=False),
hostinterface_config=dict(type='dict', default={}),
hostinterface_id=dict(),
sessionservice_config=dict(type='dict', default={}),
),
required_together=[
('username', 'password'),
Expand Down Expand Up @@ -329,6 +347,9 @@ def main():
# HostInterface instance ID
hostinterface_id = module.params['hostinterface_id']

# SessionService config options
sessionservice_config = module.params['sessionservice_config']

# Build root URI
root_uri = "https://" + module.params['baseuri']
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
Expand Down Expand Up @@ -375,6 +396,16 @@ def main():
elif command == "SetHostInterface":
result = rf_utils.set_hostinterface_attributes(hostinterface_config, hostinterface_id)

elif category == "SessionService":
# execute only if we find a SessionService 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_sessionservice(sessionservice_config)

# Return data back or fail with proper message
if result['ret'] is True:
if result.get('warning'):
Expand Down