host.power

Pluggable power control strategy for hosts.

Powering a host on or off cannot run on the host — it’s off. A PowerController embodies where control happens: it runs commands on a designated controller host (a hypervisor, a jump host with ipmitool, a PDU controller) resolved via the target’s lab back-reference, or talks to an external API. otto ships CommandPowerController (the generic command-based backend); projects register richer ones (IPMI/redfish/libvirt/ cloud/PDU) via register_power_controller(), the same extension hook otto.host.binary_loader.register_binary_loader() uses.

class otto.host.power.PowerState(value)

Bases: Enum

A host’s power state as reported by a controller.

ON = 'on'
OFF = 'off'
class otto.host.power.PowerController

Bases: ABC

How to power a host on/off from somewhere the host can be reached.

type_name : ClassVar[str]

Lab-data string for this controller (e.g. 'command').

abstract async on(host: Host) tuple[Status, str]

Power host on.

abstract async off(host: Host) tuple[Status, str]

Power host off.

async cycle(host: Host) tuple[Status, str]

Power-cycle host: off, then on. Override for a native reset.

async status(host: Host) PowerState | None

Return the current power state, or None when this controller can’t report it.

class otto.host.power.CommandPowerController(on_cmd: str, off_cmd: str, status_cmd: str | None = None, status_on: str = '', controller: str | None = None)

Bases: PowerController

Generic controller that runs configured commands on a controller host.

Commands are str.format-templated with the target host’s name/ip/ id. controller names the lab host the commands run on (via its oneshot); None runs them on the local otto machine.

type_name : ClassVar[str] = 'command'

Lab-data string for this controller (e.g. 'command').

on_cmd : str
off_cmd : str
status_cmd : str | None
status_on : str
controller : str | None
async on(host: Host) tuple[Status, str]

Power host on.

async off(host: Host) tuple[Status, str]

Power host off.

async status(host: Host) PowerState | None

Return the current power state, or None when this controller can’t report it.

otto.host.power.register_power_controller(type_name: str, cls: type[PowerController]) None

Register a PowerController subclass for lab-data selection.

otto.host.power.build_power_controller(type_name: str) type[PowerController]

Return the PowerController class registered under type_name.

otto.host.power.power_control_from_spec(value: Any) PowerController | None

Coerce a lab-data value into a PowerController instance.

Accepts None / an existing instance (pass-through), a str (a config-free controller type name), or a dict with a type key plus the controller’s constructor kwargs.