refs #981 #984 adds a minimal kea configuration to the installer, adds a json with the interfaces and the ogbootIp, adds gateway configuration when a subnet is create o modified in the controller
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
0f8870e003
commit
2946fc1d19
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"interfaces": ["eth0", "eth1"],
|
||||
"ogbootIP": "172.17.8.37"
|
||||
}
|
|
@ -450,6 +450,73 @@ modify_php_fpm_config() {
|
|||
}
|
||||
|
||||
|
||||
configure_kea() {
|
||||
# Ruta del archivo config_ogdhcp.json proporcionado por el usuario
|
||||
CONFIG_FILE="config_ogdhcp.json"
|
||||
|
||||
# Verificar si jq está instalado
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "jq no está instalado. Por favor, instala jq para continuar."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verificar si el archivo de configuración existe
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "El archivo $CONFIG_FILE no se encuentra. Asegúrate de que esté disponible antes de la instalación."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Leer los parámetros del archivo JSON usando jq
|
||||
INTERFACES=$(jq -r '.interfaces[]' "$CONFIG_FILE")
|
||||
OGBOOT_IP=$(jq -r '.ogbootIP' "$CONFIG_FILE")
|
||||
|
||||
# Crear la configuración mínima de Kea DHCP
|
||||
KEA_CONFIG="/etc/kea/kea-dhcp4.conf"
|
||||
|
||||
# Hacer una copia de seguridad del archivo kea-dhcp4.conf si ya existe
|
||||
if [ -f "$KEA_CONFIG" ]; then
|
||||
cp "$KEA_CONFIG" "$KEA_CONFIG.backup"
|
||||
echo "Se ha creado una copia de seguridad del archivo de configuración actual en $KEA_CONFIG.backup"
|
||||
fi
|
||||
|
||||
# Generar la configuración mínima para Kea DHCP
|
||||
cat > "$KEA_CONFIG" << EOL
|
||||
{
|
||||
"Dhcp4": {
|
||||
"interfaces-config": {
|
||||
"interfaces": [ $(
|
||||
for interface in $INTERFACES; do
|
||||
echo "\"$interface\""
|
||||
done | paste -sd "," -
|
||||
) ]
|
||||
},
|
||||
"client-classes": [
|
||||
{
|
||||
"name": "UEFI-64",
|
||||
"test": "not substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'",
|
||||
"boot-file-name": "ipxe.efi",
|
||||
"next-server": "$OGBOOT_IP"
|
||||
},
|
||||
{
|
||||
"name": "Legacy",
|
||||
"test": "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'",
|
||||
"boot-file-name": "undionly.kpxe",
|
||||
"next-server": "$OGBOOT_IP"
|
||||
}
|
||||
],
|
||||
"control-socket": {
|
||||
"socket-name": "/run/kea/kea4-ctrl-socket",
|
||||
"socket-type": "unix"
|
||||
}
|
||||
}
|
||||
}
|
||||
EOL
|
||||
|
||||
echo "Se ha generado la configuración mínima de Kea DHCP en $KEA_CONFIG"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#####################################################################
|
||||
####### Algunas funciones útiles de propósito general:
|
||||
#####################################################################
|
||||
|
@ -555,6 +622,13 @@ if [ $? -ne 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
configure_kea
|
||||
if [ $? -ne 0 ]; then
|
||||
errorAndLog "Error configuring Kea DHCP initial configuration"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# install_kea
|
||||
# install_php
|
||||
# install_composer
|
||||
|
|
|
@ -356,8 +356,8 @@ public function getSubnets(): JsonResponse
|
|||
*/
|
||||
|
||||
|
||||
public function addDhcpSubnet(Request $request): JsonResponse
|
||||
{
|
||||
public function addDhcpSubnet(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$input = json_decode($request->getContent());
|
||||
$subnetId = (int) htmlspecialchars($input->subnetId);
|
||||
|
@ -377,12 +377,23 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
|||
try {
|
||||
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
||||
$subnetName = $address . '/' . $this->curlKeaService->convertMaskToCIDR($mask);
|
||||
|
||||
// Crear el campo option-data para la puerta de enlace (gateway)
|
||||
$gatewayIP = substr($address, 0, strrpos($address, '.')) . '.1';
|
||||
|
||||
$newSubnet = [
|
||||
"id" => $subnetId,
|
||||
"subnet" => $subnetName,
|
||||
"next-server" => $nextServer,
|
||||
"boot-file-name" => $bootFileName,
|
||||
"reservations" => []
|
||||
"reservations" => [],
|
||||
"option-data" => [
|
||||
[
|
||||
"name" => "routers",
|
||||
"code" => 3,
|
||||
"data" => $gatewayIP
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
if (!isset($response[0]['arguments']['Dhcp4']['subnet4'])) {
|
||||
|
@ -452,7 +463,8 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
|||
} catch (Exception $e) {
|
||||
return new JsonResponse(['error' => "Error al obtener la configuración de Kea DHCP: " . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Delete(
|
||||
|
@ -724,17 +736,30 @@ public function addDhcpSubnet(Request $request): JsonResponse
|
|||
$responseError = "La subred con el id '$subnetId' no existe";
|
||||
return new JsonResponse(['error' => $responseError], 400);
|
||||
} else {
|
||||
// Calcular el gateway añadiendo .1 al final de la subred
|
||||
$gateway = preg_replace('/\d+$/', '1', $address);
|
||||
|
||||
// Modificar la subred existente
|
||||
$response[0]['arguments']['Dhcp4']['subnet4'][$subnetIndex] = [
|
||||
"id" => $subnetId,
|
||||
"subnet" => $subnetName,
|
||||
"next-server" => $nextServer,
|
||||
"boot-file-name" => $bootFileName,
|
||||
"reservations" => []
|
||||
"reservations" => [],
|
||||
"option-data" => [
|
||||
[
|
||||
"name" => "routers",
|
||||
"code" => 3,
|
||||
"data" => $gateway
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// Eliminar el campo 'hash' si existe
|
||||
if (isset($response[0]['arguments']['hash'])) {
|
||||
unset($response[0]['arguments']['hash']);
|
||||
}
|
||||
|
||||
$array_encoded = json_encode($response[0]['arguments']);
|
||||
$configurationParsed = str_replace('\\', '', $array_encoded);
|
||||
$configuration = json_decode($configurationParsed);
|
||||
|
@ -1035,7 +1060,7 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse
|
|||
}
|
||||
}
|
||||
if ($createdHost) {
|
||||
return new JsonResponse(['success' => "Host agregado correctamente", 'newHost' => $createdHost], 200);
|
||||
return new JsonResponse(['success' => "Host agregado correctamente", 'message' => $createdHost], 200);
|
||||
} else {
|
||||
return new JsonResponse(['error' => "No se pudo encontrar el host recién creado"], 400);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue