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]:
|
if raid_card.get_serial_number() not in [x.serial for x in nb_raid_cards]:
|
||||||
self.create_netbox_raid_card(raid_card)
|
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 = [
|
non_raid_disks = [
|
||||||
'MR9361-8i',
|
'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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -301,17 +311,22 @@ class Inventory():
|
||||||
disks = []
|
disks = []
|
||||||
|
|
||||||
for disk in self.lshw.get_hw_linux("storage"):
|
for disk in self.lshw.get_hw_linux("storage"):
|
||||||
product = disk.get('product')
|
if self.is_virtual_disk(disk):
|
||||||
if self.is_virtual_disk(product):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
logicalname = disk.get('logicalname')
|
||||||
|
description = disk.get('description')
|
||||||
|
size = disk.get('size')
|
||||||
|
product = disk.get('product')
|
||||||
|
serial = disk.get('serial')
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
d["name"] = ""
|
d["name"] = ""
|
||||||
d['Size'] = '{} GB'.format(int(disk['size']/1024/1024/1024))
|
d['Size'] = '{} GB'.format(int(disk['size']/1024/1024/1024))
|
||||||
d['logicalname'] = disk['logicalname']
|
d['logicalname'] = logicalname
|
||||||
d['description'] = disk['description']
|
d['description'] = description
|
||||||
d['SN'] = disk.get('serial')
|
d['SN'] = serial
|
||||||
d['Model'] = disk.get('product')
|
d['Model'] = product
|
||||||
if disk.get('vendor'):
|
if disk.get('vendor'):
|
||||||
d['Vendor'] = disk['vendor']
|
d['Vendor'] = disk['vendor']
|
||||||
else:
|
else:
|
||||||
|
|
@ -321,18 +336,25 @@ class Inventory():
|
||||||
for raid_card in self.get_raid_cards():
|
for raid_card in self.get_raid_cards():
|
||||||
disks += raid_card.get_physical_disks()
|
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):
|
def create_netbox_disk(self, disk):
|
||||||
manufacturer = None
|
manufacturer = None
|
||||||
if "Vendor" in disk:
|
if "Vendor" in disk:
|
||||||
manufacturer = self.find_or_create_manufacturer(disk["Vendor"])
|
manufacturer = self.find_or_create_manufacturer(disk["Vendor"])
|
||||||
|
|
||||||
|
logicalname = disk.get('logicalname')
|
||||||
|
desc = disk.get('description')
|
||||||
# nonraid disk
|
# nonraid disk
|
||||||
if disk.get('logicalname') and disk.get('description'):
|
if logicalname and desc:
|
||||||
|
if type(logicalname) is list:
|
||||||
|
logicalname = logicalname[0]
|
||||||
name = '{} - {} ({})'.format(
|
name = '{} - {} ({})'.format(
|
||||||
disk.get('description'),
|
desc,
|
||||||
disk.get('logicalname'),
|
logicalname,
|
||||||
disk.get('Size', 0))
|
disk.get('Size', 0))
|
||||||
description = 'Device {}'.format(disk.get('logicalname', 'Unknown'))
|
description = 'Device {}'.format(disk.get('logicalname', 'Unknown'))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ class LSHW():
|
||||||
self.vendor = self.hw_info["vendor"]
|
self.vendor = self.hw_info["vendor"]
|
||||||
self.product = self.hw_info["product"]
|
self.product = self.hw_info["product"]
|
||||||
self.chassis_serial = self.hw_info["serial"]
|
self.chassis_serial = self.hw_info["serial"]
|
||||||
self.motherboard_serial = self.hw_info["children"][0]["serial"]
|
self.motherboard_serial = self.hw_info["children"][0].get("serial", "No S/N")
|
||||||
self.motherboard = self.hw_info["children"][0]["product"]
|
self.motherboard = self.hw_info["children"][0].get("product", "Motherboard")
|
||||||
|
|
||||||
for k in self.hw_info["children"]:
|
for k in self.hw_info["children"]:
|
||||||
if k["class"] == "power":
|
if k["class"] == "power":
|
||||||
|
|
@ -75,12 +75,12 @@ class LSHW():
|
||||||
if "children" in obj:
|
if "children" in obj:
|
||||||
for device in obj["children"]:
|
for device in obj["children"]:
|
||||||
d = {}
|
d = {}
|
||||||
d["logicalname"] = device["logicalname"]
|
d["logicalname"] = device.get("logicalname")
|
||||||
d["product"] = device["product"]
|
d["product"] = device.get("product")
|
||||||
d["serial"] = device["serial"]
|
d["serial"] = device.get("serial")
|
||||||
d["version"] = device["version"]
|
d["version"] = device.get("version")
|
||||||
d["size"] = device["size"]
|
d["size"] = device.get("size")
|
||||||
d["description"] = device["description"]
|
d["description"] = device.get("description")
|
||||||
|
|
||||||
self.disks.append(d)
|
self.disks.append(d)
|
||||||
|
|
||||||
|
|
@ -121,13 +121,13 @@ class LSHW():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
d["slot"] = dimm["slot"]
|
d["slot"] = dimm.get("slot")
|
||||||
d["description"] = dimm["description"]
|
d["description"] = dimm.get("description")
|
||||||
d["id"] = dimm["id"]
|
d["id"] = dimm.get("id")
|
||||||
d["serial"] = dimm["serial"]
|
d["serial"] = dimm.get("serial", 'N/A')
|
||||||
d["vendor"] = dimm["vendor"]
|
d["vendor"] = dimm.get("vendor")
|
||||||
d["product"] = dimm["product"]
|
d["product"] = dimm.get("product")
|
||||||
d["size"] = dimm["size"] / 2 ** 20 / 1024
|
d["size"] = dimm.get("size", 0) / 2 ** 20 / 1024
|
||||||
|
|
||||||
self.memories.append(d)
|
self.memories.append(d)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,6 @@ class Network():
|
||||||
|
|
||||||
def update_netbox_network_cards(self):
|
def update_netbox_network_cards(self):
|
||||||
if config.update_all is None or config.update_network is None:
|
if config.update_all is None or config.update_network is None:
|
||||||
print(config)
|
|
||||||
return None
|
return None
|
||||||
logging.debug('Updating NIC...')
|
logging.debug('Updating NIC...')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue