refs #1205 adds gateway paremeter in subnet
testing/og-dhcp-API/pipeline/head There was a failure building this commit
Details
testing/og-dhcp-API/pipeline/head There was a failure building this commit
Details
parent
d58744c595
commit
27f8babdf7
|
|
@ -28,7 +28,6 @@ class DhcpController
|
||||||
$this->backup_dir = $params->get('backup_dir');
|
$this->backup_dir = $params->get('backup_dir');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/ogdhcp/v1/status", name="getDhcpStatus", methods={"GET"})
|
* @Route("/ogdhcp/v1/status", name="getDhcpStatus", methods={"GET"})
|
||||||
* @OA\Get(
|
* @OA\Get(
|
||||||
|
|
@ -300,7 +299,8 @@ public function getSubnets(): JsonResponse
|
||||||
* @OA\Property(property="mask", type="string", example="255.255.255.0"),
|
* @OA\Property(property="mask", type="string", example="255.255.255.0"),
|
||||||
* @OA\Property(property="address", type="string", example="192.168.1.0"),
|
* @OA\Property(property="address", type="string", example="192.168.1.0"),
|
||||||
* @OA\Property(property="nextServer", type="string", example="192.168.1.1"),
|
* @OA\Property(property="nextServer", type="string", example="192.168.1.1"),
|
||||||
* @OA\Property(property="bootFileName", type="string", example="pxelinux.0")
|
* @OA\Property(property="bootFileName", type="string", example="pxelinux.0"),
|
||||||
|
* @OA\Property(property="router", type="string", example="192.168.1.254")
|
||||||
* )
|
* )
|
||||||
* ),
|
* ),
|
||||||
* @OA\Response(
|
* @OA\Response(
|
||||||
|
|
@ -357,19 +357,21 @@ public function getSubnets(): JsonResponse
|
||||||
* )
|
* )
|
||||||
* @Route("/ogdhcp/v1/subnets", methods={"POST"})
|
* @Route("/ogdhcp/v1/subnets", methods={"POST"})
|
||||||
*/
|
*/
|
||||||
|
public function addDhcpSubnet(Request $request): JsonResponse
|
||||||
|
{
|
||||||
public function addDhcpSubnet(Request $request): JsonResponse
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
$input = json_decode($request->getContent());
|
$input = json_decode($request->getContent());
|
||||||
$subnetId = (int) htmlspecialchars($input->subnetId);
|
$subnetId = (int) htmlspecialchars($input->subnetId);
|
||||||
$mask = htmlspecialchars($input->mask);
|
$mask = htmlspecialchars($input->mask);
|
||||||
$address = htmlspecialchars($input->address);
|
$address = htmlspecialchars($input->address);
|
||||||
|
|
||||||
// Verificar si next-server y boot-file-name están presentes
|
// Verificar si next-server, boot-file-name y router están presentes
|
||||||
$nextServer = isset($input->nextServer) ? htmlspecialchars($input->nextServer) : null;
|
$nextServer = isset($input->nextServer) ? htmlspecialchars($input->nextServer) : null;
|
||||||
$bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null;
|
$bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null;
|
||||||
|
$router = isset($input->router) ? htmlspecialchars($input->router) : null;
|
||||||
|
|
||||||
|
// Calcular el gatewayIP si no se proporciona el router
|
||||||
|
$gatewayIP = $router ?: substr($address, 0, strrpos($address, '.')) . '.1';
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$response["message"] = $e->getMessage();
|
$response["message"] = $e->getMessage();
|
||||||
if (strpos($e->getMessage(), 'Undefined property') !== false) {
|
if (strpos($e->getMessage(), 'Undefined property') !== false) {
|
||||||
|
|
@ -383,9 +385,6 @@ public function getSubnets(): JsonResponse
|
||||||
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
||||||
$subnetName = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
$subnetName = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
||||||
|
|
||||||
// Crear el campo option-data para la puerta de enlace (gateway)
|
|
||||||
$gatewayIP = substr($address, 0, strrpos($address, '.')) . '.1';
|
|
||||||
|
|
||||||
// Crear el array newSubnet con los valores obligatorios
|
// Crear el array newSubnet con los valores obligatorios
|
||||||
$newSubnet = [
|
$newSubnet = [
|
||||||
"id" => $subnetId,
|
"id" => $subnetId,
|
||||||
|
|
@ -477,7 +476,7 @@ public function getSubnets(): JsonResponse
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return new JsonResponse(['error' => "Error al obtener la configuración de Kea DHCP: " . $e->getMessage()], 500);
|
return new JsonResponse(['error' => "Error al obtener la configuración de Kea DHCP: " . $e->getMessage()], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -617,7 +616,7 @@ public function getSubnets(): JsonResponse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/ogdhcp/v1/subnets/{subnetId}", methods={"PUT"})
|
* @Route("/ogdhcp/v1/subnets/{subnetId}", methods={"PUT"})
|
||||||
* @OA\Put(
|
* @OA\Put(
|
||||||
* path="/ogdhcp/v1/subnets/{subnetId}",
|
* path="/ogdhcp/v1/subnets/{subnetId}",
|
||||||
|
|
@ -636,6 +635,7 @@ public function getSubnets(): JsonResponse
|
||||||
* type="object",
|
* type="object",
|
||||||
* @OA\Property(property="mask", type="string"),
|
* @OA\Property(property="mask", type="string"),
|
||||||
* @OA\Property(property="address", type="string"),
|
* @OA\Property(property="address", type="string"),
|
||||||
|
* @OA\Property(property="router", type="string", example="192.168.1.254"),
|
||||||
* @OA\Property(property="nextServer", type="string"),
|
* @OA\Property(property="nextServer", type="string"),
|
||||||
* @OA\Property(property="bootFileName", type="string")
|
* @OA\Property(property="bootFileName", type="string")
|
||||||
* )
|
* )
|
||||||
|
|
@ -650,12 +650,12 @@ public function getSubnets(): JsonResponse
|
||||||
* ),
|
* ),
|
||||||
* @OA\Response(
|
* @OA\Response(
|
||||||
* response=400,
|
* response=400,
|
||||||
* description="Error occurred while deleting the subnet",
|
* description="Error occurred while modifying the subnet",
|
||||||
* @OA\JsonContent(
|
* @OA\JsonContent(
|
||||||
* oneOf={
|
* oneOf={
|
||||||
* @OA\Schema(@OA\Property(property="error", type="string", example="Falta un parámetro requerido: $paramFaltante")),
|
* @OA\Schema(@OA\Property(property="error", type="string", example="Falta un parámetro requerido: $paramFaltante")),
|
||||||
* @OA\Schema(@OA\Property(property="error", type="string", example="No hay subredes definidas")),
|
* @OA\Schema(@OA\Property(property="error", type="string", example="No hay subredes definidas")),
|
||||||
* @OA\Schema(@OA\Property(property="error", type="string", example="Error configuracion de kea invalido")),
|
* @OA\Schema(@OA\Property(property="error", type="string", example="Error configuración de Kea inválido")),
|
||||||
* @OA\Schema(@OA\Property(property="error", type="string", example="Error al guardar la configuración en Kea DHCP")),
|
* @OA\Schema(@OA\Property(property="error", type="string", example="Error al guardar la configuración en Kea DHCP")),
|
||||||
* @OA\Schema(@OA\Property(property="error", type="string", example="Error al escribir en la configuración en Kea DHCP"))
|
* @OA\Schema(@OA\Property(property="error", type="string", example="Error al escribir en la configuración en Kea DHCP"))
|
||||||
* }
|
* }
|
||||||
|
|
@ -682,9 +682,13 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
$mask = htmlspecialchars($input->mask);
|
$mask = htmlspecialchars($input->mask);
|
||||||
$address = htmlspecialchars($input->address);
|
$address = htmlspecialchars($input->address);
|
||||||
|
|
||||||
// Verificar si next-server y boot-file-name están presentes
|
// Verificar si next-server, boot-file-name y router están presentes
|
||||||
$nextServer = isset($input->nextServer) ? htmlspecialchars($input->nextServer) : null;
|
$nextServer = isset($input->nextServer) ? htmlspecialchars($input->nextServer) : null;
|
||||||
$bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null;
|
$bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null;
|
||||||
|
$router = isset($input->router) ? htmlspecialchars($input->router) : null;
|
||||||
|
|
||||||
|
// Calcular el gateway añadiendo .1 al final de la subred si no se proporciona el router
|
||||||
|
$gateway = $router ?: preg_replace('/\d+$/', '1', $address);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if (strpos($e->getMessage(), 'Undefined property') !== false) {
|
if (strpos($e->getMessage(), 'Undefined property') !== false) {
|
||||||
preg_match('/Undefined property: stdClass::\$(\w+)/', $e->getMessage(), $matches);
|
preg_match('/Undefined property: stdClass::\$(\w+)/', $e->getMessage(), $matches);
|
||||||
|
|
@ -707,9 +711,6 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
if ($subnetIndex === false) {
|
if ($subnetIndex === false) {
|
||||||
return new JsonResponse(['error' => "La subred con el id '$subnetId' no existe"], 400);
|
return new JsonResponse(['error' => "La subred con el id '$subnetId' no existe"], 400);
|
||||||
} else {
|
} else {
|
||||||
// Calcular el gateway añadiendo .1 al final de la subred
|
|
||||||
$gateway = preg_replace('/\d+$/', '1', $address);
|
|
||||||
|
|
||||||
// Obtener la subred actual para mantener las reservas existentes
|
// Obtener la subred actual para mantener las reservas existentes
|
||||||
$existingSubnet = $response[0]['arguments']['Dhcp4']['subnet4'][$subnetIndex];
|
$existingSubnet = $response[0]['arguments']['Dhcp4']['subnet4'][$subnetIndex];
|
||||||
|
|
||||||
|
|
@ -731,7 +732,6 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
if ($nextServer) {
|
if ($nextServer) {
|
||||||
$newSubnet["next-server"] = $nextServer;
|
$newSubnet["next-server"] = $nextServer;
|
||||||
} else {
|
} else {
|
||||||
// Eliminar next-server de las reservas si no está presente
|
|
||||||
foreach ($newSubnet['reservations'] as &$reservation) {
|
foreach ($newSubnet['reservations'] as &$reservation) {
|
||||||
unset($reservation['next-server']);
|
unset($reservation['next-server']);
|
||||||
}
|
}
|
||||||
|
|
@ -741,7 +741,6 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
if ($bootFileName) {
|
if ($bootFileName) {
|
||||||
$newSubnet["boot-file-name"] = $bootFileName;
|
$newSubnet["boot-file-name"] = $bootFileName;
|
||||||
} else {
|
} else {
|
||||||
// Eliminar boot-file-name de las reservas si no está presente
|
|
||||||
foreach ($newSubnet['reservations'] as &$reservation) {
|
foreach ($newSubnet['reservations'] as &$reservation) {
|
||||||
unset($reservation['boot-file-name']);
|
unset($reservation['boot-file-name']);
|
||||||
}
|
}
|
||||||
|
|
@ -750,10 +749,10 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
// Actualizar las reservas con los nuevos valores de next-server y boot-file-name
|
// Actualizar las reservas con los nuevos valores de next-server y boot-file-name
|
||||||
foreach ($newSubnet['reservations'] as &$reservation) {
|
foreach ($newSubnet['reservations'] as &$reservation) {
|
||||||
if ($nextServer) {
|
if ($nextServer) {
|
||||||
$reservation['next-server'] = $nextServer; // Actualizar el next-server del host
|
$reservation['next-server'] = $nextServer;
|
||||||
}
|
}
|
||||||
if ($bootFileName) {
|
if ($bootFileName) {
|
||||||
$reservation['boot-file-name'] = $bootFileName; // Actualizar el boot-file-name del host
|
$reservation['boot-file-name'] = $bootFileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -790,7 +789,7 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new JsonResponse(['error' => "Error configuracion de kea invalido: " . $responseTest[0]["text"]], 400);
|
return new JsonResponse(['error' => "Error configuración de Kea inválida: " . $responseTest[0]["text"]], 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
@ -800,6 +799,7 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @OA\Get(
|
* @OA\Get(
|
||||||
* path="/ogdhcp/v1/subnets/{subnetId}/hosts",
|
* path="/ogdhcp/v1/subnets/{subnetId}/hosts",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue