Created
November 29, 2021 13:21
-
-
Save agraul/a31d9499997c4d06b516b6cb88adc097 to your computer and use it in GitHub Desktop.
Crude pre_flight_script.sh generation based on Uyuni DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import textwrap | |
from spacewalk.server import rhnSQL | |
if len(sys.argv) < 2: | |
print("Call like `python3 create_pre_flight.py $minion_id`") | |
sys.exit(1) | |
minion_id = sys.argv[1] | |
# Let's repeat our mantra 3 time: | |
# We love global state! | |
# We love global state! | |
# We love global state! | |
rhnSQL.initDB() | |
first_query = textwrap.dedent( | |
""" | |
SELECT s.name, s.os, s.release, a.name as arch | |
FROM rhnserver as s | |
INNER JOIN rhnserverarch as a | |
ON s.server_arch_id = a.id | |
""" | |
) | |
prepared_first_query = rhnSQL.prepare(first_query) | |
prepared_first_query.execute() | |
prepared_second_query = rhnSQL.prepare("SELECT * FROM minion_pillars(:id)") | |
prepared_second_query.execute(id=minion_id) | |
# let's try with one for now | |
row_first_query = prepared_first_query.fetchone_dict() | |
os_map = {"sles": "sle", "leap": "leap"} | |
os = os_map[row_first_query["os"].lower()] | |
if "." in row_first_query["release"]: | |
release = row_first_query["release"].replace(".", "/") | |
else: | |
release = f"{row_first_query['release']}/0" | |
arch = row_first_query["arch"].lower() | |
whole_pillar=prepared_second_query.fetchall_dict() | |
master="" | |
for pillar in whole_pillar: | |
if 'mgr_server' in pillar['pillar']: | |
master = pillar['pillar']['mgr_server'] | |
break | |
pre_flight_script = textwrap.dedent( | |
f""" | |
#!/bin/bash | |
MASTER={master} | |
BOOTSTRAP_REPO_URL=https://$MASTER/pub/repositories/{os}/{release}/bootstrap | |
VENV_FILE=venv-enabled-{arch}.txt | |
VENV_FILE_URL=$BOOTSTRAP_REPO_URL/$VENV_FILE | |
venv_package=$(curl $VENV_FILE_URL) | |
""" | |
) | |
print(f"Calculated pre_flight_script:\n{pre_flight_script}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment