Add new command ClearSessions (#65600)

* Add ClearSessions command to clear all active sessions.

* Delete trailing whitespaces
This commit is contained in:
XuLei Ren 2020-02-15 21:00:55 +08:00 committed by GitHub
parent f21ee7f685
commit 435bd91d2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View file

@ -1169,6 +1169,24 @@ class RedfishUtils(object):
result["entries"] = sessions_results
return result
def clear_sessions(self):
response = self.get_request(self.root_uri + self.sessions_uri)
if response['ret'] is False:
return response
data = response['data']
# if no active sessions, return as success
if data['Members@odata.count'] == 0:
return {'ret': True, 'changed': False, 'msg': "There is no active sessions"}
# loop to delete every active session
for session in data[u'Members']:
response = self.delete_request(self.root_uri + session[u'@odata.id'])
if response['ret'] is False:
return response
return {'ret': True, 'changed': True, 'msg': "Clear all sessions successfully"}
def get_firmware_update_capabilities(self):
result = {}
response = self.get_request(self.root_uri + self.update_uri)

View file

@ -294,6 +294,14 @@ EXAMPLES = '''
username: "{{ username }}"
password: "{{ password }}"
timeout: 20
- name: Clear Sessions
redfish_command:
category: Sessions
command: ClearSessions
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
'''
RETURN = '''
@ -317,6 +325,7 @@ CATEGORY_COMMANDS_ALL = {
"Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",
"UpdateUserRole", "UpdateUserPassword", "UpdateUserName",
"UpdateAccountServiceProperties"],
"Sessions": ["ClearSessions"],
"Manager": ["GracefulRestart", "ClearLogs"],
}
@ -433,6 +442,16 @@ def main():
if command in led_commands:
result = rf_utils.manage_indicator_led(command)
elif category == "Sessions":
# execute only if we find SessionService resources
resource = rf_utils._find_sessionservice_resource()
if resource['ret'] is False:
module.fail_json(msg=resource['msg'])
for command in command_list:
if command == "ClearSessions":
result = rf_utils.clear_sessions()
elif category == "Manager":
MANAGER_COMMANDS = {
"GracefulRestart": rf_utils.restart_manager_gracefully,