From 43958efaa00ddf0ff4110da510545dd09869d206 Mon Sep 17 00:00:00 2001 From: "Caleb St. John" <30729806+yocalebo@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:55:19 -0500 Subject: [PATCH] NAS-133583 / 25.04 / Convert webui.main.dashboard.sys_info to new API (#15399) --- .../middlewared/api/v25_04_0/__init__.py | 1 + .../api/v25_04_0/webui_main_dashboard.py | 28 ++++++++++++++++ .../plugins/webui/main_dashboard.py | 33 +++++++++++-------- 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 src/middlewared/middlewared/api/v25_04_0/webui_main_dashboard.py diff --git a/src/middlewared/middlewared/api/v25_04_0/__init__.py b/src/middlewared/middlewared/api/v25_04_0/__init__.py index e153461eee28f..93cf624126217 100644 --- a/src/middlewared/middlewared/api/v25_04_0/__init__.py +++ b/src/middlewared/middlewared/api/v25_04_0/__init__.py @@ -67,3 +67,4 @@ from .vm import * # noqa from .vm_device import * # noqa from .webui_enclosure import * # noqa +from .webui_main_dashboard import * # noqa diff --git a/src/middlewared/middlewared/api/v25_04_0/webui_main_dashboard.py b/src/middlewared/middlewared/api/v25_04_0/webui_main_dashboard.py new file mode 100644 index 0000000000000..95c0f79af2b34 --- /dev/null +++ b/src/middlewared/middlewared/api/v25_04_0/webui_main_dashboard.py @@ -0,0 +1,28 @@ +from datetime import datetime + +from pydantic import Field + +from middlewared.api.base import BaseModel, NonEmptyString + + +class WebUIMainDashboardSysInfoArgs(BaseModel): + pass + + +class SysInfoEntry(BaseModel): + platform: NonEmptyString + version: NonEmptyString + codename: NonEmptyString + license: dict + system_serial: str + hostname: NonEmptyString + uptime_seconds: float + datetime_: datetime = Field(alias="datetime") + + +class SysInfo(SysInfoEntry): + remote_info: SysInfoEntry | None + + +class WebUIMainDashboardSysInfoResult(BaseModel): + result: SysInfo diff --git a/src/middlewared/middlewared/plugins/webui/main_dashboard.py b/src/middlewared/middlewared/plugins/webui/main_dashboard.py index 8c55f604ec6a4..27d9bd418107a 100644 --- a/src/middlewared/middlewared/plugins/webui/main_dashboard.py +++ b/src/middlewared/middlewared/plugins/webui/main_dashboard.py @@ -1,7 +1,11 @@ from datetime import datetime, timezone from time import clock_gettime, CLOCK_MONOTONIC_RAW, time -from middlewared.schema import accepts +from middlewared.api import api_method +from middlewared.api.current import ( + WebUIMainDashboardSysInfoArgs, + WebUIMainDashboardSysInfoResult +) from middlewared.service import Service from middlewared.utils import sw_version, sw_codename @@ -40,7 +44,11 @@ def sys_info_impl(self): 'datetime': datetime.fromtimestamp(time(), timezone.utc), } - @accepts(roles=['READONLY_ADMIN']) + @api_method( + WebUIMainDashboardSysInfoArgs, + WebUIMainDashboardSysInfoResult, + roles=['READONLY_ADMIN'] + ) def sys_info(self): """This endpoint was designed to be exclusively consumed by the webUI team. This is what makes @@ -48,15 +56,14 @@ def sys_info(self): dashboard after a user logs in. """ info = self.sys_info_impl() - try: - info['remote_info'] = self.middleware.call_sync( - 'failover.call_remote', 'webui.main.dashboard.sys_info_impl' - ) - except Exception: - # could be ENOMETHOD (fresh upgrade) or we could - # be on a non-HA system. Either way, doesn't matter - # we just need to try and get the information and - # set the key to None if we fail - info['remote_info'] = None - + info['remote'] = None + if self.middleware.call_sync('failover.licensed'): + try: + info['remote_info'] = self.middleware.call_sync( + 'failover.call_remote', 'webui.main.dashboard.sys_info_impl' + ) + except Exception: + # could be ENOMETHOD (fresh upgrade) or we could + # be on a non-HA system. Either way, doesn't matter + pass return info