refs #1160 #1159 adds ogboot update and ogboot update bootfile. Changes installer to conserve the tmp directory where is cloned ipxe repo

ogboot-log
Luis Gerardo Romero Garcia 2024-12-03 08:32:32 +01:00
parent 62778c923b
commit 61b64dea9e
3 changed files with 263 additions and 35 deletions

View File

@ -531,50 +531,47 @@ def tzConfigure():
file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ}\"\n")
def install_ipxe():
if os.path.exists (f"{INSTALL_OGBOOT_TARGET}/tftpboot/undionly.kpxe"):
logger.info ('iPXE already present--not compiling again')
clone_dir = "/tmp/ipxe_repo"
if os.path.exists(f"{INSTALL_OGBOOT_TARGET}/tftpboot/undionly.kpxe"):
logger.info('iPXE already present--not compiling again')
return True
cwd = os.getcwd()
with tempfile.TemporaryDirectory() as clone_dir:
logger.info(f"Clonando el repositorio {ipxe_repo_url}")
if not os.path.exists(clone_dir):
os.makedirs(clone_dir)
logger.info(f"Cloning the repository {ipxe_repo_url}")
if subprocess.call(["git", "-c", "http.sslVerify=false", "clone", ipxe_repo_url, clone_dir]) == 0:
logger.info("Repositorio clonado correctamente.")
logger.info("Repository cloned successfully.")
else:
logger.error(f"ERROR\tNo se pudo clonar el repositorio {ipxe_repo_url}.")
logger.error(f"ERROR: Could not clone the repository {ipxe_repo_url}.")
return False
else:
logger.info(f"Repository already exists at {clone_dir}")
cwd = os.getcwd()
os.chdir(f"{clone_dir}/src")
# Ejecutar el comando make en el directorio src
#logger.info(f"Ejecutando make en {clone_dir}/src")
os.chdir(f"{clone_dir}/src")
#if subprocess.run(["make", "-s", "-j", "4"], capture_output=True).returncode == 0:
# logger.info(f"Directorio {clone_dir}/src correctamente compilado.")
#else:
# logger.error(f"ERROR\tNo se pudo compilar el directorio {clone_dir}/src.")
# return False
logger.info("Generating make of undionly.kpxe:")
if subprocess.run(["make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Boot file mounted correctly.")
else:
logger.error("Failed to mount boot file.")
return False
logger.info("Copying undionly.kpxe with user opengnsys:")
subprocess.call(["cp", "bin/undionly.kpxe", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
logger.info("Generando make de undionly.kpxe:")
if subprocess.run(["make", "-s", "bin/undionly.kpxe", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Boot file mounted correctly.")
else:
logger.error("Failed to mount boot file.")
return False
logger.info("Copiando undionly.kpxe con usuario opengnsys:")
subprocess.call(["cp", "bin/undionly.kpxe", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
logger.info("Generating make of ipxe.efi:")
if subprocess.run(["make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Properly constructed EFI file.")
else:
logger.error("Could not build EFI file.")
return False
subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
subprocess.call(["cp", f"{REPO_DIR}/tftpboot/grub.exe", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates", exist_ok=True)
subprocess.call(["cp", "-r", f"{REPO_DIR}/tftpboot/ipxe_scripts/templates/.", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.run(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
subprocess.call(["chown", "-R", "opengnsys:opengnsys", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
logger.info("Generando make de ipxe.efi:")
if subprocess.run(["make", "-s", "bin-x86_64-efi/ipxe.efi", f"EMBED={INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"], capture_output=True).returncode == 0:
logger.info("Properly constructed EFI file.")
else:
logger.error("Could not build EFI file.")
return False
subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OGBOOT_TARGET}/tftpboot"])
subprocess.call(["cp", f"{REPO_DIR}/tftpboot/grub.exe", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates", exist_ok=True)
subprocess.call(["cp", "-r", f"{REPO_DIR}/tftpboot/ipxe_scripts/templates/.", f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/templates"])
subprocess.run(["chmod", "-R", "775", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
subprocess.call(["chown", "-R", "opengnsys:opengnsys", f"{INSTALL_OGBOOT_TARGET}/tftpboot/"])
os.chdir(cwd)
return True

View File

@ -0,0 +1,120 @@
import os
import json
import subprocess
import shutil
import logging
# Configuración básica del logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Cargar configuración desde config.json
PROGRAM_DIR = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(PROGRAM_DIR, 'config.json')
with open(config_file, 'r') as f:
config = json.load(f)
# Extraer parámetros de configuración
ogcore_ip_port = config['ogCore_ServerIP']
if ':' in ogcore_ip_port:
OGCORE_IP, OGCORE_PORT = ogcore_ip_port.split(':')
else:
OGCORE_IP = ogcore_ip_port
OGCORE_PORT = "8443"
ogboot_ip_port = config['ogBoot_ServerIP']
if ':' in ogboot_ip_port:
OGBOOT_IP, OGBOOT_PORT = ogboot_ip_port.split(':')
else:
OGBOOT_IP = ogboot_ip_port
OGBOOT_PORT = "8082"
oglive_iso_url = config["ogLive_Default"]
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
OPENGNSYS_CLIENT_USER = config["ogBootSambaUser"]
OPENGNSYS_CLIENT_PASSWD = config["ogBootSambaPass"]
def og_boot_copy_files():
"""
Copia los archivos necesarios al punto de montaje de ogBoot.
Preserva el directorio client/images si existe.
"""
# repo_dir = os.path.join(PROGRAM_DIR)
repo_dir = os.path.dirname(PROGRAM_DIR) # Ruta al directorio ogboot
directories = {
"bin": os.path.join(repo_dir, "bin"),
"src": os.path.join(repo_dir, "src"),
"config": os.path.join(repo_dir, "config"),
"lib": os.path.join(repo_dir, "lib"),
"client": os.path.join(repo_dir, "client"),
}
for key, source in directories.items():
dest = os.path.join(INSTALL_OGBOOT_TARGET, key)
if key == "client":
# Preservar el directorio client/images si existe
images_dir = os.path.join(dest, "images")
if os.path.exists(images_dir):
temp_images_dir = os.path.join("/tmp", "ogboot_client_images")
logger.info(f"Preservando el directorio {images_dir} temporalmente en {temp_images_dir}.")
shutil.move(images_dir, temp_images_dir)
# Reemplazar todo el directorio client
if os.path.exists(dest):
shutil.rmtree(dest)
shutil.copytree(source, dest)
# Restaurar el directorio images
if os.path.exists(temp_images_dir):
os.makedirs(dest, exist_ok=True)
shutil.move(temp_images_dir, os.path.join(dest, "images"))
logger.info(f"Directorio images restaurado en {dest}.")
else:
# Reemplazar otros directorios
if os.path.exists(dest):
shutil.rmtree(dest)
shutil.copytree(source, dest)
logger.info(f"Copiado {key} desde {source} a {dest}.")
# Crear directorios adicionales si no existen
additional_dirs = ["etc", "public"]
for dir_name in additional_dirs:
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, dir_name), mode=0o775, exist_ok=True)
subprocess.run(["chmod", "-R", "775", INSTALL_OGBOOT_TARGET])
subprocess.run(["chown", "-R", "opengnsys:opengnsys", INSTALL_OGBOOT_TARGET])
logger.info("Archivos copiados y permisos ajustados correctamente.")
def og_boot_composer_install():
"""
Ejecuta Composer para instalar y actualizar las dependencias.
"""
result = subprocess.run(
["sudo", "-u", "opengnsys", "composer", "install", "--no-interaction", "--working-dir", INSTALL_OGBOOT_TARGET]
)
if result.returncode != 0:
logger.error("Error creando el proyecto Symfony usando Composer.")
return False
result = subprocess.run(
["sudo", "-u", "opengnsys", f"{INSTALL_OGBOOT_TARGET}/bin/composer.phar", "update", "doctrine/dbal",
"--working-dir", INSTALL_OGBOOT_TARGET]
)
if result.returncode != 0:
logger.error("Error actualizando el paquete doctrine/dbal usando Composer.")
return False
subprocess.call(["chown", "-R", "opengnsys:opengnsys", f"{INSTALL_OGBOOT_TARGET}/public"])
logger.info("Composer ejecutado correctamente y permisos ajustados.")
return True
if __name__ == "__main__":
try:
og_boot_copy_files()
if not og_boot_composer_install():
raise Exception("Error en la ejecución de Composer.")
logger.info("Actualización de ogBoot completada correctamente.")
except Exception as e:
logger.error(f"ERROR\tFallo crítico: {e}")

View File

@ -0,0 +1,111 @@
import os
import json
import subprocess
import tempfile
import logging
# Configuración básica del logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Cargar configuración desde config.json
PROGRAM_DIR = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(PROGRAM_DIR, 'config.json')
with open(config_file, 'r') as f:
config = json.load(f)
# Extraer parámetros de configuración
ogcore_ip_port = config['ogCore_ServerIP']
if ':' in ogcore_ip_port:
OGCORE_IP, OGCORE_PORT = ogcore_ip_port.split(':')
else:
OGCORE_IP = ogcore_ip_port
OGCORE_PORT = "8443"
ogboot_ip_port = config['ogBoot_ServerIP']
if ':' in ogboot_ip_port:
OGBOOT_IP, OGBOOT_PORT = ogboot_ip_port.split(':')
else:
OGBOOT_IP = ogboot_ip_port
OGBOOT_PORT = "8082"
oglive_iso_url = config["ogLive_Default"]
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
OPENGNSYS_CLIENT_USER = config["ogBootSambaUser"]
OPENGNSYS_CLIENT_PASSWD = config["ogBootSambaPass"]
def update_ipxe_boot_files():
"""
Actualiza los archivos de arranque iPXE.
"""
ipxe_repo_url = "https://github.com/ipxe/ipxe.git"
install_ogboot_target = INSTALL_OGBOOT_TARGET
cwd = os.getcwd()
clone_dir = "/tmp/ipxe_repo"
if not os.path.exists(clone_dir):
os.makedirs(clone_dir)
logger.info(f"Clonando el repositorio {ipxe_repo_url}")
clone_cmd = ["git", "-c", "http.sslVerify=false", "clone", ipxe_repo_url, clone_dir]
if subprocess.call(clone_cmd) == 0:
logger.info("Repositorio clonado correctamente.")
else:
logger.error(f"ERROR\tNo se pudo clonar el repositorio {ipxe_repo_url}.")
return False
else:
logger.info(f"Usando el repositorio clonado previamente en {clone_dir}")
os.chdir(f"{clone_dir}/src")
logger.info("Generando make de undionly.kpxe:")
undionly_cmd = [
"make", "-s", "bin/undionly.kpxe",
f"EMBED={install_ogboot_target}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
]
if subprocess.run(undionly_cmd, capture_output=True).returncode == 0:
logger.info("Boot file undionly.kpxe generado correctamente.")
else:
logger.error("ERROR\tNo se pudo generar el archivo undionly.kpxe.")
return False
logger.info("Copiando undionly.kpxe al directorio de destino:")
dest_undionly = os.path.join(install_ogboot_target, "tftpboot")
if subprocess.call(["cp", "bin/undionly.kpxe", dest_undionly]) == 0:
logger.info(f"Archivo undionly.kpxe copiado a {dest_undionly}")
else:
logger.error("ERROR\tNo se pudo copiar el archivo undionly.kpxe.")
return False
logger.info("Generando make de ipxe.efi:")
ipxe_efi_cmd = [
"make", "-s", "bin-x86_64-efi/ipxe.efi",
f"EMBED={install_ogboot_target}/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
]
if subprocess.run(ipxe_efi_cmd, capture_output=True).returncode == 0:
logger.info("Archivo ipxe.efi generado correctamente.")
else:
logger.error("ERROR\tNo se pudo generar el archivo ipxe.efi.")
return False
logger.info("Copiando ipxe.efi al directorio de destino:")
dest_ipxe_efi = os.path.join(install_ogboot_target, "tftpboot")
if subprocess.call(["cp", "bin-x86_64-efi/ipxe.efi", dest_ipxe_efi]) == 0:
logger.info(f"Archivo ipxe.efi copiado a {dest_ipxe_efi}")
else:
logger.error("ERROR\tNo se pudo copiar el archivo ipxe.efi.")
return False
os.chdir(cwd)
logger.info("Proceso completado exitosamente.")
return True
if __name__ == "__main__":
try:
if update_ipxe_boot_files():
logger.info("Archivos de arranque actualizados correctamente.")
else:
logger.error("Hubo un error durante la actualización de los archivos de arranque.")
except Exception as e:
logger.error(f"ERROR\tFallo crítico: {e}")