Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133583 / 25.04 / Convert webui.main.dashboard.sys_info to new API #15399

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading