From 575663e638eb6552d1c9eb90fdf95b1ba241f7de Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 19 Jun 2019 14:25:00 -0400 Subject: [PATCH] Offer save_licenses to backup license Lenovo XCC offers ability to save off license keys. Expose API for it. Change-Id: If6c1311f4801c9dde4aebb0d9480eb3eaa4b04fe --- pyghmi/ipmi/command.py | 4 ++++ pyghmi/ipmi/oem/generic.py | 3 +++ pyghmi/ipmi/oem/lenovo/handler.py | 5 +++++ pyghmi/ipmi/oem/lenovo/imm.py | 17 +++++++++++++++++ pyghmi/redfish/command.py | 3 +++ pyghmi/redfish/oem/generic.py | 3 +++ pyghmi/redfish/oem/lenovo/xcc.py | 17 +++++++++++++++++ 7 files changed, 52 insertions(+) diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 880047af..85ee1a8d 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -1999,6 +1999,10 @@ class Command(object): self.oem_init() return self._oem.get_licenses() + def save_licenses(self, directory): + self.oem_init() + return self._oem.save_licenses(directory) + def apply_license(self, filename, progress=None): self.oem_init() return self._oem.apply_license(filename, progress) diff --git a/pyghmi/ipmi/oem/generic.py b/pyghmi/ipmi/oem/generic.py index 827d2969..34ef97b0 100644 --- a/pyghmi/ipmi/oem/generic.py +++ b/pyghmi/ipmi/oem/generic.py @@ -356,5 +356,8 @@ class OEMHandler(object): def get_licenses(self): raise exc.UnsupportedFunctionality() + def save_licenses(self, directory): + raise exc.UnsupportedFunctionality() + def apply_license(self, filename, progress=None): raise exc.UnsupportedFunctionality() diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index 001ab95a..7a1b5015 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -981,6 +981,11 @@ class OEMHandler(generic.OEMHandler): return self.immhandler.get_licenses() return super(OEMHandler, self).get_licenses() + def save_licenses(self, directory): + if self.has_xcc: + return self.immhandler.save_licenses(directory) + return super(OEMHandler, self).save_licenses(directory) + def apply_license(self, filename, progress=None): if self.has_xcc: return self.immhandler.apply_license(filename, progress) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index d4ffbace..64ec4538 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -1798,6 +1798,23 @@ class XCCClient(IMMClient): if lic['status'] == 0: yield {'name': lic['feature']} + def save_licenses(self, directory): + licdata = self.wc.grab_json_response('/api/providers/imm_fod') + for lic in licdata.get('items', [{}])[0].get('keys', []): + licid = ','.join((str(lic['type']), str(lic['id']))) + rsp = self.wc.grab_json_response( + '/api/providers/imm_fod', {'FOD_LicenseKeyExport': licid}) + filename = rsp.get('FileName', None) + if filename: + url = '/download/' + filename + savefile = os.path.join(directory, filename) + fd = webclient.FileDownloader(self.wc, url, savefile) + fd.start() + while fd.isAlive(): + fd.join(1) + self._refresh_token() + yield savefile + def apply_license(self, filename, progress=None): uploadthread = webclient.FileUploader(self.wc, '/upload', filename) uploadthread.start() diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 81a682a3..93e4658f 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -1426,6 +1426,9 @@ class Command(object): def get_licenses(self): return self.oem.get_licenses() + def save_licenses(self, directory): + return self.oem.save_licenses(directory) + def apply_license(self, filename, progress=None): return self.oem.apply_license(filename, progress) diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index 9fd15c75..62006060 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -92,5 +92,8 @@ class OEMHandler(object): def get_licenses(self): raise exc.UnsupportedFunctionality() + def save_licenses(self, directory): + raise exc.UnsupportedFunctionality() + def apply_license(self, filename, progress=None): raise exc.UnsupportedFunctionality() diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index 2f7d3fbd..497d90a5 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -710,6 +710,23 @@ class OEMHandler(generic.OEMHandler): if lic['status'] == 0: yield {'name': lic['feature']} + def save_licenses(self, directory): + licdata = self.wc.grab_json_response('/api/providers/imm_fod') + for lic in licdata.get('items', [{}])[0].get('keys', []): + licid = ','.join((str(lic['type']), str(lic['id']))) + rsp = self.wc.grab_json_response( + '/api/providers/imm_fod', {'FOD_LicenseKeyExport': licid}) + filename = rsp.get('FileName', None) + if filename: + url = '/download/' + filename + savefile = os.path.join(directory, filename) + fd = webclient.FileDownloader(self.wc, url, savefile) + fd.start() + while fd.isAlive(): + fd.join(1) + self._refresh_token() + yield savefile + def apply_license(self, filename, progress=None): uploadthread = webclient.FileUploader(self.wc, '/upload', filename) uploadthread.start()