Refs #202 modidys controller endpoints and add a bar to tftpboot dir
parent
7a5d2b2c7b
commit
c64ad8cb21
|
|
@ -43,7 +43,7 @@ PROG=$(basename "$(realpath "$0")") # Program name.
|
||||||
OPENGNSYS=/opt/ogboot # OpenGnsys main directory.
|
OPENGNSYS=/opt/ogboot # OpenGnsys main directory.
|
||||||
DOWNLOADDIR=$OPENGNSYS/lib # Directory to store ogLive images.
|
DOWNLOADDIR=$OPENGNSYS/lib # Directory to store ogLive images.
|
||||||
DOWNLOADURL="https://ognproject.evlt.uma.es/trac/downloads" # Download URL.
|
DOWNLOADURL="https://ognproject.evlt.uma.es/trac/downloads" # Download URL.
|
||||||
TFTPDIR=$OPENGNSYS/tftpboot # TFTP directory.
|
TFTPDIR=$OPENGNSYS/tftpboot/ # TFTP directory.
|
||||||
DEFOGLIVE="ogLive" # Default ogLive directory.
|
DEFOGLIVE="ogLive" # Default ogLive directory.
|
||||||
MINREL=20190601 # Mininum ogLive compatibility release.
|
MINREL=20190601 # Mininum ogLive compatibility release.
|
||||||
INFOFILE=$OPENGNSYS/etc/ogliveinfo.json # Configuration file.
|
INFOFILE=$OPENGNSYS/etc/ogliveinfo.json # Configuration file.
|
||||||
|
|
|
||||||
|
|
@ -68,13 +68,13 @@ Regenerar plantilla - PUT /ogboot/pxe-templates
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/ogboot/v1/config", name="getConfig", methods={"GET"})
|
* @Route("/ogboot/v1/status", name="getStatus", methods={"GET"})
|
||||||
* @OA\Get(
|
* @OA\Get(
|
||||||
* path="/ogboot/v1/config",
|
* path="/ogboot/v1/status",
|
||||||
* summary="Get ogboot configuration",
|
* summary="Get ogboot status",
|
||||||
* @OA\Response(
|
* @OA\Response(
|
||||||
* response=200,
|
* response=200,
|
||||||
* description="Configuration retrieved successfully",
|
* description="Status retrieved successfully",
|
||||||
* @OA\JsonContent(
|
* @OA\JsonContent(
|
||||||
* type="object",
|
* type="object",
|
||||||
* @OA\Property(property="disk_usage", type="object",
|
* @OA\Property(property="disk_usage", type="object",
|
||||||
|
|
@ -89,7 +89,7 @@ Regenerar plantilla - PUT /ogboot/pxe-templates
|
||||||
* )
|
* )
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function getConfig(): Response
|
public function getStatus(): Response
|
||||||
{
|
{
|
||||||
// Call oglivecli to get disk usage
|
// Call oglivecli to get disk usage
|
||||||
$diskUsageResult = $this->curlRequestService->callOgLive("disk_usage");
|
$diskUsageResult = $this->curlRequestService->callOgLive("disk_usage");
|
||||||
|
|
@ -124,43 +124,6 @@ public function getConfig(): Response
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route("/ogboot/v1/status", name="status", methods={"GET"})
|
|
||||||
* @OA\Get(
|
|
||||||
* path="/ogboot/v1/status",
|
|
||||||
* summary="Get ogboot status",
|
|
||||||
* @OA\Response(
|
|
||||||
* response=200,
|
|
||||||
* description="Successful operation",
|
|
||||||
* @OA\JsonContent(
|
|
||||||
* type="object",
|
|
||||||
* @OA\Property(
|
|
||||||
* property="message",
|
|
||||||
* type="string",
|
|
||||||
* description="Status message indicating any issues detected"
|
|
||||||
* )
|
|
||||||
* )
|
|
||||||
* ),
|
|
||||||
* @OA\Response(
|
|
||||||
* response=500,
|
|
||||||
* description="Failed to retrieve status"
|
|
||||||
* )
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
public function status(): Response
|
|
||||||
{
|
|
||||||
|
|
||||||
# $result = $this->curlRequestService->common_request(OG_REST_CMD_POWEROFF, POST, [OG_REST_PARAM_CLIENTS => $ips]);
|
|
||||||
$result = $this->curlRequestService->callOgLive("check");
|
|
||||||
|
|
||||||
if ($result) {
|
|
||||||
return new Response($result, Response::HTTP_OK);
|
|
||||||
} else {
|
|
||||||
return new Response('Failed', Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/ogboot/v1/oglives/isos", name="getDownloadMenu", methods={"GET"})
|
* @Route("/ogboot/v1/oglives/isos", name="getDownloadMenu", methods={"GET"})
|
||||||
* @OA\Get(
|
* @OA\Get(
|
||||||
|
|
@ -216,7 +179,7 @@ public function getDownloadMenu(): Response
|
||||||
* @OA\Property(
|
* @OA\Property(
|
||||||
* property="id",
|
* property="id",
|
||||||
* type="string",
|
* type="string",
|
||||||
* description="Unique identifier for the ogLive client, generated from linuxISO.sum",
|
* description="Unique identifier for the ogLive client, generated from ogclient.sqfs.sum",
|
||||||
* example="9e49a085ba74f97a81bdf9b3d0785094"
|
* example="9e49a085ba74f97a81bdf9b3d0785094"
|
||||||
* ),
|
* ),
|
||||||
* @OA\Property(
|
* @OA\Property(
|
||||||
|
|
@ -287,8 +250,8 @@ public function getOglives(): Response
|
||||||
$directory = $entry;
|
$directory = $entry;
|
||||||
$ogLivePath = $directoryPath . $entry;
|
$ogLivePath = $directoryPath . $entry;
|
||||||
|
|
||||||
// Obtener el ID del archivo linuxISO.sum
|
// Obtener el ID del archivo ogclient.sqfs.sum
|
||||||
$sumFile = $ogLivePath . '/linuxISO.sum';
|
$sumFile = $ogLivePath . '/ogclient.sqfs.sum';
|
||||||
$id = '';
|
$id = '';
|
||||||
if (file_exists($sumFile)) {
|
if (file_exists($sumFile)) {
|
||||||
$id = trim(file_get_contents($sumFile));
|
$id = trim(file_get_contents($sumFile));
|
||||||
|
|
@ -480,8 +443,8 @@ public function getOglive(string $checksum): Response
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/ogboot/v1/oglives/default", name="setOgliveDefault", methods={"POST"})
|
* @Route("/ogboot/v1/oglives/default", name="setOgliveDefault", methods={"PUT"})
|
||||||
* @OA\Post(
|
* @OA\Put(
|
||||||
* path="/ogboot/v1/oglives/default",
|
* path="/ogboot/v1/oglives/default",
|
||||||
* summary="Set default ogLive client",
|
* summary="Set default ogLive client",
|
||||||
* @OA\RequestBody(
|
* @OA\RequestBody(
|
||||||
|
|
@ -589,7 +552,7 @@ public function installOglive(Request $request): Response
|
||||||
}
|
}
|
||||||
|
|
||||||
$isoname = $data['isoname'];
|
$isoname = $data['isoname'];
|
||||||
$result = $this->curlRequestService->callOgLive("install " . escapeshellarg($isoname));
|
$result = $this->curlRequestService->callOgLive("download " . escapeshellarg($isoname));
|
||||||
|
|
||||||
if (is_array($result) && isset($result['success']) && $result['success'] === false) {
|
if (is_array($result) && isset($result['success']) && $result['success'] === false) {
|
||||||
return new JsonResponse(['error' => 'Failed to install ogLive client', 'details' => $result['error']], Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse(['error' => 'Failed to install ogLive client', 'details' => $result['error']], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
|
@ -1105,7 +1068,6 @@ public function getBootFile(string $mac): Response
|
||||||
|
|
||||||
return new Response($content, Response::HTTP_OK, ['Content-Type' => 'text/plain']);
|
return new Response($content, Response::HTTP_OK, ['Content-Type' => 'text/plain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/ogboot/v1/pxe-templates", methods={"POST"})
|
* @Route("/ogboot/v1/pxe-templates", methods={"POST"})
|
||||||
*
|
*
|
||||||
|
|
@ -1160,7 +1122,7 @@ public function getBootFile(string $mac): Response
|
||||||
try {
|
try {
|
||||||
file_put_contents($filePath, $contentTemplate);
|
file_put_contents($filePath, $contentTemplate);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return new Response('Ocurrió un error al crear la plantilla de arranque.', 500);
|
return new Response('Ocurrió un error al crear la plantilla de arranque. ' . $e->getMessage(), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(json_encode([
|
return new Response(json_encode([
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,6 @@ public function callOgLive($parameter)
|
||||||
{
|
{
|
||||||
$socketPath = '/var/run/oglive/oglive_daemon.sock';
|
$socketPath = '/var/run/oglive/oglive_daemon.sock';
|
||||||
|
|
||||||
// Registrar el parámetro recibido
|
|
||||||
file_put_contents('/tmp/serviceOglive.log', 'callOgLive called with parameter: ' . $parameter . PHP_EOL, FILE_APPEND);
|
file_put_contents('/tmp/serviceOglive.log', 'callOgLive called with parameter: ' . $parameter . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
|
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
|
@ -109,7 +108,6 @@ public function callOgLive($parameter)
|
||||||
|
|
||||||
socket_close($socket);
|
socket_close($socket);
|
||||||
|
|
||||||
// Registrar la respuesta en bruto
|
|
||||||
file_put_contents('/tmp/serviceOglive.log', 'Raw response: ' . $response . PHP_EOL, FILE_APPEND);
|
file_put_contents('/tmp/serviceOglive.log', 'Raw response: ' . $response . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
if (empty($response)) {
|
if (empty($response)) {
|
||||||
|
|
@ -123,7 +121,6 @@ public function callOgLive($parameter)
|
||||||
|
|
||||||
$decodedResponse = json_decode($response, true);
|
$decodedResponse = json_decode($response, true);
|
||||||
|
|
||||||
// Registrar cualquier error de decodificación JSON
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
$error = 'Error al decodificar JSON: ' . json_last_error_msg();
|
$error = 'Error al decodificar JSON: ' . json_last_error_msg();
|
||||||
file_put_contents('/tmp/serviceOglive.log', 'JSON decode error: ' . $error . PHP_EOL, FILE_APPEND);
|
file_put_contents('/tmp/serviceOglive.log', 'JSON decode error: ' . $error . PHP_EOL, FILE_APPEND);
|
||||||
|
|
@ -134,7 +131,6 @@ public function callOgLive($parameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($decodedResponse['success']) && $decodedResponse['success']) {
|
if (isset($decodedResponse['success']) && $decodedResponse['success']) {
|
||||||
// Registrar la respuesta decodificada
|
|
||||||
file_put_contents('/tmp/serviceOglive.log', 'Decoded successful response: ' . json_encode($decodedResponse['output']) . PHP_EOL, FILE_APPEND);
|
file_put_contents('/tmp/serviceOglive.log', 'Decoded successful response: ' . json_encode($decodedResponse['output']) . PHP_EOL, FILE_APPEND);
|
||||||
return $decodedResponse['output'];
|
return $decodedResponse['output'];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue