"""How the host is hardened: napalm-device-types' ``HardeningMixin`` (NetOrk/netork#2706). With it ``CpuMicrocodeMixin``, the one fix the reading leads to: the CPU vendor's microcode on a host that runs on its own CPU, over the driver's ``ensure_package``, apt transports and ``refresh_available_updates``. The command and its parse are napalm-device-types'; this is only how the command reaches the host. An exec channel, since ``aa-status --json`` prints one line longer than the PTY netmiko holds reliably takes. Read-only either way; root only for AppArmor's profiles, and the mixin falls back to the login user where it is refused. """ from __future__ import annotations from typing import TYPE_CHECKING from napalm_device_types import CommandResult, CpuMicrocodeMixin, HardeningMixin #: Seconds the reading may take: a handful of small files and two quick tools. _READ_TIMEOUT = 60 class LinuxHardeningMixin(HardeningMixin, CpuMicrocodeMixin): """The transport for ``get_hardening``, and ``install_cpu_microcode``.""" if TYPE_CHECKING: # pragma: no cover - the driver's own, declared for type checkers def run_command( self, command: str, *, privileged: bool = False, timeout: float = 60, stdin: bytes | None = None, ) -> CommandResult: ... def _run_hardening_command(self, command: str, *, privileged: bool) -> str: return self.run_command(command, privileged=privileged, timeout=_READ_TIMEOUT).stdout