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
local download_url="$1"
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.
if [[ ! "$OGLIVEFILE" =~ \.iso$ ]]; then
@ -148,6 +150,11 @@ function download() {
# Obtener el tamaño de descarga.
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\"."
# 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.
TARGETFILE="$DOWNLOADDIR/$OGLIVEFILE"

View File

@ -476,12 +476,19 @@ def copyClientFiles():
logger.error(f"Error while copying client structure")
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)
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")
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
try:
template_path = os.path.join(REPO_DIR, "etc/ogAdmClient.cfg.tmpl")

View File

@ -140,11 +140,22 @@ public function getStatus(): Response
$ogLiveConfigResult = $ogLiveResponse['output'];
$ogLiveExitCode = $ogLiveResponse['exitCode'];
$defaultOglive = "";
$installedOglives = [];
$ogLiveError = null;
if ($ogLiveExitCode !== 0) {
return new JsonResponse(
['error' => 'FAILED_TO_RETRIEVE_OGLIVE_CONFIGURATION', 'details' => $ogLiveConfigResult['error'] ?? 'Unknown error'],
Response::HTTP_INTERNAL_SERVER_ERROR
);
// Capturar el error, pero continuar la ejecución
$ogLiveError = [
'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
@ -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 = [
'success' => 'Status retrieved successfully',
'message' => [
@ -180,6 +180,11 @@ public function getStatus(): Response
]
]; // 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);
}