fix: inventory disk issue if size None

```
Traceback (most recent call last):
  File "/usr/bin/netbox_agent", line 33, in <module>
    sys.exit(load_entry_point('netbox-agent==0.7.1', 'console_scripts', 'netbox_agent')())
  File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/cli.py", line 50, in main
    return run(config)
  File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/cli.py", line 43, in run
    server.netbox_create_or_update(config)
  File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/server.py", line 417, in netbox_create_or_update
    self.inventory.create_or_update()
  File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/inventory.py", line 550, in create_or_update
    self.do_netbox_disks()
  File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/inventory.py", line 420, in do_netbox_disks
    disks = self.get_hw_disks()
  File "/opt/netbox-agent/lib/python3.6/site-packages/netbox_agent/inventory.py", line 344, in get_hw_disks
    size = int(disk.get('size', 0))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
```
This commit is contained in:
Cyril Levis 2022-08-23 08:41:59 +02:00
parent 79a08359ae
commit 0b9087fa41
No known key found for this signature in database
GPG key ID: 6DB88737C11F5A48

View file

@ -341,21 +341,23 @@ class Inventory():
for disk in self.lshw.get_hw_linux("storage"): for disk in self.lshw.get_hw_linux("storage"):
if self.is_virtual_disk(disk, raid_devices): if self.is_virtual_disk(disk, raid_devices):
continue continue
size =int(disk.get('size', 0)) / 1073741824 size = int(getattr(disk, "size", 0))
d = { if size > 0:
"name": "", size /= 1073741824
'Size': '{} GB'.format(size), d = {
'logicalname': disk.get('logicalname'), "name": "",
'description': disk.get('description'), 'Size': '{} GB'.format(size),
'SN': disk.get('serial'), 'logicalname': disk.get('logicalname'),
'Model': disk.get('product'), 'description': disk.get('description'),
'Type': disk.get('type'), 'SN': disk.get('serial'),
} 'Model': disk.get('product'),
if disk.get('vendor'): 'Type': disk.get('type'),
d['Vendor'] = disk['vendor'] }
else: if disk.get('vendor'):
d['Vendor'] = get_vendor(disk['product']) d['Vendor'] = disk['vendor']
disks.append(d) else:
d['Vendor'] = get_vendor(disk['product'])
disks.append(d)
# remove duplicate serials # remove duplicate serials
seen = set() seen = set()