Skip to content

Commit

Permalink
NAS-133583 / 25.04 / Convert webui.main.dashboard.sys_info to new API (
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo authored Jan 15, 2025
1 parent c079cf6 commit 43958ef
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/middlewared/middlewared/api/v25_04_0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@
from .vm import * # noqa
from .vm_device import * # noqa
from .webui_enclosure import * # noqa
from .webui_main_dashboard import * # noqa
28 changes: 28 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/webui_main_dashboard.py
Original file line number Diff line number Diff line change
@@ -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
33 changes: 20 additions & 13 deletions src/middlewared/middlewared/plugins/webui/main_dashboard.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -40,23 +44,26 @@ 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
up the System Information card on the main
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

0 comments on commit 43958ef

Please sign in to comment.