feat: add scripts for k3s cluster upgrade and health checks via AWX and SSH
This commit is contained in:
45
scripts/run_aerodrome_precheck.py
Normal file
45
scripts/run_aerodrome_precheck.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import paramiko, time
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
||||
|
||||
py_code = """
|
||||
from awx.main.models import Project, JobTemplate, Job
|
||||
import time
|
||||
|
||||
p = Project.objects.get(name='Snarfnet Infrastructure Playbooks')
|
||||
update = p.update()
|
||||
for _ in range(15):
|
||||
update.refresh_from_db()
|
||||
if update.status in ['successful', 'failed', 'error']:
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
print(f"Project update [{update.id}]: {update.status}")
|
||||
|
||||
jt = JobTemplate.objects.get(name='Aerodrome K3s Pre-Upgrade Check')
|
||||
job = jt.create_unified_job()
|
||||
job.signal_start()
|
||||
print(f"Launched Job [{job.id}] for '{jt.name}': Status={job.status}")
|
||||
|
||||
for _ in range(30):
|
||||
job.refresh_from_db()
|
||||
if job.status in ['successful', 'failed', 'error', 'canceled']:
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
print(f"Job [{job.id}] finished with Status={job.status}, Elapsed={job.elapsed}s, Failed={job.failed}")
|
||||
|
||||
print('\\n=== PLAY RECAP ===')
|
||||
for e in job.job_events.filter(event='playbook_on_stats'):
|
||||
print(e.stdout)
|
||||
"""
|
||||
|
||||
cmd = f"kubectl exec -i -n awx -c awx-task deployment/awx-task -- awx-manage shell_plus --quiet << 'EOF'\n{py_code}\nEOF"
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
|
||||
for line in iter(stdout.readline, ""):
|
||||
print(line, end="")
|
||||
|
||||
ssh.close()
|
||||
Reference in New Issue
Block a user