Add healthy and supported to API (#1889)

* Add healthy and supported to API

* fix protected attributes
This commit is contained in:
Pascal Vizeli 2020-08-11 16:00:51 +02:00 committed by GitHub
parent 495f9f2373
commit 71ccaa2bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 20 deletions

3
API.md
View File

@ -42,6 +42,8 @@ The addons from `addons` are only installed one.
"arch": "armhf|aarch64|i386|amd64", "arch": "armhf|aarch64|i386|amd64",
"channel": "stable|beta|dev", "channel": "stable|beta|dev",
"timezone": "TIMEZONE", "timezone": "TIMEZONE",
"healthy": "bool",
"supported": "bool",
"logging": "debug|info|warning|error|critical", "logging": "debug|info|warning|error|critical",
"ip_address": "ip address", "ip_address": "ip address",
"wait_boot": "int", "wait_boot": "int",
@ -798,6 +800,7 @@ return:
"machine": "type", "machine": "type",
"arch": "arch", "arch": "arch",
"supported_arch": ["arch1", "arch2"], "supported_arch": ["arch1", "arch2"],
"supported": "bool",
"channel": "stable|beta|dev", "channel": "stable|beta|dev",
"logging": "debug|info|warning|error|critical", "logging": "debug|info|warning|error|critical",
"timezone": "Europe/Zurich" "timezone": "Europe/Zurich"

View File

@ -14,6 +14,7 @@ from ..const import (
ATTR_LOGGING, ATTR_LOGGING,
ATTR_MACHINE, ATTR_MACHINE,
ATTR_SUPERVISOR, ATTR_SUPERVISOR,
ATTR_SUPPORTED,
ATTR_SUPPORTED_ARCH, ATTR_SUPPORTED_ARCH,
ATTR_TIMEZONE, ATTR_TIMEZONE,
) )
@ -38,6 +39,7 @@ class APIInfo(CoreSysAttributes):
ATTR_MACHINE: self.sys_machine, ATTR_MACHINE: self.sys_machine,
ATTR_ARCH: self.sys_arch.default, ATTR_ARCH: self.sys_arch.default,
ATTR_SUPPORTED_ARCH: self.sys_arch.supported, ATTR_SUPPORTED_ARCH: self.sys_arch.supported,
ATTR_SUPPORTED: self.sys_supported,
ATTR_CHANNEL: self.sys_updater.channel, ATTR_CHANNEL: self.sys_updater.channel,
ATTR_LOGGING: self.sys_config.logging, ATTR_LOGGING: self.sys_config.logging,
ATTR_TIMEZONE: self.sys_timezone, ATTR_TIMEZONE: self.sys_timezone,

View File

