refs #797 changes output in get subnets
testing/og-dhcp-API/pipeline/head There was a failure building this commit Details

nginx_conf
Luis Gerardo Romero Garcia 2024-10-03 09:20:48 +02:00
parent 98319e3718
commit 16e1e41da5
1 changed files with 52 additions and 25 deletions

View File

@ -206,42 +206,69 @@ class DhcpController
* @OA\Response(
* response=200,
* description="Devuelve todas las subredes",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="success", type="string", example="Subredes obtenidas correctamente"),
* @OA\Property(property="message", type="array",
* @OA\Items(
* type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="subnet", type="string", example="192.168.1.0/24"),
* @OA\Property(property="pools", type="array",
* @OA\Items(
* type="object",
* @OA\Property(property="pool", type="string", example="192.168.1.10-192.168.1.100")
* )
* ),
* @OA\Property(property="reservations", type="array",
* @OA\Items(
* type="object",
* @OA\Property(property="ip-address", type="string", example="192.168.1.20"),
* @OA\Property(property="hw-address", type="string", example="00:0c:29:6b:5e:71")
* )
* )
* )
* )
* )
* ),
* @OA\Response(
* response=400,
* description="Error al obtener las subredes",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="error", type="string", example="Error al obtener las subredes")
* )
* )
* )
* @Route("/ogdhcp/v1/subnets", methods={"GET"})
*/
public function getSubnets(): JsonResponse
{
try {
$response = $this->curlKeaService->executeCurlCommand('config-get');
public function getSubnets(): JsonResponse
{
try {
$response = $this->curlKeaService->executeCurlCommand('config-get');
if (!$response) {
$responseError = 'Error: No se pudo acceder al archivo dhcpd.conf';
return new JsonResponse(['error' => $responseError], 400);
} else {
$result_code = $response[0]["result"];
if ($result_code == 0) {
if (!isset($response[0]['arguments']['Dhcp4']['subnet4'])) {
$responseError = 'El campo \'subnet4\' no está inicializado';
return new JsonResponse(['error' => $responseError], 400);
} else {
$arrayReservations = $response[0]['arguments']['Dhcp4']['subnet4'];
return new JsonResponse($arrayReservations, 200);
}
} else {
$responseError = "Error kea configuration invalid: " . $response[0]["text"];
return new JsonResponse(['error' => $responseError], 400);
}
}
} catch (Exception $e) {
$responseError = "Error al obtener la configuración de Kea DHCP: " . $e->getMessage();
return new JsonResponse(['error' => $responseError], 400);
if (!$response) {
return new JsonResponse(['error' => 'Error: No se pudo acceder al archivo de configuración de Kea'], 400);
}
$result_code = $response[0]["result"];
if ($result_code == 0) {
if (!isset($response[0]['arguments']['Dhcp4']['subnet4'])) {
return new JsonResponse(['error' => 'El campo "subnet4" no está inicializado'], 400);
} else {
$subnets = $response[0]['arguments']['Dhcp4']['subnet4'];
return new JsonResponse([
'success' => 'Subredes obtenidas correctamente',
'message' => $subnets
], 200);
}
} else {
return new JsonResponse(['error' => "Error en la configuración de Kea: " . $response[0]["text"]], 400);
}
} catch (Exception $e) {
return new JsonResponse(['error' => "Error al obtener la configuración de Kea DHCP: " . $e->getMessage()], 400);
}
}
/**
* @OA\Post(