Add scripts for managing VM and LXC container power states and fan control

- 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.
This commit is contained in:
2025-10-06 10:10:54 -04:00
parent 6fe5db1adc
commit 95f132bdf8
16 changed files with 227 additions and 45 deletions
@@ -0,0 +1,38 @@
#!/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()
@@ -0,0 +1,35 @@
#!/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="Login to iLO, show serverinfo and power on")
p.add_argument("-H", "--host", required=True, help="iLO host/IP")
p.add_argument("-a", "--action", default="On", choices=["On","Off","GracefulRestart","ForceOff","Reset"],
help="power/reboot action to run (default: On)")
p.add_argument("--no-serverinfo", action="store_true", help="skip running serverinfo")
args = p.parse_args()
ts_print(f"Sending {args.action} to {args.host}")
run(['ilorest', 'login', args.host, '-u', '<username>', '-p', '<password>'])
if not args.no_serverinfo:
run(['ilorest', 'serverinfo'])
run(['ilorest', 'reboot', args.action])
if __name__ == "__main__":
main()
@@ -0,0 +1,31 @@
#!/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()
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import argparse
import subprocess
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}")
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", "on",
]
print(f"Sending power on to {args.host}")
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()