Local inventory #16
4 changed files with 22 additions and 12 deletions
|
@ -6,7 +6,6 @@ from netbox_agent.config import netbox_instance as nb
|
||||||
from netbox_agent.misc import is_tool
|
from netbox_agent.misc import is_tool
|
||||||
from netbox_agent.raid.hp import HPRaid
|
from netbox_agent.raid.hp import HPRaid
|
||||||
from netbox_agent.raid.dell import StorcliRaid
|
from netbox_agent.raid.dell import StorcliRaid
|
||||||
import netbox_agent.dmidecode as dmidecode
|
|
||||||
|
|
||||||
INVENTORY_TAG = {
|
INVENTORY_TAG = {
|
||||||
'cpu': {'name': 'hw:cpu', 'slug': 'hw-cpu'},
|
'cpu': {'name': 'hw:cpu', 'slug': 'hw-cpu'},
|
||||||
|
@ -67,7 +66,7 @@ class Inventory():
|
||||||
def create_netbox_cpus(self):
|
def create_netbox_cpus(self):
|
||||||
nb_cpus, model = self.get_cpus()
|
nb_cpus, model = self.get_cpus()
|
||||||
for i in range(nb_cpus):
|
for i in range(nb_cpus):
|
||||||
cpu = nb.dcim.inventory_items.create(
|
_ = nb.dcim.inventory_items.create(
|
||||||
device=self.device_id,
|
device=self.device_id,
|
||||||
tags=[INVENTORY_TAG['cpu']['name']],
|
tags=[INVENTORY_TAG['cpu']['name']],
|
||||||
name=model,
|
name=model,
|
||||||
|
@ -134,6 +133,7 @@ class Inventory():
|
||||||
name='{}'.format(raid_card.get_product_name()),
|
name='{}'.format(raid_card.get_product_name()),
|
||||||
serial='{}'.format(raid_card.get_serial_number()),
|
serial='{}'.format(raid_card.get_serial_number()),
|
||||||
)
|
)
|
||||||
|
return nb_raid_card
|
||||||
|
|
||||||
def create_netbox_raid_cards(self):
|
def create_netbox_raid_cards(self):
|
||||||
for raid_card in self.get_raid_cards():
|
for raid_card in self.get_raid_cards():
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
class RaidController():
|
class RaidController():
|
||||||
|
|
||||||
def get_product_name(self):
|
def get_product_name(self):
|
||||||
raise NotImplemented
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_serial_number(self):
|
def get_serial_number(self):
|
||||||
raise NotImplemented
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_manufacturer(self):
|
def get_manufacturer(self):
|
||||||
raise NotImplemented
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_firmware_version(self):
|
def get_firmware_version(self):
|
||||||
raise NotImplemented
|
raise NotImplementedError
|
||||||
|
|
||||||
class Raid():
|
class Raid():
|
||||||
def get_controllers(self):
|
def get_controllers(self):
|
||||||
raise NotImplemented
|
raise NotImplementedError
|
||||||
|
|
|
@ -3,6 +3,7 @@ import json
|
||||||
|
|
||||||
from netbox_agent.raid.base import Raid, RaidController
|
from netbox_agent.raid.base import Raid, RaidController
|
||||||
|
|
||||||
|
|
||||||
class StorcliController(RaidController):
|
class StorcliController(RaidController):
|
||||||
def __init__(self, controller_index, data):
|
def __init__(self, controller_index, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
@ -22,14 +23,18 @@ class StorcliController(RaidController):
|
||||||
|
|
||||||
def get_physical_disks(self):
|
def get_physical_disks(self):
|
||||||
ret = []
|
ret = []
|
||||||
output = subprocess.getoutput('storcli /c{}/eall/sall show all J'.format(self.controller_index))
|
output = subprocess.getoutput(
|
||||||
|
'storcli /c{}/eall/sall show all J'.format(self.controller_index)
|
||||||
|
)
|
||||||
drive_infos = json.loads(output)['Controllers'][self.controller_index]['Response Data']
|
drive_infos = json.loads(output)['Controllers'][self.controller_index]['Response Data']
|
||||||
|
|
||||||
for physical_drive in self.data['PD LIST']:
|
for physical_drive in self.data['PD LIST']:
|
||||||
enclosure = physical_drive.get('EID:Slt').split(':')[0]
|
enclosure = physical_drive.get('EID:Slt').split(':')[0]
|
||||||
slot = physical_drive.get('EID:Slt').split(':')[1]
|
slot = physical_drive.get('EID:Slt').split(':')[1]
|
||||||
size = physical_drive.get('Size').strip()
|
size = physical_drive.get('Size').strip()
|
||||||
drive_identifier = 'Drive /c{}/e{}/s{}'.format(str(self.controller_index), str(enclosure), str(slot))
|
drive_identifier = 'Drive /c{}/e{}/s{}'.format(
|
||||||
|
str(self.controller_index), str(enclosure), str(slot)
|
||||||
|
)
|
||||||
drive_attr = drive_infos['{} - Detailed Information'.format(drive_identifier)]\
|
drive_attr = drive_infos['{} - Detailed Information'.format(drive_identifier)]\
|
||||||
['{} Device attributes'.format(drive_identifier)]
|
['{} Device attributes'.format(drive_identifier)]
|
||||||
ret.append({
|
ret.append({
|
||||||
|
@ -46,7 +51,7 @@ class StorcliRaid(Raid):
|
||||||
self.controllers = []
|
self.controllers = []
|
||||||
|
|
||||||
if len([
|
if len([
|
||||||
x for x in self.data['Controllers'] \
|
x for x in self.data['Controllers']
|
||||||
if x['Command Status']['Status'] == 'Success'
|
if x['Command Status']['Status'] == 'Success'
|
||||||
]) > 0:
|
]) > 0:
|
||||||
for controller in self.data['Controllers']:
|
for controller in self.data['Controllers']:
|
||||||
|
|
|
@ -5,10 +5,12 @@ from netbox_agent.raid.base import Raid, RaidController
|
||||||
|
|
||||||
REGEXP_CONTROLLER_HP = re.compile(r'Smart Array ([a-zA-Z0-9- ]+) in Slot ([0-9]+)')
|
REGEXP_CONTROLLER_HP = re.compile(r'Smart Array ([a-zA-Z0-9- ]+) in Slot ([0-9]+)')
|
||||||
|
|
||||||
|
|
||||||
def _get_indentation(string):
|
def _get_indentation(string):
|
||||||
"""Return the number of spaces before the current line."""
|
"""Return the number of spaces before the current line."""
|
||||||
return len(string) - len(string.lstrip(' '))
|
return len(string) - len(string.lstrip(' '))
|
||||||
|
|
||||||
|
|
||||||
def _get_key_value(string):
|
def _get_key_value(string):
|
||||||
"""Return the (key, value) as a tuple from a string."""
|
"""Return the (key, value) as a tuple from a string."""
|
||||||
# Normally all properties look like this:
|
# Normally all properties look like this:
|
||||||
|
@ -36,6 +38,7 @@ def _get_key_value(string):
|
||||||
|
|
||||||
return key.lstrip(' ').rstrip(' '), value.lstrip(' ').rstrip(' ')
|
return key.lstrip(' ').rstrip(' '), value.lstrip(' ').rstrip(' ')
|
||||||
|
|
||||||
|
|
||||||
def _get_dict(lines, start_index, indentation):
|
def _get_dict(lines, start_index, indentation):
|
||||||
"""Recursive function for parsing hpssacli/ssacli output."""
|
"""Recursive function for parsing hpssacli/ssacli output."""
|
||||||
|
|
||||||
|
@ -85,6 +88,7 @@ def _get_dict(lines, start_index, indentation):
|
||||||
|
|
||||||
return info, i
|
return info, i
|
||||||
|
|
||||||
|
|
||||||
class HPRaidController(RaidController):
|
class HPRaidController(RaidController):
|
||||||
def __init__(self, controller_name, data):
|
def __init__(self, controller_name, data):
|
||||||
self.controller_name = controller_name
|
self.controller_name = controller_name
|
||||||
|
@ -102,6 +106,7 @@ class HPRaidController(RaidController):
|
||||||
def get_firmware_version(self):
|
def get_firmware_version(self):
|
||||||
return self.data['Firmware Version']
|
return self.data['Firmware Version']
|
||||||
|
|
||||||
|
|
||||||
class HPRaid(Raid):
|
class HPRaid(Raid):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.output = subprocess.getoutput('ssacli ctrl all show detail')
|
self.output = subprocess.getoutput('ssacli ctrl all show detail')
|
||||||
|
|
Loading…
Add table
Reference in a new issue