From f56e000a666c0af5db3485f84011f75542043ef1 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 15 Aug 2025 16:40:25 -0400 Subject: [PATCH] Attempt better redfish account deletion Better redfish implementations offer the sane option of just deleting the account, try that before trying to hack our way out of a bad implementation. Change-Id: Icb97a0ae18bdafd3fed3528f5eee6ed6ba40cdac --- pyghmi/redfish/command.py | 2 +- pyghmi/redfish/oem/generic.py | 12 +++++++++--- pyghmi/redfish/oem/lenovo/xcc.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 9157f4ba..d195d39a 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -445,7 +445,7 @@ class Command(object): return self.oem.get_ikvm_launchdata() def user_delete(self, uid): - self.oem.user_delete(uid) + self.oem.user_delete(uid, self) def set_user_name(self, uid, name): """Set user name diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index ab0b445e..15ca457b 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -383,13 +383,19 @@ class OEMHandler(object): summary['badreadings'].append(unkinf) return summary - def user_delete(self, uid): + def user_delete(self, uid, fishclient): # Redfish doesn't do so well with Deleting users either... # Blanking the username seems to be the convention # First, set a bogus password in case the implementation does honor # blank user, at least render such an account harmless - self.set_user_password(uid, base64.b64encode(os.urandom(15))) - self.set_user_name(uid, '') + try: + accinfo = fishclient._account_url_info_by_id(uid) + if not accinfo: + raise Exception("No such account found") + self._do_web_request(accinfo[0], method='DELETE') + except Exception: # fall back to old ipmi-like behavior for such implementations + fishclient.set_user_password(uid, base64.b64encode(os.urandom(15))) + fishclient.set_user_name(uid, '') return True def set_bootdev(self, bootdev, persist=False, uefiboot=None, diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index 4dcfd7a3..aaf3f986 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -1662,7 +1662,7 @@ class OEMHandler(generic.OEMHandler): license_errors[rsp['return']]) return self.get_licenses(fishclient) - def user_delete(self, uid): + def user_delete(self, uid, fishclient=None): userinfo = self.wc.grab_json_response('/api/dataset/imm_users') uidtonamemap = {} for user in userinfo.get('items', [{'users': []}])[0].get('users', []):