#!/usr/bin/env python3
import argparse
import subprocess
import sys

IPMIUSER = "<username>"
IPMIPW = "<password>"
IPMIEK = "0000000000000000000000000000000000000000"

def main():
    p = argparse.ArgumentParser(description="Send IPMI power off")
    p.add_argument("-H", "--host", required=True, help="IPMI host address")
    args = p.parse_args()

    cmd = [
        "ipmitool",
        "-I", "lanplus",
        "-H", args.host,
        "-U", IPMIUSER,
        "-P", IPMIPW,
        "-y", IPMIEK,
        "power", "off",
    ]
    proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    if proc.returncode != 0:
        print("ipmitool failed:", proc.stderr.strip(), file=sys.stderr)
        sys.exit(proc.returncode)
    print(proc.stdout.strip())

if __name__ == "__main__":
    main()
