From 3506f73da1452dc6c84afe15e7a366398eb970a2 Mon Sep 17 00:00:00 2001 From: Scott Seekamp Date: Mon, 28 Oct 2024 14:10:48 -0600 Subject: [PATCH] Add UpdateUserAccountTypes command to redfish_command (#9059) * Add UpdateUserAccountTypes command to redfish_command https://github.com/ansible-collections/community.general/issues/9058 * Add changelog fragment * Update changelogs/fragments/9059-redfish_command-updateuseraccounttypes.yml Update changelog fragment Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- ...redfish_command-updateuseraccounttypes.yml | 2 ++ plugins/module_utils/redfish_utils.py | 21 +++++++++++++++++++ plugins/modules/redfish_command.py | 15 ++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/9059-redfish_command-updateuseraccounttypes.yml diff --git a/changelogs/fragments/9059-redfish_command-updateuseraccounttypes.yml b/changelogs/fragments/9059-redfish_command-updateuseraccounttypes.yml new file mode 100644 index 0000000000..066a84e1e9 --- /dev/null +++ b/changelogs/fragments/9059-redfish_command-updateuseraccounttypes.yml @@ -0,0 +1,2 @@ +minor_changes: + - redfish_command - add ``UpdateUserAccountTypes`` command (https://github.com/ansible-collections/community.general/issues/9058, https://github.com/ansible-collections/community.general/pull/9059). diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 2ef928e510..2dab9d80f2 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -1557,6 +1557,27 @@ class RedfishUtils(object): resp['msg'] = 'Modified account service' return resp + def update_user_accounttypes(self, user): + account_types = user.get('account_accounttypes') + oemaccount_types = user.get('account_oemaccounttypes') + if account_types is None and oemaccount_types is None: + return {'ret': False, 'msg': + 'Must provide account_accounttypes or account_oemaccounttypes for UpdateUserAccountTypes command'} + + response = self._find_account_uri(username=user.get('account_username'), + acct_id=user.get('account_id')) + if not response['ret']: + return response + + uri = response['uri'] + payload = {} + if user.get('account_accounttypes'): + payload['AccountTypes'] = user.get('account_accounttypes') + if user.get('account_oemaccounttypes'): + payload['OEMAccountTypes'] = user.get('account_oemaccounttypes') + + return self.patch_request(self.root_uri + uri, payload, check_pyld=True) + def check_password_change_required(self, return_data): """ Checks a response if a user needs to change their password diff --git a/plugins/modules/redfish_command.py b/plugins/modules/redfish_command.py index df541a1bd3..103f9e1d50 100644 --- a/plugins/modules/redfish_command.py +++ b/plugins/modules/redfish_command.py @@ -549,6 +549,18 @@ EXAMPLES = ''' AccountLockoutThreshold: 5 AccountLockoutDuration: 600 + - name: Update user AccountTypes + community.general.redfish_command: + category: Accounts + command: UpdateUserAccountTypes + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + account_username: "{{ account_username }}" + account_types: + - Redfish + - WebUI + - name: Clear Manager Logs with a timeout of 20 seconds community.general.redfish_command: category: Manager @@ -810,7 +822,7 @@ CATEGORY_COMMANDS_ALL = { "Chassis": ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"], "Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser", "UpdateUserRole", "UpdateUserPassword", "UpdateUserName", - "UpdateAccountServiceProperties"], + "UpdateUserAccountTypes", "UpdateAccountServiceProperties"], "Sessions": ["ClearSessions", "CreateSession", "DeleteSession"], "Manager": ["GracefulRestart", "ClearLogs", "VirtualMediaInsert", "ResetToDefaults", @@ -978,6 +990,7 @@ def main(): "UpdateUserRole": rf_utils.update_user_role, "UpdateUserPassword": rf_utils.update_user_password, "UpdateUserName": rf_utils.update_user_name, + "UpdateUserAccountTypes": rf_utils.update_user_accounttypes, "UpdateAccountServiceProperties": rf_utils.update_accountservice_properties }