Merge pull request 'Make lshw scrpping more resilient' (#292) from sinavir/fix_gpu_without_vendor into master

Reviewed-on: #292
This commit is contained in:
thubrecht 2024-10-21 10:15:27 +02:00
commit 7a968deee9

View file

@ -77,20 +77,20 @@ class LSHW():
# newer versions of lshw can return a list of names, see issue #227 # newer versions of lshw can return a list of names, see issue #227
if not isinstance(i["name"], list): if not isinstance(i["name"], list):
if i["name"].startswith("unknown"): if i["name"].startswith("unknown"):
unkn_intfs.push(i) unkn_intfs.append(i)
else: else:
for j in i["name"]: for j in i["name"]:
if j.startswith("unknown"): if j.startswith("unknown"):
unkn_intfs.push(j) unkn_intfs.append(j)
unkn_name = "unknown{}".format(len(unkn_intfs)) unkn_name = "unknown{}".format(len(unkn_intfs))
self.interfaces.append({ self.interfaces.append({
"name": obj.get("logicalname", unkn_name), "name": obj.get("logicalname", unkn_name),
"macaddress": obj.get("serial", ""), "macaddress": obj.get("serial", ""),
"serial": obj.get("serial", ""), "serial": obj.get("serial", ""),
"product": obj["product"], "product": obj.get("product", "Unknown NIC"),
"vendor": obj["vendor"], "vendor": obj.get("vendor", "Unknown"),
"description": obj["description"], "description": obj.get("description", ""),
}) })
def find_storage(self, obj): def find_storage(self, obj):
@ -135,10 +135,10 @@ class LSHW():
def find_cpus(self, obj): def find_cpus(self, obj):
if "product" in obj: if "product" in obj:
self.cpus.append({ self.cpus.append({
"product": obj["product"], "product": obj.get("product", "Unknown CPU"),
"vendor": obj["vendor"], "vendor": obj.get("vendor", "Unknown vendor"),
"description": obj["description"], "description": obj.get("description", ""),
"location": obj["slot"], "location": obj.get("slot", ""),
}) })
def find_memories(self, obj): def find_memories(self, obj):
@ -162,11 +162,12 @@ class LSHW():
def find_gpus(self, obj): def find_gpus(self, obj):
if "product" in obj: if "product" in obj:
self.gpus.append({ infos = {
"product": obj["product"], "product": obj.get("product", "Unknown GPU"),
"vendor": obj["vendor"], "vendor": obj.get("vendor", "Unknown"),
"description": obj["description"], "description": obj.get("description", ""),
}) }
self.gpus.append(infos)
def walk_bridge(self, obj): def walk_bridge(self, obj):
if "children" not in obj: if "children" not in obj: