From 3782127590d84ea54e7ecf02a5ed23ba70b5f53d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 14 Jan 2019 14:55:03 -0500 Subject: [PATCH] Implement retrieving license info from XCC With changes to pyghmi, we can now get license data. Prepare API to provide information about the licenses. --- confluent_server/confluent/core.py | 4 ++++ confluent_server/confluent/messages.py | 4 ++-- .../plugins/hardwaremanagement/ipmi.py | 24 ++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/confluent_server/confluent/core.py b/confluent_server/confluent/core.py index 016f8aa1..3976e7f4 100644 --- a/confluent_server/confluent/core.py +++ b/confluent_server/confluent/core.py @@ -165,6 +165,10 @@ def _init_core(): 'pluginattrs': ['hardwaremanagement.method'], 'default': 'ipmi', }), + 'licenses': PluginCollection({ + 'pluginattrs': ['hardwaremanagement.method'], + 'default': 'ipmi', + }), 'net_interfaces': PluginCollection({ 'pluginattrs': ['hardwaremanagement.method'], 'default': 'ipmi', diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 881127b5..90126f83 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -1530,12 +1530,12 @@ class NTPServer(ConfluentMessage): class License(ConfluentMessage): readonly = True - def __init__(self, name=None, kvm=None): + def __init__(self, name=None, kvm=None, feature=None): self.notnode = name is None self.desc = 'License' kv = [] - kv.append({'kvm_availability': str(kvm)}) + kv.append({'kvm_availability': str(kvm), 'feature': feature}) if self.notnode: self.kvpairs = {'License': kv} else: diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index ab4b4fe0..3a1ad68a 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -375,7 +375,8 @@ def perform_requests(operator, nodes, element, cfg, inputdata, realop): if datum != 'Done': if isinstance(datum, Exception): raise datum - if hasattr(datum, 'kvpairs') and len(datum.kvpairs) == 1: + if (hasattr(datum, 'kvpairs') and datum.kvpairs and + len(datum.kvpairs) == 1): bundle.append((datum.kvpairs.keys()[0], datum)) numnodes -= 1 else: @@ -617,6 +618,8 @@ class IpmiHandler(object): return self.handle_sysconfig(True) elif self.element[1:3] == ['system', 'clear']: return self.handle_sysconfigclear() + elif self.element[1:3] == ['management_controller', 'licenses']: + return self.handle_licenses() raise Exception('Not implemented') def decode_alert(self): @@ -1396,6 +1399,25 @@ class IpmiHandler(object): self.output.put(msg.License(self.node, available)) return + def handle_licenses(self): + if self.element[-1] == '': + self.element = self.element[:-1] + if len(self.element) == 3: + self.output.put(msg.ChildCollection('all')) + i = 1 + for lic in self.ipmicmd.get_licenses(): + self.output.put(msg.ChildCollection(str(i))) + i += 1 + return + licname = self.element[3] + if licname == 'all': + for lic in self.ipmicmd.get_licenses(): + 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'])) + def handle_description(self): dsc = self.ipmicmd.get_description() self.output.put(msg.KeyValueData(dsc, self.node))