handle more cases for inventory
This commit is contained in:
parent
b0ead9ebb3
commit
23d590e3c7
3 changed files with 50 additions and 29 deletions
|
|
@ -289,11 +289,21 @@ class Inventory():
|
|||
if raid_card.get_serial_number() not in [x.serial for x in nb_raid_cards]:
|
||||
self.create_netbox_raid_card(raid_card)
|
||||
|
||||
def is_virtual_disk(self, product):
|
||||
def is_virtual_disk(self, disk):
|
||||
logicalname = disk.get('logicalname')
|
||||
description = disk.get('description')
|
||||
size = disk.get('size')
|
||||
product = disk.get('product')
|
||||
|
||||
non_raid_disks = [
|
||||
'MR9361-8i',
|
||||
]
|
||||
if 'virtual' in product or 'logical' in product or product in non_raid_disks:
|
||||
]
|
||||
|
||||
if size is None and logicalname is None or \
|
||||
'virtual' in product.lower() or 'logical' in product.lower() or \
|
||||
product in non_raid_disks or \
|
||||
description == 'SCSI Enclosure' or \
|
||||
'volume' in description.lower() :
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -301,17 +311,22 @@ class Inventory():
|
|||
disks = []
|
||||
|
||||
for disk in self.lshw.get_hw_linux("storage"):
|
||||
product = disk.get('product')
|
||||
if self.is_virtual_disk(product):
|
||||
if self.is_virtual_disk(disk):
|
||||
continue
|
||||
|
||||
logicalname = disk.get('logicalname')
|
||||
description = disk.get('description')
|
||||
size = disk.get('size')
|
||||
product = disk.get('product')
|
||||
serial = disk.get('serial')
|
||||
|
||||
d = {}
|
||||
d["name"] = ""
|
||||
d['Size'] = '{} GB'.format(int(disk['size']/1024/1024/1024))
|
||||
d['logicalname'] = disk['logicalname']
|
||||
d['description'] = disk['description']
|
||||
d['SN'] = disk.get('serial')
|
||||
d['Model'] = disk.get('product')
|
||||
d['logicalname'] = logicalname
|
||||
d['description'] = description
|
||||
d['SN'] = serial
|
||||
d['Model'] = product
|
||||
if disk.get('vendor'):
|
||||
d['Vendor'] = disk['vendor']
|
||||
else:
|
||||
|
|
@ -321,18 +336,25 @@ class Inventory():
|
|||
for raid_card in self.get_raid_cards():
|
||||
disks += raid_card.get_physical_disks()
|
||||
|
||||
return disks
|
||||
# remove duplicate serials
|
||||
seen = set()
|
||||
uniq = [x for x in disks if x['SN'] not in seen and not seen.add(x['SN'])]
|
||||
return uniq
|
||||
|
||||
def create_netbox_disk(self, disk):
|
||||
manufacturer = None
|
||||
if "Vendor" in disk:
|
||||
manufacturer = self.find_or_create_manufacturer(disk["Vendor"])
|
||||
|
||||
logicalname = disk.get('logicalname')
|
||||
desc = disk.get('description')
|
||||
# nonraid disk
|
||||
if disk.get('logicalname') and disk.get('description'):
|
||||
if logicalname and desc:
|
||||
if type(logicalname) is list:
|
||||
logicalname = logicalname[0]
|
||||
name = '{} - {} ({})'.format(
|
||||
disk.get('description'),
|
||||
disk.get('logicalname'),
|
||||
desc,
|
||||
logicalname,
|
||||
disk.get('Size', 0))
|
||||
description = 'Device {}'.format(disk.get('logicalname', 'Unknown'))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ class LSHW():
|
|||
self.vendor = self.hw_info["vendor"]
|
||||
self.product = self.hw_info["product"]
|
||||
self.chassis_serial = self.hw_info["serial"]
|
||||
self.motherboard_serial = self.hw_info["children"][0]["serial"]
|
||||
self.motherboard = self.hw_info["children"][0]["product"]
|
||||
self.motherboard_serial = self.hw_info["children"][0].get("serial", "No S/N")
|
||||
self.motherboard = self.hw_info["children"][0].get("product", "Motherboard")
|
||||
|
||||
for k in self.hw_info["children"]:
|
||||
if k["class"] == "power":
|
||||
|
|
@ -75,12 +75,12 @@ class LSHW():
|
|||
if "children" in obj:
|
||||
for device in obj["children"]:
|
||||
d = {}
|
||||
d["logicalname"] = device["logicalname"]
|
||||
d["product"] = device["product"]
|
||||
d["serial"] = device["serial"]
|
||||
d["version"] = device["version"]
|
||||
d["size"] = device["size"]
|
||||
d["description"] = device["description"]
|
||||
d["logicalname"] = device.get("logicalname")
|
||||
d["product"] = device.get("product")
|
||||
d["serial"] = device.get("serial")
|
||||
d["version"] = device.get("version")
|
||||
d["size"] = device.get("size")
|
||||
d["description"] = device.get("description")
|
||||
|
||||
self.disks.append(d)
|
||||
|
||||
|
|
@ -121,13 +121,13 @@ class LSHW():
|
|||
continue
|
||||
|
||||
d = {}
|
||||
d["slot"] = dimm["slot"]
|
||||
d["description"] = dimm["description"]
|
||||
d["id"] = dimm["id"]
|
||||
d["serial"] = dimm["serial"]
|
||||
d["vendor"] = dimm["vendor"]
|
||||
d["product"] = dimm["product"]
|
||||
d["size"] = dimm["size"] / 2 ** 20 / 1024
|
||||
d["slot"] = dimm.get("slot")
|
||||
d["description"] = dimm.get("description")
|
||||
d["id"] = dimm.get("id")
|
||||
d["serial"] = dimm.get("serial", 'N/A')
|
||||
d["vendor"] = dimm.get("vendor")
|
||||
d["product"] = dimm.get("product")
|
||||
d["size"] = dimm.get("size", 0) / 2 ** 20 / 1024
|
||||
|
||||
self.memories.append(d)
|
||||
|
||||
|
|
|
|||
|
|
@ -503,7 +503,6 @@ class Network():
|
|||
|
||||
def update_netbox_network_cards(self):
|
||||
if config.update_all is None or config.update_network is None:
|
||||
print(config)
|
||||
return None
|
||||
logging.debug('Updating NIC...')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue