Merge pull request 'oglive-status-bug' (#7) from oglive-status-bug into main

Reviewed-on: #7
engine-branch
Luis Gerardo Romero Garcia 2025-02-25 07:40:26 +01:00
commit 2e374c310a
3 changed files with 35 additions and 16 deletions

View File

@ -139,6 +139,8 @@ function download() {
else else
local download_url="$1" local download_url="$1"
OGLIVEFILE=$(basename "$download_url") OGLIVEFILE=$(basename "$download_url")
local oglive_name="${OGLIVEFILE%.iso}" # Nombre del ogLive sin la extensión .iso
INSTALLED_PATH="$TFTPDIR/$oglive_name" # Ruta de instalación donde se verifica
# Validar que la URL apunte a un archivo ISO. # Validar que la URL apunte a un archivo ISO.
if [[ ! "$OGLIVEFILE" =~ \.iso$ ]]; then if [[ ! "$OGLIVEFILE" =~ \.iso$ ]]; then
@ -149,6 +151,11 @@ function download() {
SOURCELENGTH=$(curl -k --head --retry 5 --retry-delay 5 --max-time 30 "$download_url" | awk -F: '/Content-Length:/ {print $2}') SOURCELENGTH=$(curl -k --head --retry 5 --retry-delay 5 --max-time 30 "$download_url" | awk -F: '/Content-Length:/ {print $2}')
[ -n "$SOURCELENGTH" ] || raiseError download "No se pudo obtener el tamaño del archivo desde \"$download_url\"." [ -n "$SOURCELENGTH" ] || raiseError download "No se pudo obtener el tamaño del archivo desde \"$download_url\"."
# Verificar si el ogLive ya está instalado
if [ -d "$INSTALLED_PATH" ]; then
raiseError download "El ogLive \"$oglive_name\" ya está instalado en \"$INSTALLED_PATH\"."
fi
# Descargar ogLive. # Descargar ogLive.
TARGETFILE="$DOWNLOADDIR/$OGLIVEFILE" TARGETFILE="$DOWNLOADDIR/$OGLIVEFILE"
trap "rm -f $TARGETFILE" 1 2 3 6 9 15 trap "rm -f $TARGETFILE" 1 2 3 6 9 15

View File

@ -476,12 +476,19 @@ def copyClientFiles():
logger.error(f"Error while copying client structure") logger.error(f"Error while copying client structure")
errstatus = 1 errstatus = 1
logger.info(f"Copying OpenGnsys Cloning Engine files.") logger.info(f"Copying OpenGnsys Cloning Engine files in client library.")
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/client/lib/engine/bin", mode=0o775, exist_ok=True) os.makedirs(f"{INSTALL_OGBOOT_TARGET}/client/lib/engine/bin", mode=0o775, exist_ok=True)
if 0 != subprocess.run (['rsync', '-aH', f'{REPO_DIR}/client/engine/', f'{INSTALL_OGBOOT_TARGET}/client/lib/engine/bin/']).returncode: if 0 != subprocess.run (['rsync', '-aH', f'{REPO_DIR}/client/engine/', f'{INSTALL_OGBOOT_TARGET}/client/lib/engine/bin/']).returncode:
logger.error(f"Error while copying engine files") logger.error(f"Error while copying engine files")
errstatus = 1 errstatus = 1
logger.info(f"Copying OpenGnsys Cloning Engine files in client engine.")
os.makedirs(f"{INSTALL_OGBOOT_TARGET}/client/engine", mode=0o775, exist_ok=True)
if 0 != subprocess.run (['rsync', '-aH', f'{REPO_DIR}/client/engine/', f'{INSTALL_OGBOOT_TARGET}/client/engine/']).returncode:
logger.error(f"Error while copying engine files")
errstatus = 1
# Creación del archivo ogAdmClient.cfg # Creación del archivo ogAdmClient.cfg
try: try:
template_path = os.path.join(REPO_DIR, "etc/ogAdmClient.cfg.tmpl") template_path = os.path.join(REPO_DIR, "etc/ogAdmClient.cfg.tmpl")

View File

@ -140,11 +140,22 @@ public function getStatus(): Response
$ogLiveConfigResult = $ogLiveResponse['output']; $ogLiveConfigResult = $ogLiveResponse['output'];
$ogLiveExitCode = $ogLiveResponse['exitCode']; $ogLiveExitCode = $ogLiveResponse['exitCode'];
$defaultOglive = "";
$installedOglives = [];
$ogLiveError = null;
if ($ogLiveExitCode !== 0) { if ($ogLiveExitCode !== 0) {
return new JsonResponse( // Capturar el error, pero continuar la ejecución
['error' => 'FAILED_TO_RETRIEVE_OGLIVE_CONFIGURATION', 'details' => $ogLiveConfigResult['error'] ?? 'Unknown error'], $ogLiveError = [
Response::HTTP_INTERNAL_SERVER_ERROR 'error' => 'FAILED_TO_RETRIEVE_OGLIVE_CONFIGURATION',
); 'details' => $ogLiveConfigResult['error'] ?? 'Unknown error'
];
$defaultOglive = "";
$installedOglives = [];
} else {
// Extraer datos si el comando fue exitoso
$defaultOglive = $ogLiveConfigResult['default_oglive'] ?? "";
$installedOglives = $ogLiveConfigResult['installed_ogLives'] ?? [];
} }
// Llamar a oglivecli para obtener el estado de los servicios // Llamar a oglivecli para obtener el estado de los servicios
@ -159,17 +170,6 @@ public function getStatus(): Response
); );
} }
// Verificar si las claves 'default_oglive' e 'installed_ogLives' existen en la respuesta de oglivecli
$defaultOglive = $ogLiveConfigResult['default_oglive'] ?? null;
$installedOglives = $ogLiveConfigResult['installed_ogLives'] ?? [];
if ($defaultOglive === null || empty($installedOglives)) {
return new JsonResponse(
['error' => 'NOT_FOUND', 'message' => 'No default or installed ogLives found.'],
Response::HTTP_NOT_FOUND
);
}
$response = [ $response = [
'success' => 'Status retrieved successfully', 'success' => 'Status retrieved successfully',
'message' => [ 'message' => [
@ -180,6 +180,11 @@ public function getStatus(): Response
] ]
]; // Formatear la respuesta final con todos los datos ]; // Formatear la respuesta final con todos los datos
// Incluir el error de oglive si existe
if ($ogLiveError !== null) {
$response['message']['oglive_error'] = $ogLiveError;
}
return new JsonResponse($response, Response::HTTP_OK); return new JsonResponse($response, Response::HTTP_OK);
} }