summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--PKGBUILD12
-rw-r--r--kvmd/apps/__init__.py1
-rw-r--r--kvmd/apps/kvmd/info/hw.py29
-rw-r--r--testenv/platform3
5 files changed, 40 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 68a630fb..74de6453 100644
--- a/Makefile
+++ b/Makefile
@@ -123,6 +123,7 @@ run: testenv $(TESTENV_GPIO)
&& cp -r /usr/share/kvmd/configs.default/nginx/* /etc/kvmd/nginx \
&& cp -a /testenv/.ssl/nginx /etc/kvmd/nginx/ssl \
&& cp -a /testenv/.ssl/vnc /etc/kvmd/vnc/ssl \
+ && cp /testenv/platform /usr/share/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.yaml /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*passwd /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.secret /etc/kvmd \
@@ -149,6 +150,7 @@ run-cfg: testenv
-it $(TESTENV_IMAGE) /bin/bash -c " \
cp -a /testenv/.ssl/nginx /etc/kvmd/nginx/ssl \
&& cp -a /testenv/.ssl/vnc /etc/kvmd/vnc/ssl \
+ && cp /testenv/platform /usr/share/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.yaml /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*passwd /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.secret /etc/kvmd \
@@ -171,6 +173,7 @@ run-ipmi: testenv
-it $(TESTENV_IMAGE) /bin/bash -c " \
cp -a /testenv/.ssl/nginx /etc/kvmd/nginx/ssl \
&& cp -a /testenv/.ssl/vnc /etc/kvmd/vnc/ssl \
+ && cp /testenv/platform /usr/share/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.yaml /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*passwd /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.secret /etc/kvmd \
@@ -193,6 +196,7 @@ run-vnc: testenv
-it $(TESTENV_IMAGE) /bin/bash -c " \
cp -a /testenv/.ssl/nginx /etc/kvmd/nginx/ssl \
&& cp -a /testenv/.ssl/vnc /etc/kvmd/vnc/ssl \
+ && cp /testenv/platform /usr/share/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.yaml /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*passwd /etc/kvmd \
&& cp /usr/share/kvmd/configs.default/kvmd/*.secret /etc/kvmd \
diff --git a/PKGBUILD b/PKGBUILD
index 4927140a..15c3b140 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -252,11 +252,11 @@ for _variant in "${_variants[@]}"; do
fi
mkdir -p \"\$pkgdir/usr/share/kvmd\"
- local _device=\"\$pkgdir/usr/share/kvmd/device\"
- rm -f \"\$_device\"
- echo PIKVM_BASE=$_base > \"\$_device\"
- echo PIKVM_VIDEO=$_video >> \"\$_device\"
- echo PIKVM_BOARD=$_board >> \"\$_device\"
- chmod 444 \"\$_device\"
+ local _platform=\"\$pkgdir/usr/share/kvmd/platform\"
+ rm -f \"\$_platform\"
+ echo PIKVM_MODEL=$_base > \"\$_platform\"
+ echo PIKVM_VIDEO=$_video >> \"\$_platform\"
+ echo PIKVM_BOARD=$_board >> \"\$_platform\"
+ chmod 444 \"\$_platform\"
}"
done
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:
diff --git a/testenv/platform b/testenv/platform
new file mode 100644
index 00000000..223c57de
--- /dev/null
+++ b/testenv/platform
@@ -0,0 +1,3 @@
+PIKVM_MODEL=test_model
+PIKVM_VIDEO=test_video
+PIKVM_BOARD=test_board