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

oglivecli-no-daemon
Luis Gerardo Romero Garcia 2024-10-18 13:29:30 +00:00
parent 8264459a6b
commit d34f1dd22e
4 changed files with 62 additions and 50 deletions

3
.env
View File

@ -15,8 +15,9 @@
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration # https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
APP_ENV=prod APP_ENV=dev
APP_SECRET=d423d1302b974417d415b10bcde25767 APP_SECRET=d423d1302b974417d415b10bcde25767
OGCORE_API_URL="https://172.17.8.90:8443"
###< symfony/framework-bundle ### ###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ### ###> doctrine/doctrine-bundle ###

View File

@ -10,6 +10,8 @@ services:
_defaults: _defaults:
autowire: true # Automatically injects dependencies in your services. autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. 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 # makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name # this creates a service per class whose id is the fully-qualified class name

View File

@ -15,10 +15,9 @@ class OgLiveInstallCommand extends Command
protected static $defaultName = 'oglive:install'; protected static $defaultName = 'oglive:install';
private $curlRequestService; private $curlRequestService;
private $httpClient; private $httpClient;
private $params;
private $logger; 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(); parent::__construct();
$this->curlRequestService = $curlRequestService; $this->curlRequestService = $curlRequestService;
@ -27,7 +26,6 @@ class OgLiveInstallCommand extends Command
'verify_peer' => false, // Ignorar la verificación del certificado SSL 'verify_peer' => false, // Ignorar la verificación del certificado SSL
'verify_host' => false, // Ignorar la verificación del nombre del host '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
} }
@ -94,9 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->logger->info('Installation completed with details', ['installResult' => $installResult]); $this->logger->info('Installation completed with details', ['installResult' => $installResult]);
$this->logger->info('Webhook data to be sent: ', ['webhookData' => $webhookData]); $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 // Log: enviando datos al webhook
$this->logger->info('Sending data to webhook', ['webhookUrl' => $webhookUrl, 'webhookData' => $webhookData]); $this->logger->info('Sending data to webhook', ['webhookUrl' => $webhookUrl, 'webhookData' => $webhookData]);

View File

@ -1163,7 +1163,6 @@ public function createBootFile(Request $request): JsonResponse
return new JsonResponse(['message' => 'El archivo de arranque se eliminó correctamente'], Response::HTTP_OK); return new JsonResponse(['message' => 'El archivo de arranque se eliminó correctamente'], Response::HTTP_OK);
} }
/** /**
* @Route("/ogboot/v1/pxe-templates", methods={"GET"}) * @Route("/ogboot/v1/pxe-templates", methods={"GET"})
* @OA\Get( * @OA\Get(
@ -1175,8 +1174,9 @@ public function createBootFile(Request $request): JsonResponse
* description="Lista de plantillas de arranque PXE", * description="Lista de plantillas de arranque PXE",
* @OA\JsonContent( * @OA\JsonContent(
* type="object", * type="object",
* @OA\Property(property="success", type="string", example="Lista de plantillas obtenida con éxito"),
* @OA\Property( * @OA\Property(
* property="templates", * property="message",
* type="array", * type="array",
* @OA\Items(type="string", example="mi_plantilla.ipxe") * @OA\Items(type="string", example="mi_plantilla.ipxe")
* ) * )
@ -1184,7 +1184,12 @@ public function createBootFile(Request $request): JsonResponse
* ), * ),
* @OA\Response( * @OA\Response(
* response=500, * response=500,
* description="Error interno del servidor" * 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")
* )
* ) * )
* ) * )
*/ */
@ -1194,7 +1199,10 @@ public function createBootFile(Request $request): JsonResponse
// Verificar si el directorio existe // Verificar si el directorio existe
if (!is_dir($templateDir)) { if (!is_dir($templateDir)) {
return new JsonResponse(['error' => 'Directorio de plantillas no encontrado'], Response::HTTP_INTERNAL_SERVER_ERROR); 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 // Obtener la lista de archivos en el directorio
@ -1205,7 +1213,11 @@ public function createBootFile(Request $request): JsonResponse
return !in_array($file, ['.', '..']) && !is_dir($templateDir . '/' . $file); return !in_array($file, ['.', '..']) && !is_dir($templateDir . '/' . $file);
}); });
return new JsonResponse(['templates' => array_values($templates)], Response::HTTP_OK); // Formatear la respuesta siguiendo el estándar
return new JsonResponse(
['success' => 'Lista de plantillas obtenida con éxito', 'message' => array_values($templates)],
Response::HTTP_OK
);
} }
/** /**