mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-04 07:46:31 +00:00

* Fix mypy issues in plugins * Fix mypy issues in resolution module * fix misses in resolution check * Fix signatures on evaluate methods * nitpick fix suggestions
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""Evaluation class for lxc."""
|
|
|
|
from contextlib import suppress
|
|
from pathlib import Path
|
|
|
|
from ...const import CoreState
|
|
from ...coresys import CoreSys
|
|
from ..const import UnsupportedReason
|
|
from .base import EvaluateBase
|
|
|
|
|
|
def setup(coresys: CoreSys) -> EvaluateBase:
|
|
"""Initialize evaluation-setup function."""
|
|
return EvaluateLxc(coresys)
|
|
|
|
|
|
class EvaluateLxc(EvaluateBase):
|
|
"""Evaluate if running inside LXC."""
|
|
|
|
@property
|
|
def reason(self) -> UnsupportedReason:
|
|
"""Return a UnsupportedReason enum."""
|
|
return UnsupportedReason.LXC
|
|
|
|
@property
|
|
def on_failure(self) -> str:
|
|
"""Return a string that is printed when self.evaluate is True."""
|
|
return "Detected Docker running inside LXC."
|
|
|
|
@property
|
|
def states(self) -> list[CoreState]:
|
|
"""Return a list of valid states when this evaluation can run."""
|
|
return [CoreState.INITIALIZE]
|
|
|
|
async def evaluate(self) -> bool:
|
|
"""Run evaluation."""
|
|
|
|
def check_lxc() -> bool:
|
|
with suppress(OSError):
|
|
if "container=lxc" in Path("/proc/1/environ").read_text(
|
|
encoding="utf-8"
|
|
):
|
|
return True
|
|
return Path("/dev/lxd/sock").exists()
|
|
|
|
return await self.sys_run_in_executor(check_lxc)
|