Skip to content

Commit

Permalink
feat: add get_hardwarevendor_from_hostnamectl
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Miller <[email protected]>
  • Loading branch information
Dustin Miller committed Sep 18, 2023
1 parent ab54f1d commit 6f90f53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packethardware/component/management_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self):
self.name = self.model + " Base Management Controller"

self.vendor = utils.normalize_vendor(utils.get_mc_info("vendor"))

if "unknown" in self.vendor.lower():
self.vendor = utils.get_hardwarevendor_from_hostnamectl(self)

self.serial = utils.get_mc_info("guid")

self.data = {"aux": utils.get_mc_info("aux")}
Expand Down
14 changes: 14 additions & 0 deletions packethardware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,17 @@ def get_bios_features():
obj = json.loads(bios_features)

return json.dumps(obj)


def get_hardwarevendor_from_hostnamectl(self):
hostnamectl_output = cmd_output("hostnamectl", "--json", "pretty")
if hostnamectl_output:
try:
data = json.loads(hostnamectl_output)
return data.get("HardwareVendor", None)
except json.JSONDecodeError:
print("Failed to parse JSON output")
return None
else:
print("Failed to get hostnamectl output")
return None

0 comments on commit 6f90f53

Please sign in to comment.