From 5826966ea4e0fc5deefaade83e27af428d3f2451 Mon Sep 17 00:00:00 2001 From: Solvik Date: Wed, 21 Aug 2019 16:17:01 +0200 Subject: [PATCH] support HPE BL460c Gen10 and its stupid dmidecode info (#39) --- netbox_agent/dmidecode.py | 18 ++++++++++-------- netbox_agent/hp/hp.py | 13 ++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/netbox_agent/dmidecode.py b/netbox_agent/dmidecode.py index 9ddc483..ce90cb7 100644 --- a/netbox_agent/dmidecode.py +++ b/netbox_agent/dmidecode.py @@ -117,7 +117,9 @@ def get_by_type(type_id): 42 Management Controller Host Interface """ if isinstance(type_id, str): - type_id = _str2type[type_id] + type_id = _str2type.get(type_id) + if type_id is None: + return None data = parse() result = [] @@ -129,7 +131,7 @@ def get_by_type(type_id): def _execute_cmd(): - return _subprocess.check_output('dmidecode', stderr=_subprocess.PIPE) + return _subprocess.check_output(['dmidecode', ], stderr=_subprocess.PIPE) def _parse(buffer): @@ -168,14 +170,13 @@ def _parse(buffer): break # Check whether we are inside a \t\t block if in_block_elemet != '': - - in_block_data = _in_block_re.findall(record_element[1]) + in_block_data = _in_block_re.findall(record_element[i]) if in_block_data: if not in_block_list: - in_block_list = in_block_data[0][0] + in_block_list = [in_block_data[0]] else: - in_block_list = in_block_list + '\t\t' + in_block_data[0][1] + in_block_list.append(in_block_data[0]) output_data[dmi_handle][in_block_elemet] = in_block_list continue @@ -194,11 +195,12 @@ def _parse(buffer): # Didn't findall regular entry, maybe an array of data? record_data2 = _record2_re.findall(record_element[i]) - if record_data2: # This is an array of data - let the loop know we are inside # an array block - in_block_elemet = record_data2[0][0] + in_block_elemet = record_data2[0] + in_block_list = '' + continue if not output_data: diff --git a/netbox_agent/hp/hp.py b/netbox_agent/hp/hp.py index 11be0ba..cb2f516 100644 --- a/netbox_agent/hp/hp.py +++ b/netbox_agent/hp/hp.py @@ -18,9 +18,16 @@ class HPHost(ServerBase): """ # FIXME: make a dmidecode function get_by_dminame() ? if self.is_blade(): - for key, value in self.dmi.parse().items(): - if value['DMIName'] == 'HP ProLiant System/Rack Locator': - return value + locator = self.dmi.get_by_type(204) + if self.get_product_name() == 'ProLiant BL460c Gen10': + locator = locator[0]['Strings'] + return { + 'Enclosure Model': locator[2].strip(), + 'Enclosure Name': locator[0].strip(), + 'Server Bay': locator[3].strip(), + 'Enclosure Serial': locator[4].strip(), + } + return locator[0] def get_blade_slot(self): if self.is_blade():