From d34f1dd22e09287767b9741015b751046156276d Mon Sep 17 00:00:00 2001 From: lgromero Date: Fri, 18 Oct 2024 13:29:30 +0000 Subject: [PATCH] refs #875 #863 #949 #943 #969 Adds env variable ogcoreIp, changes command script to use the ogcoreIp, changes getTemplate to standardize output, adds pxe endpoint to format mac --- .env | 3 +- config/services.yaml | 2 + .../Command/OgLiveInstallCommand.php | 11 +-- .../Controller/OgBootController.php | 96 +++++++++++-------- 4 files changed, 62 insertions(+), 50 deletions(-) diff --git a/.env b/.env index 87b4f61..717fab4 100644 --- a/.env +++ b/.env @@ -15,8 +15,9 @@ # https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration ###> symfony/framework-bundle ### -APP_ENV=prod +APP_ENV=dev APP_SECRET=d423d1302b974417d415b10bcde25767 +OGCORE_API_URL="https://172.17.8.90:8443" ###< symfony/framework-bundle ### ###> doctrine/doctrine-bundle ### diff --git a/config/services.yaml b/config/services.yaml index 8c115cf..54cf407 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -10,6 +10,8 @@ services: _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + bind: + $ogCoreApiUrl: '%env(OGCORE_API_URL)%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/OgBootBundle/Command/OgLiveInstallCommand.php b/src/OgBootBundle/Command/OgLiveInstallCommand.php index 20ae2b7..29cda7b 100644 --- a/src/OgBootBundle/Command/OgLiveInstallCommand.php +++ b/src/OgBootBundle/Command/OgLiveInstallCommand.php @@ -15,10 +15,9 @@ class OgLiveInstallCommand extends Command protected static $defaultName = 'oglive:install'; private $curlRequestService; private $httpClient; - private $params; private $logger; - public function __construct(CurlRequestService $curlRequestService, HttpClientInterface $httpClient, ParameterBagInterface $params, LoggerInterface $logger) + public function __construct(CurlRequestService $curlRequestService, HttpClientInterface $httpClient, LoggerInterface $logger, protected readonly string $ogCoreApiUrl) { parent::__construct(); $this->curlRequestService = $curlRequestService; @@ -27,8 +26,7 @@ class OgLiveInstallCommand extends Command 'verify_peer' => false, // Ignorar la verificación del certificado SSL 'verify_host' => false, // Ignorar la verificación del nombre del host ]); - $this->params = $params; - $this->logger = $logger; // Añadimos el logger + $this->logger = $logger; // Añadimos el logger } protected function configure() @@ -94,9 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->logger->info('Installation completed with details', ['installResult' => $installResult]); $this->logger->info('Webhook data to be sent: ', ['webhookData' => $webhookData]); - // Obtener la URL del webhook desde el archivo .env - $webhookUrl = "https://172.17.8.90:8443/og-lives/install/webhook"; - + #$webhookUrl = "https://172.17.8.90:8443/og-lives/install/webhook"; + $webhookUrl = "{$this->ogCoreApiUrl}/og-lives/install/webhook"; // Log: enviando datos al webhook $this->logger->info('Sending data to webhook', ['webhookUrl' => $webhookUrl, 'webhookData' => $webhookData]); diff --git a/src/OgBootBundle/Controller/OgBootController.php b/src/OgBootBundle/Controller/OgBootController.php index 4d435fe..a635eb4 100644 --- a/src/OgBootBundle/Controller/OgBootController.php +++ b/src/OgBootBundle/Controller/OgBootController.php @@ -1163,51 +1163,63 @@ public function createBootFile(Request $request): JsonResponse return new JsonResponse(['message' => 'El archivo de arranque se eliminó correctamente'], Response::HTTP_OK); } +/** + * @Route("/ogboot/v1/pxe-templates", methods={"GET"}) + * @OA\Get( + * path="/ogboot/v1/pxe-templates", + * summary="Obtener todas las plantillas PXE", + * description="Obtiene una lista de todas las plantillas de arranque PXE disponibles.", + * @OA\Response( + * response=200, + * description="Lista de plantillas de arranque PXE", + * @OA\JsonContent( + * type="object", + * @OA\Property(property="success", type="string", example="Lista de plantillas obtenida con éxito"), + * @OA\Property( + * property="message", + * type="array", + * @OA\Items(type="string", example="mi_plantilla.ipxe") + * ) + * ) + * ), + * @OA\Response( + * response=500, + * description="Error interno del servidor", + * @OA\JsonContent( + * type="object", + * @OA\Property(property="error", type="string", example="SERVER_ERROR"), + * @OA\Property(property="message", type="string", example="Directorio de plantillas no encontrado") + * ) + * ) + * ) + */ +public function getAllTemplates(): JsonResponse +{ + $templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates'; - /** - * @Route("/ogboot/v1/pxe-templates", methods={"GET"}) - * @OA\Get( - * path="/ogboot/v1/pxe-templates", - * summary="Obtener todas las plantillas PXE", - * description="Obtiene una lista de todas las plantillas de arranque PXE disponibles.", - * @OA\Response( - * response=200, - * description="Lista de plantillas de arranque PXE", - * @OA\JsonContent( - * type="object", - * @OA\Property( - * property="templates", - * type="array", - * @OA\Items(type="string", example="mi_plantilla.ipxe") - * ) - * ) - * ), - * @OA\Response( - * response=500, - * description="Error interno del servidor" - * ) - * ) - */ - public function getAllTemplates(): JsonResponse - { - $templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates'; - - // Verificar si el directorio existe - if (!is_dir($templateDir)) { - return new JsonResponse(['error' => 'Directorio de plantillas no encontrado'], Response::HTTP_INTERNAL_SERVER_ERROR); - } - - // Obtener la lista de archivos en el directorio - $files = scandir($templateDir); - - // Filtrar los archivos válidos (excluir directorios y archivos ocultos) - $templates = array_filter($files, function ($file) use ($templateDir) { - return !in_array($file, ['.', '..']) && !is_dir($templateDir . '/' . $file); - }); - - return new JsonResponse(['templates' => array_values($templates)], Response::HTTP_OK); + // Verificar si el directorio existe + if (!is_dir($templateDir)) { + return new JsonResponse( + ['error' => 'SERVER_ERROR', 'message' => 'Directorio de plantillas no encontrado'], + Response::HTTP_INTERNAL_SERVER_ERROR + ); } + // Obtener la lista de archivos en el directorio + $files = scandir($templateDir); + + // Filtrar los archivos válidos (excluir directorios y archivos ocultos) + $templates = array_filter($files, function ($file) use ($templateDir) { + return !in_array($file, ['.', '..']) && !is_dir($templateDir . '/' . $file); + }); + + // Formatear la respuesta siguiendo el estándar + return new JsonResponse( + ['success' => 'Lista de plantillas obtenida con éxito', 'message' => array_values($templates)], + Response::HTTP_OK + ); +} + /** * @Route("/ogboot/v1/pxe-templates/{templateName}", name="get_template", methods={"GET"}) * @OA\Get(