Add new command ClearSessions (#65600)

* Add ClearSessions command to clear all active sessions.

* Delete trailing whitespaces
pull/65665/merge
XuLei Ren 5 years ago committed by GitHub
parent f21ee7f685
commit 435bd91d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1169,6 +1169,24 @@ class RedfishUtils(object):
result["entries"] = sessions_results result["entries"] = sessions_results
return result 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): def get_firmware_update_capabilities(self):
result = {} result = {}
response = self.get_request(self.root_uri + self.update_uri) response = self.get_request(self.root_uri + self.update_uri)

@ -294,6 +294,14 @@ EXAMPLES = '''
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
timeout: 20 timeout: 20
- name: Clear Sessions
redfish_command:
category: Sessions
command: ClearSessions
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
''' '''
RETURN = ''' RETURN = '''
@ -317,6 +325,7 @@ CATEGORY_COMMANDS_ALL = {
"Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser", "Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",
"UpdateUserRole", "UpdateUserPassword", "UpdateUserName", "UpdateUserRole", "UpdateUserPassword", "UpdateUserName",
"UpdateAccountServiceProperties"], "UpdateAccountServiceProperties"],
"Sessions": ["ClearSessions"],
"Manager": ["GracefulRestart", "ClearLogs"], "Manager": ["GracefulRestart", "ClearLogs"],
} }
@ -433,6 +442,16 @@ def main():
if command in led_commands: if command in led_commands:
result = rf_utils.manage_indicator_led(command) 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": elif category == "Manager":
MANAGER_COMMANDS = { MANAGER_COMMANDS = {
"GracefulRestart": rf_utils.restart_manager_gracefully, "GracefulRestart": rf_utils.restart_manager_gracefully,

Loading…
Cancel
Save