From 1b4005ee19fa4cf4ec5a89311bda6ca0e1d05e2f Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 25 Feb 2021 14:25:50 -0500 Subject: [PATCH] Apply license from file-like object Allow passing pre-opened files to apply_license. Change-Id: I83e0e5352b15ef1dc73f65a1a54d0fbe03f10b3a --- pyghmi/ipmi/command.py | 4 ++-- pyghmi/ipmi/oem/generic.py | 2 +- pyghmi/ipmi/oem/lenovo/handler.py | 6 +++--- pyghmi/ipmi/oem/lenovo/imm.py | 5 +++-- pyghmi/redfish/command.py | 4 ++-- pyghmi/redfish/oem/generic.py | 2 +- pyghmi/redfish/oem/lenovo/xcc.py | 5 +++-- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 6025509d..7e58e4d4 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -2066,6 +2066,6 @@ class Command(object): self.oem_init() return self._oem.save_licenses(directory) - def apply_license(self, filename, progress=None): + def apply_license(self, filename, progress=None, data=None): self.oem_init() - return self._oem.apply_license(filename, progress) + return self._oem.apply_license(filename, progress, data=None) diff --git a/pyghmi/ipmi/oem/generic.py b/pyghmi/ipmi/oem/generic.py index 3f2d323f..c13ab595 100644 --- a/pyghmi/ipmi/oem/generic.py +++ b/pyghmi/ipmi/oem/generic.py @@ -378,7 +378,7 @@ class OEMHandler(object): def save_licenses(self, directory): raise exc.UnsupportedFunctionality() - def apply_license(self, filename, progress=None): + def apply_license(self, filename, progress=None, data=None): raise exc.UnsupportedFunctionality() def get_user_expiration(self, uid): diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index 6a7d5d16..29bbc11d 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -1085,7 +1085,7 @@ class OEMHandler(generic.OEMHandler): return self.immhandler.save_licenses(directory) return super(OEMHandler, self).save_licenses(directory) - def apply_license(self, filename, progress=None): + def apply_license(self, filename, progress=None, data=None): if self.has_xcc: - return self.immhandler.apply_license(filename, progress) - return super(OEMHandler, self).apply_license(filename, progress) + return self.immhandler.apply_license(filename, progress, data) + return super(OEMHandler, self).apply_license(filename, progress, data) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 57414097..a39c1e46 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -2097,7 +2097,7 @@ class XCCClient(IMMClient): '/api/providers/imm_fod', {'FOD_LicenseKeyDelete': licid}) break - def apply_license(self, filename, progress=None): + def apply_license(self, filename, progress=None, data=None): license_errors = { 310: "License is for a different model of system", 311: "License is for a different system serial number", @@ -2105,7 +2105,8 @@ class XCCClient(IMMClient): 313: "License is expired", 314: "License usage limit reached", } - uploadthread = webclient.FileUploader(self.wc, '/upload', filename) + uploadthread = webclient.FileUploader(self.wc, '/upload', filename, + data=data) uploadthread.start() uploadthread.join() rsp = json.loads(uploadthread.rsp) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 8cb489a2..f4f2b968 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -1508,8 +1508,8 @@ class Command(object): directory)) return self.oem.save_licenses(directory) - def apply_license(self, filename, progress=None): - return self.oem.apply_license(filename, progress) + def apply_license(self, filename, progress=None, data=None): + return self.oem.apply_license(filename, progress, data) if __name__ == '__main__': diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index 62c75576..e741a954 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -393,7 +393,7 @@ class OEMHandler(object): def save_licenses(self, directory): raise exc.UnsupportedFunctionality() - def apply_license(self, filename, progress=None): + def apply_license(self, filename, progress=None, data=None): raise exc.UnsupportedFunctionality() def get_user_expiration(self, uid): diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index 6408d630..96ba42b7 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -974,7 +974,7 @@ class OEMHandler(generic.OEMHandler): self._refresh_token() yield savefile - def apply_license(self, filename, progress=None): + def apply_license(self, filename, progress=None, data=None): license_errors = { 310: "License is for a different model of system", 311: "License is for a different system serial number", @@ -982,7 +982,8 @@ class OEMHandler(generic.OEMHandler): 313: "License is expired", 314: "License usage limit reached", } - uploadthread = webclient.FileUploader(self.wc, '/upload', filename) + uploadthread = webclient.FileUploader(self.wc, '/upload', filename, + data=data) uploadthread.start() uploadthread.join() rsp = json.loads(uploadthread.rsp)