fix logic order while using all nvme disk, round disk size to 2 digit after point
This commit is contained in:
parent
0f4a9ff9aa
commit
814b931410
3 changed files with 35 additions and 23 deletions
|
|
@ -314,15 +314,14 @@ class Inventory():
|
|||
non_raid_disks = [
|
||||
'MR9361-8i',
|
||||
]
|
||||
|
||||
if logicalname in raid_devices or \
|
||||
disk_type is None or \
|
||||
product in non_raid_disks or \
|
||||
'virtual' in product.lower() or \
|
||||
'logical' in product.lower() or \
|
||||
'volume' in description.lower() or \
|
||||
description == 'SCSI Enclosure' or \
|
||||
(size is None and logicalname is None):
|
||||
disk_type is None or \
|
||||
product in non_raid_disks or \
|
||||
'virtual' in product.lower() or \
|
||||
'logical' in product.lower() or \
|
||||
'volume' in description.lower() or \
|
||||
description == 'SCSI Enclosure' or \
|
||||
(size is None and logicalname is None):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -339,9 +338,10 @@ class Inventory():
|
|||
]
|
||||
|
||||
for disk in self.lshw.get_hw_linux("storage"):
|
||||
logging.debug(f"disk: {disk}")
|
||||
if self.is_virtual_disk(disk, raid_devices):
|
||||
continue
|
||||
size =int(disk.get('size', 0)) / 1073741824
|
||||
size = round(int(disk.get('size', 0)) / 1073741824, 2)
|
||||
d = {
|
||||
"name": "",
|
||||
'Size': '{} GB'.format(size),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class LSHW():
|
|||
data = subprocess.getoutput(
|
||||
'lshw -quiet -json'
|
||||
)
|
||||
|
||||
json_data = json.loads(data)
|
||||
# Starting from version 02.18, `lshw -json` wraps its result in a list
|
||||
# rather than returning directly a dictionary
|
||||
|
|
@ -72,8 +73,9 @@ class LSHW():
|
|||
# Some interfaces do not have device (logical) name (eth0, for
|
||||
# instance), such as not connected network mezzanine cards in blade
|
||||
# servers. In such situations, the card will be named `unknown[0-9]`.
|
||||
#DEBUG:root:lshw interfaces is: [{'name': ['enp68s0f0', '/dev/fb0'], 'macaddress': 'xx:ec:xx:fb:xx:xx', 'serial': 'xx:ec:xx:fb:xx:xx', 'product': 'Ethernet Controller X710 for 10GBASE-T', 'vendor': 'Intel Corporation', 'description': 'Ethernet interface'}]
|
||||
unkn_intfs = [
|
||||
i for i in self.interfaces if i["name"].startswith("unknown")
|
||||
i for i in self.interfaces if i["name"][0].startswith("unknown")
|
||||
]
|
||||
unkn_name = "unknown{}".format(len(unkn_intfs))
|
||||
self.interfaces.append({
|
||||
|
|
@ -86,18 +88,8 @@ class LSHW():
|
|||
})
|
||||
|
||||
def find_storage(self, obj):
|
||||
if "children" in obj:
|
||||
for device in obj["children"]:
|
||||
self.disks.append({
|
||||
"logicalname": device.get("logicalname"),
|
||||
"product": device.get("product"),
|
||||
"serial": device.get("serial"),
|
||||
"version": device.get("version"),
|
||||
"size": device.get("size"),
|
||||
"description": device.get("description"),
|
||||
"type": device.get("description"),
|
||||
})
|
||||
elif "nvme" in obj["configuration"]["driver"]:
|
||||
if "nvme" in obj["configuration"]["driver"]:
|
||||
logging.debug("go to nvme")
|
||||
if not is_tool('nvme'):
|
||||
logging.error('nvme-cli >= 1.0 does not seem to be installed')
|
||||
return
|
||||
|
|
@ -123,7 +115,25 @@ class LSHW():
|
|||
self.disks.append(d)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
elif "children" in obj:
|
||||
logging.debug("go to children")
|
||||
for device in obj["children"]:
|
||||
logging.debug(device)
|
||||
# if device.get("logicalname") is None or device.get("product") is None or \
|
||||
# device.get("serial") is None or device.get("version") is None or \
|
||||
# device.get("size") is None:
|
||||
# continue
|
||||
if device.get("size") is None:
|
||||
continue
|
||||
self.disks.append({
|
||||
"logicalname": device.get("logicalname"),
|
||||
"product": device.get("product"),
|
||||
"serial": device.get("serial"),
|
||||
"version": device.get("version"),
|
||||
"size": device.get("size"),
|
||||
"description": device.get("description"),
|
||||
"type": device.get("description"),
|
||||
})
|
||||
def find_cpus(self, obj):
|
||||
if "product" in obj:
|
||||
self.cpus.append({
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ class Network(object):
|
|||
def get_or_create_vlan(self, vlan_id):
|
||||
# FIXME: we may need to specify the datacenter
|
||||
# since users may have same vlan id in multiple dc
|
||||
logging.debug(f"VLAN ID is: {vlan_id}")
|
||||
vlan = nb.ipam.vlans.get(
|
||||
vid=vlan_id,
|
||||
)
|
||||
|
|
@ -305,6 +306,7 @@ class Network(object):
|
|||
# if pvid is not present, it'll be processed as a vlan tagged interface
|
||||
vlans = self.lldp.get_switch_vlan(nic['name'])
|
||||
for vid, vlan_infos in vlans.items():
|
||||
logging.debug(f"vid: {vid}, infos: {vlan_infos}")
|
||||
nb_vlan = self.get_or_create_vlan(vid)
|
||||
if vlan_infos.get('vid'):
|
||||
interface.mode = self.dcim_choices['interface:mode']['Access']
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue