adding new scripts to start and stop clients as well as wrapper scripts to execute them

This commit is contained in:
2025-07-03 15:19:49 -04:00
parent 3d527d4712
commit 20839809b0
7 changed files with 202 additions and 70 deletions
+50
View File
@@ -0,0 +1,50 @@
#!/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)