95f132bdf8
- Implemented set_fanspeed.py for dynamic fan speed control based on temperature. - Created ilo_poweroff.py and ilo_poweron.py for iLO power management. - Added ipmi_poweroff.py and ipmi_poweron.py for IPMI power control. - Developed vm_start.py, vm_stop.py, vm_restart.py, and vm_shutdown.py for VM and LXC management. - Introduced wrapper scripts (start_wrapper.sh, stop_wrapper.sh) for simplified execution. - Removed deprecated shell scripts for power control.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import subprocess
|
|
import getpass
|
|
import sys
|
|
import datetime
|
|
|
|
def ts_print(msg):
|
|
"""ts_print message prefixed with a timestamp (YYYY-MM-DD HH:MM:SS)."""
|
|
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
print(f"{now} {msg}")
|
|
|
|
def run(cmd):
|
|
try:
|
|
subprocess.run(cmd, check=True)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Command failed: {' '.join(cmd)}", file=sys.stderr)
|
|
sys.exit(e.returncode)
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser(description="Run iLO REST commands (login, serverinfo, reboot)")
|
|
p.add_argument("-H", "--host", required=True, help="iLO host/IP")
|
|
p.add_argument("-a", "--action", default="ForceOff", choices=["ForceOff", "GracefulRestart", "Reset"],
|
|
help="reboot action to run (default: ForceOff)")
|
|
p.add_argument("--no-serverinfo", action="store_true", help="skip running serverinfo")
|
|
args = p.parse_args()
|
|
|
|
# login
|
|
ts_print(f"Sending {args.action} to {args.host}")
|
|
run(['ilorest', 'login', args.host, '-u', '<username>', '-p', '<password>'])
|
|
# optional serverinfo
|
|
if not args.no_serverinfo:
|
|
run(['ilorest', 'serverinfo'])
|
|
# power off / reboot action
|
|
run(['ilorest', 'reboot', args.action])
|
|
|
|
if __name__ == "__main__":
|
|
main()
|