From 4c3864b94e24e8441ac0f4fcf557c3ad2cd84085 Mon Sep 17 00:00:00 2001 From: Solvik Blum Date: Wed, 21 Aug 2019 17:22:22 +0200 Subject: [PATCH] handle HP RAID physical disk --- netbox_agent/raid/base.py | 3 +++ netbox_agent/raid/hp.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/netbox_agent/raid/base.py b/netbox_agent/raid/base.py index 69cec1a..a3d3081 100644 --- a/netbox_agent/raid/base.py +++ b/netbox_agent/raid/base.py @@ -12,6 +12,9 @@ class RaidController(): def get_firmware_version(self): raise NotImplementedError + def get_physical_disks(self): + raise NotImplementedError + class Raid(): def get_controllers(self): diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index d284021..b2a4858 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -106,6 +106,29 @@ class HPRaidController(RaidController): def get_firmware_version(self): return self.data['Firmware Version'] + def get_physical_disks(self): + ret = [] + output = subprocess.getoutput( + 'ssacli ctrl slot={slot} pd all show detail'.format(slot=self.data['Slot']) + ) + lines = output.split('\n') + lines = list(filter(None, lines)) + j = -1 + while j < len(lines): + info_dict, j = _get_dict(lines, j + 1, 0) + + key = next(iter(info_dict)) + for array, physical_disk in info_dict[key].items(): + for _, pd_attr in physical_disk.items(): + ret.append({ + 'Model': pd_attr.get('Model', '').strip(), + 'SN': pd_attr.get('Serial Number', '').strip(), + 'Size': pd_attr.get('Size', '').strip(), + 'Type': 'SSD' if pd_attr.get('Interface Type') == 'Solid State SATA' + else 'HDD', + }) + return ret + class HPRaid(Raid): def __init__(self):