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:
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/python3
|
||||
from subprocess import check_output, run
|
||||
from time import sleep
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def get_time():
|
||||
ts1 = str(datetime.now()).split('.')[0]
|
||||
return ts1
|
||||
|
||||
|
||||
def call_vm_shutdown(vmid):
|
||||
run(['/usr/sbin/qm', 'shutdown', vmid])
|
||||
|
||||
|
||||
def call_lxc_shutdown(lxc):
|
||||
run(['/usr/bin/lxc-stop', lxc])
|
||||
|
||||
|
||||
def get_status(vmid):
|
||||
vmstatus = check_output(['/usr/sbin/qm', 'shutdown', vmid])
|
||||
vmstatus = vmstatus.decode().split(': ')[1].rstrip()
|
||||
return vmstatus
|
||||
|
||||
|
||||
def monitor_status(vmid):
|
||||
vmstatus = 'running'
|
||||
while vmstatus == 'running':
|
||||
sleep(5)
|
||||
vmstatus = check_output(['/usr/sbin/qm', 'status', vmid])
|
||||
vmstatus = vmstatus.decode().split(': ')[1].rstrip()
|
||||
return 'Done'
|
||||
|
||||
|
||||
def lxc_status(lxc):
|
||||
vmstatus = 'running'
|
||||
while vmstatus.lower() == 'running':
|
||||
sleep(5)
|
||||
vmoutput = check_output(['lxc-info', lxc])
|
||||
if b'RUNNING' not in vmoutput:
|
||||
vmstatus = 'stopped'
|
||||
print(vmstatus)
|
||||
return 'Done'
|
||||
|
||||
|
||||
def shutdown_host():
|
||||
run(['/usr/sbin/init', '0'])
|
||||
|
||||
|
||||
def main():
|
||||
timestamp = get_time()
|
||||
print(f'Start time: {timestamp}')
|
||||
vms = ['115', '109', '108', '107', '101']
|
||||
for vm in vms:
|
||||
try:
|
||||
print(f'Shutting down {vm}')
|
||||
call_vm_shutdown(vm)
|
||||
vresult = monitor_status(vm)
|
||||
print(f'{vresult}')
|
||||
except Exception:
|
||||
print(f'{vm} currently not running')
|
||||
lxcs = [
|
||||
'121', '116', '114', '113', '111', '106',
|
||||
'103', '104', '105', '112', '100', '117',
|
||||
'118', '119', '110'
|
||||
]
|
||||
for lxc in lxcs:
|
||||
try:
|
||||
print(f'Shutting down {lxc}')
|
||||
call_lxc_shutdown(lxc)
|
||||
vresult = lxc_status(lxc)
|
||||
print(f'{vresult}')
|
||||
except Exception:
|
||||
print(f'{lxc} currently not running')
|
||||
timestamp = get_time()
|
||||
print(f'End time: {timestamp}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user