Skip to content

Commit

Permalink
Merge pull request #209 from Solvik/fix/chriss/raid_cmd_returncod_hp_…
Browse files Browse the repository at this point in the history
…jbod

Fixed HP raid parser when disks are in JBOD
  • Loading branch information
geektophe authored Mar 11, 2022
2 parents b53dfa9 + ad951b9 commit bb08813
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
34 changes: 26 additions & 8 deletions netbox_agent/raid/hp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@

REGEXP_CONTROLLER_HP = re.compile(r'Smart Array ([a-zA-Z0-9- ]+) in Slot ([0-9]+)')


def ssacli(command):
output = subprocess.getoutput('ssacli {}'.format(command) )
lines = output.split('\n')
class HPRaidControllerError(Exception):
pass


def ssacli(sub_command):
command = ["ssacli"]
command.extend(sub_command.split())
p = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
p.wait()
stdout = p.stdout.read().decode("utf-8")
if p.returncode != 0:
mesg = "Failed to execute command '{}':\n{}".format(
" ".join(command), stdout
)
raise HPRaidControllerError(mesg)
lines = stdout.split('\n')
lines = list(filter(None, lines))
return lines

Expand Down Expand Up @@ -92,8 +108,10 @@ def __init__(self, controller_name, data):
self.controller_name = controller_name
self.data = data
self.pdrives = self._get_physical_disks()
self.ldrives = self._get_logical_drives()
self._get_virtual_drives_map()
arrays = [d['Array'] for d in self.pdrives.values() if d.get('Array')]
if arrays:
self.ldrives = self._get_logical_drives()
self._get_virtual_drives_map()

def get_product_name(self):
return self.controller_name
Expand Down Expand Up @@ -135,6 +153,7 @@ def _get_physical_disks(self):
'Type': 'SSD' if attrs.get('Interface Type') == 'Solid State SATA'
else 'HDD',
'_src': self.__class__.__name__,
'custom_fields': {'pd_identifier': name}
}
return ret

Expand Down Expand Up @@ -164,8 +183,7 @@ def _get_virtual_drives_map(self):
" Ignoring.".format(name)
)
continue
attrs['custom_fields'] = ld
attrs['custom_fields']['pd_identifier'] = name
attrs['custom_fields'].update(ld)

def get_physical_disks(self):
return list(self.pdrives.values())
Expand Down
23 changes: 20 additions & 3 deletions netbox_agent/raid/omreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@
import re


class OmreportControllerError(Exception):
pass


def omreport(sub_command):
command = 'omreport {}'.format(sub_command)
output = subprocess.getoutput(command)
command = ["omreport"]
command.extend(sub_command.split())
p = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
p.wait()
stdout = p.stdout.read().decode("utf-8")
if p.returncode != 0:
mesg = "Failed to execute command '{}':\n{}".format(
" ".join(command), stdout
)
raise OmreportControllerError(mesg)

res = {}
section_re = re.compile('^[A-Z]')
current_section = None
current_obj = None

for line in output.split('\n'):
for line in stdout.split('\n'):
if ': ' in line:
attr, value = line.split(': ', 1)
attr = attr.strip()
Expand Down
25 changes: 21 additions & 4 deletions netbox_agent/raid/storcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@
import os


class StorcliControllerError(Exception):
pass


def storecli(sub_command):
command = 'storcli {} J'.format(sub_command)
output = subprocess.getoutput(command)
data = json.loads(output)
command = ["storcli"]
command.extend(sub_command.split())
command.append("J")
p = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
p.wait()
stdout = p.stdout.read().decode("utf-8")
if p.returncode != 0:
mesg = "Failed to execute command '{}':\n{}".format(
" ".join(command), stdout
)
raise StorcliControllerError(mesg)
data = json.loads(stdout)
controllers = dict([
(
c['Command Status']['Controller'],
Expand All @@ -22,7 +39,7 @@ def storecli(sub_command):
if not controllers:
logging.error(
"Failed to execute command '{}'. "
"Ignoring data.".format(command)
"Ignoring data.".format(" ".join(command))
)
return {}
return controllers
Expand Down

0 comments on commit bb08813

Please sign in to comment.