From 2e9a81f8f177ecc6d8268d604c39f8d0393c5ae7 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 5 Nov 2019 14:06:56 -0500 Subject: [PATCH] Offer more robust bmc reset Error on unrecognized and also check for a longer list of possible actions that we wouldn't mind using. Change-Id: I947ce7e76d28fe1e9a296c5c2a1e5a99a1a285ec --- pyghmi/redfish/command.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 8608aba6..f38d0880 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -762,16 +762,30 @@ class Command(object): return lastnicurl @property - def _bmcreseturl(self): + def _bmcresetinfo(self): if not self._varresetbmcurl: bmcinfo = self._do_web_request(self._bmcurl) - self._varresetbmcurl = bmcinfo.get('Actions', {}).get( - '#Manager.Reset', {}).get('target', None) + resetinf = bmcinfo.get('Actions', {}).get('#Manager.Reset', + {}) + url = resetinf.get('target', '') + valid = resetinf.get('ResetType@Redfish.AllowableValues', []) + resettype = None + if 'GracefulRestart' in valid: + resettype = 'GracefulRestart' + elif 'ForceRestart' in valid: + resettype = 'ForceRestart' + elif 'ColdReset' in valid: + resettype = 'ColdReset' + self._varresetbmcurl = url, resettype return self._varresetbmcurl def reset_bmc(self): - self._do_web_request(self._bmcreseturl, - {'ResetType': 'GracefulRestart'}) + url, action = self._bmcresetinfo + if not url: + raise Exception('BMC does not provide reset action') + if not action: + raise Exception('BMC does not accept a recognized reset type') + self._do_web_request(url, {'ResetType': action}) def set_identify(self, on=True, blink=None): self._do_web_request(