refs #1568 adds new parameters subnetName and dns to kea dhcp
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
82eddcc8e9
commit
16eedd9546
|
@ -242,6 +242,7 @@ class DhcpController
|
||||||
* @OA\Property(property="id", type="integer", example=1),
|
* @OA\Property(property="id", type="integer", example=1),
|
||||||
* @OA\Property(property="subnet", type="string", example="192.168.1.0/24"),
|
* @OA\Property(property="subnet", type="string", example="192.168.1.0/24"),
|
||||||
* @OA\Property(property="next-server", type="string", example="192.168.1.1"),
|
* @OA\Property(property="next-server", type="string", example="192.168.1.1"),
|
||||||
|
* @OA\Property(property="DNS", type="string", example="192.168.1.1"),
|
||||||
* @OA\Property(property="boot-file-name", type="string", example="pxelinux.0"),
|
* @OA\Property(property="boot-file-name", type="string", example="pxelinux.0"),
|
||||||
* @OA\Property(property="pools", type="array",
|
* @OA\Property(property="pools", type="array",
|
||||||
* @OA\Items(
|
* @OA\Items(
|
||||||
|
@ -394,6 +395,8 @@ class DhcpController
|
||||||
* @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="subnetName", type="string", example="Aula informatica),
|
||||||
|
* @OA\Property(property="DNS", 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\Property(property="router", type="string", example="192.168.1.254")
|
||||||
* )
|
* )
|
||||||
|
@ -467,6 +470,8 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
||||||
$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;
|
$router = isset($input->router) ? htmlspecialchars($input->router) : null;
|
||||||
|
$DNS = isset($input->DNS) ? htmlspecialchars($input->DNS) : null;
|
||||||
|
$subnetName = isset($input->subnetName) ? htmlspecialchars($input->subnetName) : null;
|
||||||
|
|
||||||
// Calcular el gatewayIP si no se proporciona el router
|
// Calcular el gatewayIP si no se proporciona el router
|
||||||
$gatewayIP = $router ?: substr($address, 0, strrpos($address, '.')) . '.1';
|
$gatewayIP = $router ?: substr($address, 0, strrpos($address, '.')) . '.1';
|
||||||
|
@ -491,11 +496,11 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
||||||
$subnetName = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
$subnetCIDR = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
||||||
|
|
||||||
$newSubnet = [
|
$newSubnet = [
|
||||||
"id" => $subnetId,
|
"id" => $subnetId,
|
||||||
"subnet" => $subnetName,
|
"subnet" => $subnetCIDR,
|
||||||
"reservations" => [],
|
"reservations" => [],
|
||||||
"option-data" => [
|
"option-data" => [
|
||||||
[
|
[
|
||||||
|
@ -506,6 +511,23 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Agregar "user-context" solo si $subnetName tiene valor
|
||||||
|
if (!empty($subnetName)) {
|
||||||
|
$newSubnet["user-context"] = [
|
||||||
|
"subnetName" => $subnetName
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($DNS)) {
|
||||||
|
$newSubnet["option-data"][] = [
|
||||||
|
"name" => "domain-name-servers",
|
||||||
|
"code" => 23,
|
||||||
|
"space" => "dhcp4",
|
||||||
|
"csv-format" => true,
|
||||||
|
"data" => $DNS
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
if ($nextServer) {
|
if ($nextServer) {
|
||||||
$newSubnet["next-server"] = $nextServer;
|
$newSubnet["next-server"] = $nextServer;
|
||||||
}
|
}
|
||||||
|
@ -520,7 +542,7 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
||||||
|
|
||||||
$subnets = $response[0]['arguments']['Dhcp4']['subnet4'];
|
$subnets = $response[0]['arguments']['Dhcp4']['subnet4'];
|
||||||
|
|
||||||
$subnetNameExists = array_reduce($subnets, fn($exists, $subnetElement) => $exists || ($subnetElement['subnet'] === $subnetName), false);
|
$subnetNameExists = array_reduce($subnets, fn($exists, $subnetElement) => $exists || ($subnetElement['subnet'] === $subnetCIDR), false);
|
||||||
$subnetIdExists = array_reduce($subnets, fn($exists, $subnetElement) => $exists || ($subnetElement['id'] === $subnetId), false);
|
$subnetIdExists = array_reduce($subnets, fn($exists, $subnetElement) => $exists || ($subnetElement['id'] === $subnetId), false);
|
||||||
|
|
||||||
if ($subnetNameExists) {
|
if ($subnetNameExists) {
|
||||||
|
@ -529,10 +551,10 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
||||||
'operation' => $operation,
|
'operation' => $operation,
|
||||||
'component' => $component,
|
'component' => $component,
|
||||||
'http_code' => Response::HTTP_BAD_REQUEST,
|
'http_code' => Response::HTTP_BAD_REQUEST,
|
||||||
'desc' => "La subred con la IP '$subnetName' ya existe."
|
'desc' => "La subred con la IP '$subnetCIDR' ya existe."
|
||||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||||
|
|
||||||
return new JsonResponse(['error' => "La subred con la ip '$subnetName' ya existe."], Response::HTTP_BAD_REQUEST);
|
return new JsonResponse(['error' => "La subred con la ip '$subnetCIDR' ya existe."], Response::HTTP_BAD_REQUEST);
|
||||||
} elseif ($subnetIdExists) {
|
} elseif ($subnetIdExists) {
|
||||||
$this->logger->error(json_encode([
|
$this->logger->error(json_encode([
|
||||||
'severity' => 'ERROR',
|
'severity' => 'ERROR',
|
||||||
|
@ -866,6 +888,8 @@ public function addDhcpSubnet(Request $request): 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="DNS", type="string")
|
||||||
|
* @OA\Property(property="subnetName", type="string")
|
||||||
* @OA\Property(property="router", type="string", example="192.168.1.254"),
|
* @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")
|
||||||
|
@ -920,6 +944,8 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
$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;
|
$router = isset($input->router) ? htmlspecialchars($input->router) : null;
|
||||||
|
$DNS = isset($input->DNS) ? htmlspecialchars($input->DNS) : null;
|
||||||
|
$subnetName = isset($input->subnetName) ? htmlspecialchars($input->subnetName) : null;
|
||||||
|
|
||||||
// Calcular el gateway añadiendo .1 al final de la subred si no se proporciona el router
|
// Calcular el gateway añadiendo .1 al final de la subred si no se proporciona el router
|
||||||
$gateway = $router ?: preg_replace('/\d+$/', '1', $address);
|
$gateway = $router ?: preg_replace('/\d+$/', '1', $address);
|
||||||
|
@ -948,7 +974,7 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
||||||
$subnetName = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
$subnetCIDR = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
||||||
|
|
||||||
if (!isset($response[0]['arguments']['Dhcp4']['subnet4'])) {
|
if (!isset($response[0]['arguments']['Dhcp4']['subnet4'])) {
|
||||||
$errorText = "No hay subredes definidas";
|
$errorText = "No hay subredes definidas";
|
||||||
|
@ -982,7 +1008,7 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
// Modificar la subred existente
|
// Modificar la subred existente
|
||||||
$newSubnet = [
|
$newSubnet = [
|
||||||
"id" => $subnetId,
|
"id" => $subnetId,
|
||||||
"subnet" => $subnetName,
|
"subnet" => $subnetCIDR,
|
||||||
"reservations" => $existingSubnet['reservations'], // Mantener las reservas existentes
|
"reservations" => $existingSubnet['reservations'], // Mantener las reservas existentes
|
||||||
"option-data" => [
|
"option-data" => [
|
||||||
[
|
[
|
||||||
|
@ -993,6 +1019,24 @@ public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Agregar "user-context" solo si $subnetName tiene valor
|
||||||
|
if (!empty($subnetName)) {
|
||||||
|
$newSubnet["user-context"] = [
|
||||||
|
"subnetName" => $subnetName
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Agregar DNS si está presente
|
||||||
|
if (!empty($DNS)) {
|
||||||
|
$newSubnet["option-data"][] = [
|
||||||
|
"name" => "domain-name-servers",
|
||||||
|
"code" => 23,
|
||||||
|
"space" => "dhcp4",
|
||||||
|
"csv-format" => true,
|
||||||
|
"data" => $DNS
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
// Añadir next-server si está presente, o eliminarlo de las reservas si no está
|
// Añadir next-server si está presente, o eliminarlo de las reservas si no está
|
||||||
if ($nextServer) {
|
if ($nextServer) {
|
||||||
$newSubnet["next-server"] = $nextServer;
|
$newSubnet["next-server"] = $nextServer;
|
||||||
|
|
Loading…
Reference in New Issue