Skip to content

Commit

Permalink
Add changes to retrieve bhyve product name
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Apr 23, 2024
1 parent d56d72d commit 38dfd13
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ixhardware/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from .chassis import PLATFORM_PREFIXES, TRUENAS_UNKNOWN, get_chassis_hardware
from .chassis import (
PLATFORM_PREFIXES, TRUENAS_UNKNOWN, get_chassis_hardware, get_bhyve_hardware_and_node,
TRUENAS_QEMU, TRUENAS_BHYVE,
)
from .dmi import DMIInfo, DMIParser, parse_dmi

__all__ = ["PLATFORM_PREFIXES", "TRUENAS_UNKNOWN", "get_chassis_hardware", "DMIInfo", "DMIParser", "parse_dmi"]
__all__ = [
"PLATFORM_PREFIXES", "TRUENAS_UNKNOWN", "get_chassis_hardware", "DMIInfo", "DMIParser", "parse_dmi",
"get_bhyve_hardware_and_node", "TRUENAS_QEMU", "TRUENAS_BHYVE",
]
36 changes: 34 additions & 2 deletions ixhardware/chassis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import typing

from pyudev import Context

from .dmi import DMIInfo

__all__ = ["PLATFORM_PREFIXES", "TRUENAS_UNKNOWN", "get_chassis_hardware"]
__all__ = [
"PLATFORM_PREFIXES", "TRUENAS_UNKNOWN", "get_chassis_hardware", "TRUENAS_BHYVE", "TRUENAS_QEMU",
"get_bhyve_hardware_and_node",
]


# We tag SMBIOS with relevant strings for each platform
Expand All @@ -16,6 +23,7 @@
"TRUENAS-R", # freenas certified replacement
"FREENAS-MINI", # minis tagged with legacy information
)
TRUENAS_BHYVE = "BHYVE"
TRUENAS_QEMU = "IXKVM"
TRUENAS_UNKNOWN = "TRUENAS-UNKNOWN"

Expand All @@ -30,9 +38,33 @@ def get_chassis_hardware(dmi: DMIInfo):
# last resort
return "TRUENAS-X"

if dmi.system_product_name == "qemu" and dmi.system_serial_number.startswith(
elif dmi.system_product_name == "qemu" and dmi.system_serial_number.startswith(
"ha"
) and dmi.system_serial_number.endswith(("_c1", "_c2")):
return TRUENAS_QEMU

elif dmi.system_product_name == "BHYVE":
if get_bhyve_hardware_and_node()[0] == "BHYVE":
return TRUENAS_BHYVE

return TRUENAS_UNKNOWN


def get_bhyve_hardware_and_node() -> typing.Tuple[str, str]:
# bhyve host configures a scsi_generic device that when sent an inquiry will
# respond with a string that we use to determine the position of the node
HARDWARE = NODE = "MANUAL"
ctx = Context()
for i in ctx.list_devices(subsystem="scsi_generic"):
if (model := i.attributes.get("device/model")) is not None:
model = model.decode().strip() if isinstance(model, bytes) else model.strip()
if model == "TrueNAS_A":
NODE = "A"
HARDWARE = "BHYVE"
break
elif model == "TrueNAS_B":
NODE = "B"
HARDWARE = "BHYVE"
break

return HARDWARE, NODE

0 comments on commit 38dfd13

Please sign in to comment.