From 2db01746d52bfcf9d985b85213dc76f64f9944f3 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 19 Jun 2019 16:35:24 -0400 Subject: [PATCH] Support deletion of licenses from XCC --- confluent_client/bin/nodelicense | 28 +++++++++++++++++-- confluent_client/confluent_env.sh | 2 +- .../plugins/hardwaremanagement/ipmi.py | 11 ++++++-- .../plugins/hardwaremanagement/redfish.py | 10 +++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/confluent_client/bin/nodelicense b/confluent_client/bin/nodelicense index e4137e01..1e3024e5 100755 --- a/confluent_client/bin/nodelicense +++ b/confluent_client/bin/nodelicense @@ -36,10 +36,11 @@ exitcode = 0 argparser = optparse.OptionParser( usage="Usage: " - "%prog [list][install |save ]") + "%prog [list][install |save |delete ]") (options, args) = argparser.parse_args() upfile = None downdir = None +delete = False try: noderange = args[0] if len(args) > 1: @@ -47,6 +48,8 @@ try: upfile = args[2] elif args[1] == 'save': downdir = args[2] + elif args[1] == 'delete': + delete = args[2] else: components = ['all'] except IndexError: @@ -83,7 +86,6 @@ def save_licenses(session, dirname): def show_licenses(session): global exitcode - firmware_shown = False for res in session.read( '/noderange/{0}/configuration/management_controller/licenses/' 'all'.format(noderange)): @@ -93,12 +95,34 @@ def show_licenses(session): 'Unknown'))) +def delete_license(session, licname): + global exitcode + licstodel = [] + for res in list(session.read( + '/noderange/{0}/configuration/management_controller/licenses/' + 'all'.format(noderange))): + for node in res.get('databynode', {}): + for license in res['databynode'][node].get('License', []): + if license.get('feature', None) == licname: + prefix = '/nodes/{0}/configuration/management_controller/licenses/'.format(node) + for currlic in list(session.read(prefix)): + currlic = currlic.get('item', {}).get('href', 'all') + if currlic == 'all': + continue + currname = list(session.read(prefix + currlic))[0] + currname = currname.get('License', [{}])[0].get('feature', None) + if currname == licname: + list(session.delete(prefix + currlic)) + show_licenses(session) + try: session = client.Command() if upfile: install_license(session, upfile) elif downdir: save_licenses(session, downdir) + elif delete: + delete_license(session, delete) else: show_licenses(session) except KeyboardInterrupt: diff --git a/confluent_client/confluent_env.sh b/confluent_client/confluent_env.sh index b6081a62..2815f11a 100644 --- a/confluent_client/confluent_env.sh +++ b/confluent_client/confluent_env.sh @@ -160,7 +160,7 @@ _confluent_nodelicense_completion() { _confluent_get_args if [ $NUMARGS == 3 ]; then - COMPREPLY=($(compgen -W "install list save" -- ${COMP_WORDS[-1]})) + COMPREPLY=($(compgen -W "install list save delete" -- ${COMP_WORDS[-1]})) return; fi if [ $NUMARGS == 4 ] && [ ${CMPARGS[2]} == 'install' ]; then diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index 563f6236..67421ce0 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -1453,12 +1453,17 @@ class IpmiHandler(object): licname = self.element[3] if licname == 'all': for lic in self.ipmicmd.get_licenses(): - self.output.put(msg.License(self.node, feature=lic['name'])) + if self.op == 'delete': + self.ipmicmd.delete_license(lic['name']) + else: + self.output.put(msg.License(self.node, feature=lic['name'])) else: index = int(licname) lic = list(self.ipmicmd.get_licenses())[index - 1] - self.output.put(msg.License(self.node, feature=lic['name'])) - + if self.op == 'delete': + self.ipmicmd.delete_license(lic['name']) + else: + self.output.put(msg.License(self.node, feature=lic['name'])) def handle_description(self): dsc = self.ipmicmd.get_description() self.output.put(msg.KeyValueData(dsc, self.node)) diff --git a/confluent_server/confluent/plugins/hardwaremanagement/redfish.py b/confluent_server/confluent/plugins/hardwaremanagement/redfish.py index e99c79ed..9a8afa85 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/redfish.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/redfish.py @@ -1319,11 +1319,17 @@ class IpmiHandler(object): licname = self.element[3] if licname == 'all': for lic in self.ipmicmd.get_licenses(): - self.output.put(msg.License(self.node, feature=lic['name'])) + if self.op == 'delete': + self.ipmicmd.delete_license(lic['name']) + else: + self.output.put(msg.License(self.node, feature=lic['name'])) else: index = int(licname) lic = list(self.ipmicmd.get_licenses())[index - 1] - self.output.put(msg.License(self.node, feature=lic['name'])) + if self.op == 'delete': + self.ipmicmd.delete_license(lic['name']) + else: + self.output.put(msg.License(self.node, feature=lic['name'])) def handle_description(self): dsc = self.ipmicmd.get_description()