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,66 @@
|
||||
#!/usr/bin/python3
|
||||
import sys, ast
|
||||
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_startup(client_type, clientid):
|
||||
if client_type == 'vm':
|
||||
run(['/usr/sbin/qm', 'start', clientid])
|
||||
elif client_type == 'lxc':
|
||||
run(['/usr/bin/lxc-start', clientid])
|
||||
else:
|
||||
print('invalid client type or client id')
|
||||
|
||||
|
||||
def get_status(client_type, clientid, vmstatus, status_wanted):
|
||||
checker = None
|
||||
if client_type == 'lxc':
|
||||
checker = check_output(['lxc-info', clientid])
|
||||
elif client_type == 'vm':
|
||||
checker = check_output(['/usr/sbin/qm', 'status', clientid])
|
||||
while vmstatus != status_wanted:
|
||||
sleep(5)
|
||||
vmoutput = checker
|
||||
if (str.encode(status_wanted)) in vmoutput.upper():
|
||||
vmstatus = status_wanted
|
||||
return status_wanted
|
||||
|
||||
|
||||
def print_state(vmtype, vmhost, vmstatus):
|
||||
print(f'{vmtype} {vmhost} is {vmstatus}')
|
||||
|
||||
|
||||
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:
|
||||
try:
|
||||
print(f'Starting {clientid}')
|
||||
call_startup(client_type, clientid)
|
||||
vresult = get_status(client_type, clientid, 'STOPPED', 'RUNNING')
|
||||
except Exception as e:
|
||||
print(f'Unable to start container {clientid}: {e}')
|
||||
else:
|
||||
print_state(client_type.upper(), clientid, vresult)
|
||||
timestamp = get_time()
|
||||
print(f'End time: {timestamp}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user