@ -18,6 +18,7 @@ from ..const import (
ATTR_DEBUG_BLOCK, ATTR_DEBUG_BLOCK,
ATTR_DESCRIPTON, ATTR_DESCRIPTON,
ATTR_DIAGNOSTICS, ATTR_DIAGNOSTICS,
ATTR_HEALTHY,
ATTR_ICON, ATTR_ICON,
ATTR_INSTALLED, ATTR_INSTALLED,
ATTR_IP_ADDRESS, ATTR_IP_ADDRESS,
@ -32,6 +33,7 @@ from ..const import (
ATTR_REPOSITORY, ATTR_REPOSITORY,
ATTR_SLUG, ATTR_SLUG,
ATTR_STATE, ATTR_STATE,
ATTR_SUPPORTED,
ATTR_TIMEZONE, ATTR_TIMEZONE,
ATTR_VERSION, ATTR_VERSION,
ATTR_VERSION_LATEST, ATTR_VERSION_LATEST,
@ -98,6 +100,8 @@ class APISupervisor(CoreSysAttributes):
ATTR_VERSION_LATEST: self.sys_updater.version_supervisor, ATTR_VERSION_LATEST: self.sys_updater.version_supervisor,
ATTR_CHANNEL: self.sys_updater.channel, ATTR_CHANNEL: self.sys_updater.channel,
ATTR_ARCH: self.sys_supervisor.arch, 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_IP_ADDRESS: str(self.sys_supervisor.ip_address),
ATTR_WAIT_BOOT: self.sys_config.wait_boot, ATTR_WAIT_BOOT: self.sys_config.wait_boot,
ATTR_TIMEZONE: self.sys_config.timezone, ATTR_TIMEZONE: self.sys_config.timezone,

View File

@ -283,7 +283,7 @@ def setup_diagnostics(coresys: CoreSys) -> None:
def filter_data(event, hint): def filter_data(event, hint):
# Ignore issue if system is not supported or diagnostics is disabled # 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 return None
# Not full startup - missing information # Not full startup - missing information

View File

@ -243,6 +243,8 @@ ATTR_ACTIVE = "active"
ATTR_APPLICATION = "application" ATTR_APPLICATION = "application"
ATTR_INIT = "init" ATTR_INIT = "init"
ATTR_DIAGNOSTICS = "diagnostics" ATTR_DIAGNOSTICS = "diagnostics"
ATTR_HEALTHY = "healthy"
ATTR_SUPPORTED = "supported"
PROVIDE_SERVICE = "provide" PROVIDE_SERVICE = "provide"
NEED_SERVICE = "need" NEED_SERVICE = "need"

View File

@ -19,46 +19,44 @@ class Core(CoreSysAttributes):
"""Initialize Supervisor object.""" """Initialize Supervisor object."""
self.coresys: CoreSys = coresys self.coresys: CoreSys = coresys
self.state: CoreStates = CoreStates.INITIALIZE 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): async def connect(self):
"""Connect Supervisor container.""" """Connect Supervisor container."""
await self.sys_supervisor.load() await self.sys_supervisor.load()
# If a update is failed? # If host docker is supported?
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 not self.sys_docker.info.supported_version: if not self.sys_docker.info.supported_version:
self.healthy = False self.coresys.supported = False
_LOGGER.critical( _LOGGER.critical(
"Docker version %s is not supported by Supervisor!", "Docker version %s is not supported by Supervisor!",
self.sys_docker.info.version, self.sys_docker.info.version,
) )
elif self.sys_docker.info.inside_lxc: elif self.sys_docker.info.inside_lxc:
self.healthy = False self.coresys.supported = False
_LOGGER.critical( _LOGGER.critical(
"Detected Docker running inside LXC. Running Home Assistant with the Supervisor on LXC is not supported!" "Detected Docker running inside LXC. Running Home Assistant with the Supervisor on LXC is not supported!"
) )
self.sys_docker.info.check_requirements() self.sys_docker.info.check_requirements()
# Dbus available # Dbus available
if not SOCKET_DBUS.exists(): if not SOCKET_DBUS.exists():
self.healthy = False self.coresys.supported = False
_LOGGER.critical( _LOGGER.critical(
"DBus is required for Home Assistant. This system is not supported!" "DBus is required for Home Assistant. This system is not supported!"
) )
# Check if system is healthy # If a update is failed?
if not self.healthy: if self.sys_dev:
_LOGGER.critical( self.sys_config.version = self.sys_supervisor.version
"System running in a unhealthy state. Please update you OS or software!" elif self.sys_config.version != self.sys_supervisor.version:
) self._healthy = False
_LOGGER.critical("Update of Supervisor fails!")
async def setup(self): async def setup(self):
"""Start setting up supervisor orchestration.""" """Start setting up supervisor orchestration."""
@ -109,6 +107,12 @@ class Core(CoreSysAttributes):
# Load secrets # Load secrets
await self.sys_secrets.load() 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): async def start(self):
"""Start Supervisor orchestration.""" """Start Supervisor orchestration."""
self.state = CoreStates.STARTUP self.state = CoreStates.STARTUP

View File

@ -44,10 +44,13 @@ class CoreSys:
def __init__(self): def __init__(self):
"""Initialize coresys.""" """Initialize coresys."""
# Static attributes # Static attributes protected
self._machine_id: Optional[str] = None self._machine_id: Optional[str] = None
self._machine: Optional[str] = None self._machine: Optional[str] = None
# Static attributes
self.supported: bool = True
# External objects # External objects
self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop() self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop()
self._websession: aiohttp.ClientSession = aiohttp.ClientSession() self._websession: aiohttp.ClientSession = aiohttp.ClientSession()
@ -459,6 +462,11 @@ class CoreSysAttributes:
"""Return True if we run dev mode.""" """Return True if we run dev mode."""
return self.coresys.dev return self.coresys.dev
@property
def sys_supported(self) -> bool:
"""Return True if the system is supported."""
return self.coresys.supported
@property @property
def sys_timezone(self) -> str: def sys_timezone(self) -> str:
"""Return timezone.""" """Return timezone."""