use lshw for inventory #58
2 changed files with 17 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from netbox_agent.config import netbox_instance as nb, config
|
from netbox_agent.config import netbox_instance as nb, config
|
||||||
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
|
||||||
|
@ -95,7 +97,7 @@ class Inventory():
|
||||||
|
|
||||||
_ = nb.dcim.inventory_items.create(
|
_ = nb.dcim.inventory_items.create(
|
||||||
device=device_id,
|
device=device_id,
|
||||||
manufacturer = manufacturer.id,
|
manufacturer=manufacturer.id,
|
||||||
discovered=True,
|
discovered=True,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
name='{}'.format(name),
|
name='{}'.format(name),
|
||||||
|
@ -114,10 +116,10 @@ class Inventory():
|
||||||
motherboards = []
|
motherboards = []
|
||||||
|
|
||||||
m = {}
|
m = {}
|
||||||
m['serial'] = self.lshw.motherboard_serial
|
m['serial']=self.lshw.motherboard_serial
|
||||||
m['vendor'] = self.lshw.vendor
|
m['vendor']=self.lshw.vendor
|
||||||
m['name'] = '{} {}'.format(self.lshw.vendor, self.lshw.motherboard)
|
m['name']='{} {}'.format(self.lshw.vendor, self.lshw.motherboard)
|
||||||
m['description'] = '{} Motherboard'.format(self.lshw.motherboard)
|
m['description']='{} Motherboard'.format(self.lshw.motherboard)
|
||||||
|
|
||||||
motherboards.append(m)
|
motherboards.append(m)
|
||||||
|
|
||||||
|
@ -187,7 +189,7 @@ class Inventory():
|
||||||
manufacturer = self.find_or_create_manufacturer(cpu["vendor"])
|
manufacturer = self.find_or_create_manufacturer(cpu["vendor"])
|
||||||
_ = nb.dcim.inventory_items.create(
|
_ = nb.dcim.inventory_items.create(
|
||||||
device=self.device_id,
|
device=self.device_id,
|
||||||
manufacturer = manufacturer.id,
|
manufacturer=manufacturer.id,
|
||||||
discovered=True,
|
discovered=True,
|
||||||
tags=[INVENTORY_TAG['cpu']['name']],
|
tags=[INVENTORY_TAG['cpu']['name']],
|
||||||
name=cpu['product'],
|
name=cpu['product'],
|
||||||
|
|
|
@ -6,7 +6,10 @@ import json
|
||||||
class LSHW():
|
class LSHW():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.hw_info = json.loads(subprocess.check_output(["lshw", "-quiet", "-json"],encoding='utf8'))
|
self.hw_info = json.loads(
|
||||||
|
subprocess.check_output(["lshw", "-quiet", "-json"],
|
||||||
|
encoding='utf8')
|
||||||
|
)
|
||||||
|
|
||||||
self.info = {}
|
self.info = {}
|
||||||
self.memories = []
|
self.memories = []
|
||||||
|
@ -77,8 +80,10 @@ class LSHW():
|
||||||
self.disks.append(d)
|
self.disks.append(d)
|
||||||
|
|
||||||
elif "nvme" in obj["configuration"]["driver"]:
|
elif "nvme" in obj["configuration"]["driver"]:
|
||||||
nvme = json.loads(subprocess.check_output(["nvme", '-list', '-o', 'json'],
|
nvme = json.loads(
|
||||||
encoding='utf8'))
|
subprocess.check_output(["nvme", '-list', '-o', 'json'],
|
||||||
|
encoding='utf8')
|
||||||
|
)
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
d["vendor"] = obj["vendor"]
|
d["vendor"] = obj["vendor"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue