Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to detect iX CI VMs #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
40 changes: 39 additions & 1 deletion 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,8 @@
"TRUENAS-R", # freenas certified replacement
"FREENAS-MINI", # minis tagged with legacy information
)
TRUENAS_BHYVE = "BHYVE"
TRUENAS_QEMU = "IXKVM"
TRUENAS_UNKNOWN = "TRUENAS-UNKNOWN"


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

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
Loading