From 71ccaa2bd0329fb52b036b809680ad693f376c3d Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 11 Aug 2020 16:00:51 +0200 Subject: [PATCH] Add healthy and supported to API (#1889) * Add healthy and supported to API * fix protected attributes --- API.md | 3 +++ supervisor/api/info.py | 2 ++ supervisor/api/supervisor.py | 4 ++++ supervisor/bootstrap.py | 2 +- supervisor/const.py | 2 ++ supervisor/core.py | 40 ++++++++++++++++++++---------------- supervisor/coresys.py | 10 ++++++++- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/API.md b/API.md index 316311af8..62abd50ab 100644 --- a/API.md +++ b/API.md @@ -42,6 +42,8 @@ The addons from `addons` are only installed one. "arch": "armhf|aarch64|i386|amd64", "channel": "stable|beta|dev", "timezone": "TIMEZONE", + "healthy": "bool", + "supported": "bool", "logging": "debug|info|warning|error|critical", "ip_address": "ip address", "wait_boot": "int", @@ -798,6 +800,7 @@ return: "machine": "type", "arch": "arch", "supported_arch": ["arch1", "arch2"], + "supported": "bool", "channel": "stable|beta|dev", "logging": "debug|info|warning|error|critical", "timezone": "Europe/Zurich" diff --git a/supervisor/api/info.py b/supervisor/api/info.py index f8d56aae8..6b25cf800 100644 --- a/supervisor/api/info.py +++ b/supervisor/api/info.py @@ -14,6 +14,7 @@ from ..const import ( ATTR_LOGGING, ATTR_MACHINE, ATTR_SUPERVISOR, + ATTR_SUPPORTED, ATTR_SUPPORTED_ARCH, ATTR_TIMEZONE, ) @@ -38,6 +39,7 @@ class APIInfo(CoreSysAttributes): ATTR_MACHINE: self.sys_machine, ATTR_ARCH: self.sys_arch.default, ATTR_SUPPORTED_ARCH: self.sys_arch.supported, + ATTR_SUPPORTED: self.sys_supported, ATTR_CHANNEL: self.sys_updater.channel, ATTR_LOGGING: self.sys_config.logging, ATTR_TIMEZONE: self.sys_timezone, diff --git a/supervisor/api/supervisor.py b/supervisor/api/supervisor.py index 68d2cca78..2b9a09728 100644 --- a/supervisor/api/supervisor.py +++ b/supervisor/api/supervisor.py @@ -18,6 +18,7 @@ from ..const import ( ATTR_DEBUG_BLOCK, ATTR_DESCRIPTON, ATTR_DIAGNOSTICS, + ATTR_HEALTHY, ATTR_ICON, ATTR_INSTALLED, ATTR_IP_ADDRESS, @@ -32,6 +33,7 @@ from ..const import ( ATTR_REPOSITORY, ATTR_SLUG, ATTR_STATE, + ATTR_SUPPORTED, ATTR_TIMEZONE, ATTR_VERSION, ATTR_VERSION_LATEST, @@ -98,6 +100,8 @@ class APISupervisor(CoreSysAttributes): ATTR_VERSION_LATEST: self.sys_updater.version_supervisor, ATTR_CHANNEL: self.sys_updater.channel, ATTR_ARCH: self.sys_supervisor.arch, + ATTR_SUPPORTED: self.sys_supported, + ATTR_HEALTHY: self.sys_core.healthy, ATTR_IP_ADDRESS: str(self.sys_supervisor.ip_address), ATTR_WAIT_BOOT: self.sys_config.wait_boot, ATTR_TIMEZONE: self.sys_config.timezone, diff --git a/supervisor/bootstrap.py b/supervisor/bootstrap.py index ec885a67d..5c4a36641 100644 --- a/supervisor/bootstrap.py +++ b/supervisor/bootstrap.py @@ -283,7 +283,7 @@ def setup_diagnostics(coresys: CoreSys) -> None: def filter_data(event, hint): # Ignore issue if system is not supported or diagnostics is disabled - if not coresys.config.diagnostics or not coresys.core.healthy: + if not coresys.config.diagnostics or not coresys.supported: return None # Not full startup - missing information diff --git a/supervisor/const.py b/supervisor/const.py index 9120ae795..d2df2f404 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -243,6 +243,8 @@ ATTR_ACTIVE = "active" ATTR_APPLICATION = "application" ATTR_INIT = "init" ATTR_DIAGNOSTICS = "diagnostics" +ATTR_HEALTHY = "healthy" +ATTR_SUPPORTED = "supported" PROVIDE_SERVICE = "provide" NEED_SERVICE = "need" diff --git a/supervisor/core.py b/supervisor/core.py index b9a824530..9cb2ee400 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -19,46 +19,44 @@ class Core(CoreSysAttributes): """Initialize Supervisor object.""" self.coresys: CoreSys = coresys self.state: CoreStates = CoreStates.INITIALIZE - self.healthy: bool = True + self._healthy: bool = True + + @property + def healthy(self) -> bool: + """Return True if system is healthy.""" + return self._healthy and self.sys_supported async def connect(self): """Connect Supervisor container.""" await self.sys_supervisor.load() - # If a update is failed? - if self.sys_dev: - self.sys_config.version = self.sys_supervisor.version - elif self.sys_config.version != self.sys_supervisor.version: - self.healthy = False - _LOGGER.critical("Update of Supervisor fails!") - - # If local docker is supported? + # If host docker is supported? if not self.sys_docker.info.supported_version: - self.healthy = False + self.coresys.supported = False _LOGGER.critical( "Docker version %s is not supported by Supervisor!", self.sys_docker.info.version, ) elif self.sys_docker.info.inside_lxc: - self.healthy = False + self.coresys.supported = False _LOGGER.critical( "Detected Docker running inside LXC. Running Home Assistant with the Supervisor on LXC is not supported!" ) - self.sys_docker.info.check_requirements() # Dbus available if not SOCKET_DBUS.exists(): - self.healthy = False + self.coresys.supported = False _LOGGER.critical( "DBus is required for Home Assistant. This system is not supported!" ) - # Check if system is healthy - if not self.healthy: - _LOGGER.critical( - "System running in a unhealthy state. Please update you OS or software!" - ) + # If a update is failed? + if self.sys_dev: + self.sys_config.version = self.sys_supervisor.version + elif self.sys_config.version != self.sys_supervisor.version: + self._healthy = False + _LOGGER.critical("Update of Supervisor fails!") async def setup(self): """Start setting up supervisor orchestration.""" @@ -109,6 +107,12 @@ class Core(CoreSysAttributes): # Load secrets await self.sys_secrets.load() + # Check if system is healthy + if not self.healthy: + _LOGGER.critical( + "System running in a unhealthy state. Please update you OS or software!" + ) + async def start(self): """Start Supervisor orchestration.""" self.state = CoreStates.STARTUP diff --git a/supervisor/coresys.py b/supervisor/coresys.py index 4aa26943d..ab10c2631 100644 --- a/supervisor/coresys.py +++ b/supervisor/coresys.py @@ -44,10 +44,13 @@ class CoreSys: def __init__(self): """Initialize coresys.""" - # Static attributes + # Static attributes protected self._machine_id: Optional[str] = None self._machine: Optional[str] = None + # Static attributes + self.supported: bool = True + # External objects self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop() self._websession: aiohttp.ClientSession = aiohttp.ClientSession() @@ -459,6 +462,11 @@ class CoreSysAttributes: """Return True if we run dev mode.""" return self.coresys.dev + @property + def sys_supported(self) -> bool: + """Return True if the system is supported.""" + return self.coresys.supported + @property def sys_timezone(self) -> str: """Return timezone."""