Files
utilities/personal/cron_scripts/system/vm_powerup.py
T
wjones 95f132bdf8 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.
2025-10-06 10:10:54 -04:00

48 lines
1.0 KiB
Python

#!/usr/bin/python3
import os
import sys
import subprocess
from subprocess import check_output, run
import time
from time import sleep
import datetime
from datetime import datetime
def get_time():
ts1 = str(datetime.now()).split('.')[0]
return ts1
def call_powerup(vmid):
run(['/usr/sbin/qm','start',vmid])
def monitor_status(vmid):
vmstatus = 'stopped'
while vmstatus == 'stopped':
sleep(5)
vmstatus = check_output(['/usr/sbin/qm','status',vmid])
vmstatus = vmstatus.decode().split(': ')[1].rstrip()
return 'Done'
def main():
timestamp = get_time()
print(f'Start time: {timestamp}')
vms = ['105']
for vm in vms:
try:
print(f'starting up {vm}')
call_powerup(vm)
vresult = monitor_status(vm)
print(f'{vresult}')
except Exception as e:
print(f'{vm} currently not running')
timestamp = get_time()
print(f'End time: {timestamp}')
if __name__ == '__main__':
main()