diff options
author | Maxim Devaev <[email protected]> | 2024-07-27 14:07:26 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2024-07-27 14:07:26 +0300 |
commit | 7e42d320076eec94adf1d42ecca361bd38275feb (patch) | |
tree | 201e3286a6a2fa879dbf574d1e2357946d7aac11 | |
parent | 6a665cd62fc317c62cb2486f701f4dc7ef2de29d (diff) |
pikvm/pikvm#1342: Verbose platform info in /api/info
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | PKGBUILD | 12 | ||||
-rw-r--r-- | kvmd/apps/__init__.py | 1 | ||||
-rw-r--r-- | kvmd/apps/kvmd/info/hw.py | 29 | ||||
-rw-r--r-- | testenv/platform | 3 |
5 files changed, 40 insertions, 9 deletions
@@ -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 \ @@ -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 |