Skip to main content

Remote power management for workstations and servers (iDRAC, iLO, AMT, SSH).

Project description

powerctl

Remote power management library for workstations and servers (iDRAC, iLO, AMT, SSH).

Project Overview

powerctl is a Python library designed to provide a unified interface for controlling the power state of various workstations and servers. It supports multiple protocols through a driver-based architecture, allowing for easy extension via drivers and concurrency via asyncio.

Supported protocols

Protocol ID Technology Notes
idrac Dell iDRAC (Redfish) iDRAC 8 / 9
ilo HP iLO (Redfish) iLO 4 / 5 / 6
amt Intel AMT (WS-Man) WS-Management SOAP over HTTP(S)
ssh_linux SSH Linux Uses asyncssh or ssh CLI
ssh_windows SSH / WinRM Windows PowerShell via SSH or WinRM

Quick start

Installation

pip install "powerctl[all]"           # everything (recommended)
pip install powerctl                  # core, no optional deps
pip install "powerctl[ssh]"           # + asyncssh for SSH drivers
pip install "powerctl[winrm]"         # + pywinrm for WinRM driver
import asyncio
from powerctl import PowerClient, Host, Credentials

host = Host(
    hostname="192.168.1.10",
    protocol="idrac",
    credentials=Credentials(username="root", password="calvin"),
)

async def main():
    async with PowerClient(host) as client:
        result = await client.reboot()
        print(result)  # <PowerResult action=reboot status=OK ...>

asyncio.run(main())

Per-protocol examples

Dell iDRAC

Host(
    hostname="192.168.1.10",
    protocol="idrac",
    credentials=Credentials(username="root", password="calvin"),
)

HP iLO

Host(
    hostname="192.168.1.20",
    protocol="ilo",
    credentials=Credentials(username="Administrator", password="hunter2"),
)

Intel AMT

Host(
    hostname="192.168.1.30",
    protocol="amt",
    credentials=Credentials(username="admin", password="AMTs3cret!"),
    extra={"tls": True},         # use port 16993 (HTTPS)
)

SSH Linux

Host(
    hostname="192.168.1.40",
    protocol="ssh_linux",
    credentials=Credentials(username="sysadmin", private_key_path="/home/me/.ssh/id_ed25519"),
    extra={"sudo": True},
)

SSH/WinRM Windows

# Via SSH (OpenSSH Server must be installed on Windows)
Host(
    hostname="192.168.1.50",
    protocol="ssh_windows",
    credentials=Credentials(username="Administrator", password="W1nd0ws!"),
    extra={"transport": "ssh"},
)

# Via WinRM (requires pip install powerctl[winrm])
Host(
    hostname="192.168.1.50",
    protocol="ssh_windows",
    credentials=Credentials(username="Administrator", password="W1nd0ws!"),
    extra={"transport": "winrm", "https": True},
)

Bulk operations

from powerctl import reboot_all, run_action_all, Host, Credentials

hosts = [
    Host(hostname=f"10.0.0.{i}", protocol="idrac",
         credentials=Credentials(username="root", password="calvin"))
    for i in range(1, 21)
]

async def main():
    results = await reboot_all(hosts, max_concurrent=5)
    for r in results:
        print(r)

Building and development setup

Setup

The project uses setuptools and pyproject.toml.

# Create a virtual environment
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip

# install build tool
pip install --upgrade build

# Install in editable mode with all dependencies
pip install -e ".[all,dev]"

Testing

Tests are located in the tests/ directory and use pytest with pytest-asyncio.

pytest

Linting and Type Checking

The project enforces strict typing and linting standards.

# Linting and formatting
ruff check .
ruff format .

# Type checking
python3 -m pip install types-requests
mypy src/powerctl

Building

python -m build

Writing a custom driver

from powerctl import register_driver, BaseDriver, PowerAction, PowerResult
from powerctl.core import Host

@register_driver
class IpmiDriver(BaseDriver):
    """Example IPMI driver using ipmitool CLI."""

    protocol = "ipmi"

    async def power_on(self) -> PowerResult:
        # call ipmitool here ...
        return PowerResult(PowerAction.POWER_ON, success=True)

    async def power_off(self) -> PowerResult: ...
    async def power_cycle(self) -> PowerResult: ...
    async def reboot(self) -> PowerResult: ...
    async def shutdown(self) -> PowerResult: ...

Once decorated with @register_driver, the driver is immediately available to PowerClient by its protocol string.

Running tests

pip install "powerctl[dev]"
pytest

Layout

powerctl/
├── __init__.py          # Public API surface
├── client.py            # PowerClient facade + bulk helpers
├── core/
│   ├── base.py          # BaseDriver ABC, PowerAction enum, PowerResult
│   ├── host.py          # Host & Credentials dataclasses
│   ├── registry.py      # @register_driver decorator + driver factory
│   └── exceptions.py    # Exception hierarchy
└── drivers/
    ├── _redfish.py      # Shared Redfish HTTP helpers
    ├── idrac.py         # Dell iDRAC
    ├── ilo.py           # HP iLO
    ├── amt.py           # Intel AMT
    ├── ssh_linux.py     # SSH Linux
    └── ssh_windows.py   # SSH / WinRM Windows

Notes:

  • Strategy + Registry pattern — drivers are registered by protocol string; build_driver(host) picks the right one at runtime.
  • Abstract Base ClassBaseDriver enforces the interface; mypy --strict will catch missing methods.
  • Zero mandatory dependencies — the stdlib covers iDRAC/iLO/AMT; SSH and WinRM libs are opt-in extras.
  • Async-first — all operations are async, enabling high-throughput bulk management with asyncio.gather.
  • Dataclasses for configHost and Credentials are frozen.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

powerctl-0.1.3.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powerctl-0.1.3-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file powerctl-0.1.3.tar.gz.

File metadata

  • Download URL: powerctl-0.1.3.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for powerctl-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c59bb00dbf24fcf9be380f79e59f6add859dea12fb5cacc149a1ab36b600d0bd
MD5 58f6b4d0fdf74d096210521678dd4a70
BLAKE2b-256 05bec01bf428f7bbc3ed81e86273dcf26cc1395e2425c5d3e1eef170601f88e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for powerctl-0.1.3.tar.gz:

Publisher: publish.yml on diegocortassa/powerctl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file powerctl-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: powerctl-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for powerctl-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5bf9d47e2210da4eadaf49bf546a911a45053ca5cf50853a620e840de395bf69
MD5 e58eda714e5b7c91dc6dbad9d63dea0e
BLAKE2b-256 b5989aa5edbd04ce6bd794cd3489e2a406de6e10528ba177f6725defb74fb5f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for powerctl-0.1.3-py3-none-any.whl:

Publisher: publish.yml on diegocortassa/powerctl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page