Mike Degatano 0e8ace949a
Fix mypy issues in plugins and resolution (#5946)
* Fix mypy issues in plugins

* Fix mypy issues in resolution module

* fix misses in resolution check

* Fix signatures on evaluate methods

* nitpick fix suggestions
2025-06-16 14:12:47 -04:00

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)