summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-07-27 14:07:26 +0300
committerMaxim Devaev <[email protected]>2024-07-27 14:07:26 +0300
commit7e42d320076eec94adf1d42ecca361bd38275feb (patch)
tree201e3286a6a2fa879dbf574d1e2357946d7aac11 /kvmd
parent6a665cd62fc317c62cb2486f701f4dc7ef2de29d (diff)
pikvm/pikvm#1342: Verbose platform info in /api/info
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py1
-rw-r--r--kvmd/apps/kvmd/info/hw.py29
2 files changed, 27 insertions, 3 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 25279be5..035b3cc4 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -382,6 +382,7 @@ def _get_config_scheme() -> dict:
"meta": Option("/etc/kvmd/meta.yaml", type=valid_abs_file),
"extras": Option("/usr/share/kvmd/extras", type=valid_abs_dir),
"hw": {
+ "platform": Option("/usr/share/kvmd/platform", type=valid_abs_file, unpack_as="platform_path"),
"vcgencmd_cmd": Option(["/usr/bin/vcgencmd"], type=valid_command),
"ignore_past": Option(False, type=valid_bool),
"state_poll": Option(5.0, type=valid_float_f01),
diff --git a/kvmd/apps/kvmd/info/hw.py b/kvmd/apps/kvmd/info/hw.py
index 33cedf70..62be7e4c 100644
--- a/kvmd/apps/kvmd/info/hw.py
+++ b/kvmd/apps/kvmd/info/hw.py
@@ -47,11 +47,13 @@ _RetvalT = TypeVar("_RetvalT")
class HwInfoSubmanager(BaseInfoSubmanager):
def __init__(
self,
+ platform_path: str,
vcgencmd_cmd: list[str],
ignore_past: bool,
state_poll: float,
) -> None:
+ self.__platform_path = platform_path
self.__vcgencmd_cmd = vcgencmd_cmd
self.__ignore_past = ignore_past
self.__state_poll = state_poll
@@ -60,12 +62,16 @@ class HwInfoSubmanager(BaseInfoSubmanager):
async def get_state(self) -> dict:
(
- model, serial, throttling,
- cpu_percent, cpu_temp,
+ base, serial,
+ (model, video, board),
+ throttling,
+ cpu_percent,
+ cpu_temp,
(mem_percent, mem_total, mem_available),
) = await asyncio.gather(
self.__read_dt_file("model"),
self.__read_dt_file("serial-number"),
+ self.__read_platform_file(),
self.__get_throttling(),
self.__get_cpu_percent(),
self.__get_cpu_temp(),
@@ -74,8 +80,11 @@ class HwInfoSubmanager(BaseInfoSubmanager):
return {
"platform": {
"type": "rpi",
- "base": model,
+ "base": base,
"serial": serial,
+ "model": model,
+ "video": video,
+ "board": board,
},
"health": {
"temp": {
@@ -114,6 +123,20 @@ class HwInfoSubmanager(BaseInfoSubmanager):
return None
return self.__dt_cache[name]
+ async def __read_platform_file(self) -> tuple[(str | None), (str | None), (str | None)]:
+ try:
+ text = await aiotools.read_file(self.__platform_path)
+ parsed: dict[str, str] = {}
+ for row in text.split("\n"):
+ row = row.strip()
+ if row:
+ (key, value) = row.split("=", 1)
+ parsed[key.strip()] = value.strip()
+ return (parsed["PIKVM_MODEL"], parsed["PIKVM_VIDEO"], parsed["PIKVM_BOARD"])
+ except Exception:
+ get_logger(0).exception("Can't read device model")
+ return (None, None, None)
+
async def __get_cpu_temp(self) -> (float | None):
temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp"
try: