bmc_host_power.py 933 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python3
  2. """Minimal BMC host-only power check; never cycles BMC power."""
  3. import argparse
  4. import os
  5. import subprocess
  6. def main():
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument("--action", choices=("status", "off"), required=True)
  9. args = parser.parse_args()
  10. password = os.environ.get("STL_BMC_S1_PASSWORD", "")
  11. if not password:
  12. raise SystemExit("BMC password environment is not configured")
  13. env = {**os.environ, "IPMI_PASSWORD": password}
  14. command = ["ipmitool", "-I", "lanplus", "-C", "17", "-H", "192.168.0.100",
  15. "-U", "ADMIN", "-E", "chassis", "power", args.action]
  16. result = subprocess.run(command, env=env, text=True, capture_output=True, timeout=25, check=False)
  17. print(result.stdout.strip())
  18. if result.stderr.strip():
  19. print(result.stderr.strip())
  20. return result.returncode
  21. if __name__ == "__main__":
  22. raise SystemExit(main())