Files
utilities/personal/cron_scripts/system/vm_stop.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

51 lines
1.3 KiB
Python

#!/usr/bin/python3
import os, sys, ast, platform
import subprocess
from time import sleep
from datetime import datetime
def get_time():
ts1 = str(datetime.now()).split('.')[0]
return ts1
def client_shutdown(client_type, clientid):
lxc_filepath = "/usr/bin/lxc-stop"
qemu_filepath = "/usr/sbin/qm"
try:
print(f'Stopping {clientid}')
if client_type == 'vm':
process_id = os.spawnv(os.P_NOWAIT, qemu_filepath, ['shutdown', clientid])
elif client_type == 'lxc':
process_id = os.spawnv(os.P_NOWAIT, lxc_filepath, [client_type, clientid])
print(process_id)
except Exception as e:
print(f'Unable to stop container {clientid}: {e}')
def main():
client_type = None
client_list = None
try:
client_type = sys.argv[1]
client_list = ast.literal_eval(sys.argv[2])
except Exception as e:
print(f'Unable to process cli arguments. {e}')
else:
print(f'{client_type} {client_list}')
timestamp = get_time()
print(f'Start time: {timestamp}')
for clientid in client_list:
client_shutdown(client_type, clientid)
else:
print(f'Successfully stopped client list.')
timestamp = get_time()
print(f'End time: {timestamp}')
if __name__ == '__main__':
main()
# sys.exit(0)
# sys.exit(1)