refs #1167 #1168 #1169 #1170 now we use a variable port that by default is 8082. If you adds a ip and a port in config.json will use the port that you defines and configure nginx with that port. attach the port in nginx connections, remove port in tftp connections and kernel parameters. Creates client/images for ogrepository samba

ogboot-log
Luis Gerardo Romero Garcia 2024-11-22 11:15:05 +01:00
parent 5ea829c99b
commit 27751b50b3
4 changed files with 37 additions and 7 deletions

View File

@ -13,6 +13,7 @@ services:
bind:
$ogCoreApiUrl: '%env(OGCORE_API_URL)%'
$ogBootIP: '%env(OGBOOT_IP)%'
$ogBootPort: '%env(OGBOOT_PORT)%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name

View File

@ -1,5 +1,5 @@
server {
listen 8082;
listen __PORT__;
server_name __SERVERIP__ localhost; # IP del servidor
# Raíz del documento para el proyecto Symfony

View File

@ -24,7 +24,17 @@ with open(config_file, 'r') as f:
config = json.load(f)
OGCORE_IP = config["ogCore_ServerIP"]
OGBOOT_IP = config['ogBoot_ServerIP']
#Para el caso de que pasen una ip con puerto separamos la ip y el puerto
#Pasamos el puerto para conexiones por http
#No pasamos el puerto para conexiones tftp y parámetros del kernel
#Si solo pasan la IP usaremos el puerto por defecto 8082
ogboot_ip_port = config['ogBoot_ServerIP']
if ':' in ogboot_ip_port:
OGBOOT_IP, OGBOOT_PORT = ogboot_ip_port.split(':')
OGBOOT_PORT = int(OGBOOT_PORT)
else:
OGBOOT_IP = ogboot_ip_port
OGBOOT_PORT = 8082
oglive_iso_url = config["ogLive_Default"]
INSTALL_OGBOOT_TARGET = config["ogBoot_Dir"]
OPENGNSYS_CLIENT_USER = config["ogBootSambaUser"]
@ -251,6 +261,10 @@ def og_boot_symfony_install():
with open(env_dest, 'a') as env_file:
env_file.write(f"\n{ogboot_ip}\n")
logger.info(f"Added OGBOOT_IP to {env_dest} with IP: {OGBOOT_IP}")
ogboot_port = f'OGBOOT_PORT="{OGBOOT_PORT}"'
with open(env_dest, 'a') as env_file:
env_file.write(f"\n{ogboot_port}\n")
logger.info(f"Added OGBOOT_PORT to {env_dest} with IP: {OGBOOT_PORT}")
except Exception as e:
logger.error(f"An error occurred while copying files or modifying .env: {e}")
@ -464,6 +478,8 @@ def copyClientFiles():
config_file.write(content)
logger.info("Configuration file ogAdmClient.cfg created successfully.")
# Creamos el directorio de images para el samba de ogrepository
os.makedirs(os.path.join(INSTALL_OGBOOT_TARGET, "client/images"), mode=0o775, exist_ok=True)
# Change ownership of INSTALL_OGBOOT_TARGET/client/ and its contents
subprocess.run(f"chown -R opengnsys:opengnsys {INSTALL_OGBOOT_TARGET}/client/", shell=True, text=True, capture_output=True)
@ -648,6 +664,7 @@ def setup_nginx():
try:
# Obtener la IP del servidor
ip_address_server = OGBOOT_IP
port_address_server = OGBOOT_PORT
php_version = get_php_fpm_version()
# Leer y modificar la plantilla de configuración de nginx
@ -656,6 +673,7 @@ def setup_nginx():
nginx_content = nginx_file.read()
nginx_content = nginx_content.replace("__SERVERIP__", ip_address_server)
nginx_content = nginx_content.replace("__PORT__", port_address_server)
nginx_content = nginx_content.replace("__PHPVERSION__", php_version)
nginx_content = nginx_content.replace("__ROOT__", INSTALL_OGBOOT_TARGET)
nginx_content = nginx_content.replace("__TFTPPATH__", f"{INSTALL_OGBOOT_TARGET}/tftpboot")

View File

@ -28,13 +28,13 @@ class OgBootController
private $httpClient;
private $params;
private $tftpbootDir;
public function __construct(CurlRequestService $curlRequestService, LoggerInterface $logger, HttpClientInterface $httpClient, ParameterBagInterface $params, protected readonly string $ogBootIP)
public function __construct(CurlRequestService $curlRequestService, LoggerInterface $logger, HttpClientInterface $httpClient, ParameterBagInterface $params, protected readonly string $ogBootIP, protected readonly string $ogBootPort)
{
$this->curlRequestService = $curlRequestService;
$this->logger = $logger;
$this->httpClient = $httpClient;
$this->params = $params; // Accedemos a las variables de entorno a través de ParameterBagInterface
$this->tftpbootDir = $params->get('tftpboot_dir');
$this->params = $params; // Accedemos a las variables de entorno a través de ParameterBagInterface
$this->tftpbootDir = $params->get('tftpboot_dir');
}
/*Tabla de Contenido
@ -1030,7 +1030,11 @@ public function createBootFile(Request $request): JsonResponse
$templateName = $data['template_name'] ?? null;
$mac = $this->validateAndFormatMac($data['mac'] ?? null);
//Si nos pasan el puerto se lo quitamos ya que server_ip siempre tirara por Samba
$serverIp = $data['server_ip'] ?? null;
if ($serverIp && strpos($serverIp, ':') !== false) {
$serverIp = explode(':', $serverIp)[0];
}
$ogLiveDir = $data['oglivedir'] ?? 'ogLive';
// Verificación de los campos obligatorios
@ -1103,13 +1107,20 @@ public function createBootFile(Request $request): JsonResponse
(is_numeric($parameters['resolution']) && $parameters['resolution'] <= 999 ? 'vga=' . $parameters['resolution'] :
(strpos($parameters['resolution'], ':') !== false ? 'video=' . $parameters['resolution'] : ' ' . $parameters['resolution']));
// Reemplazar las variables en el contenido de la plantilla
// Esta será llamada a http para arrancar kernel e imagen de inicialización
// Si lo requiriese debe llevar puerto ya que se comunica con nginx
$serverIpPort = $this->ogBootIP;
if (!empty($this->ogBootPort)) {
$serverIpPort .= ':' . $this->ogBootPort;
}
$pxeContent = str_replace(
['__INFOHOST__', '__SERVERIP__', '__OGLIVE__'],
[$kernelArgs, $this->ogBootIP, $ogLiveDir],
[$kernelArgs, $serverIpPort, $ogLiveDir],
$templateContent
);
// Insertar el comentario con el nombre de la plantilla después de #!ipxe
if (strpos($pxeContent, '#!ipxe') === 0) {
$pxeContent = "#!ipxe\n#Template: $templateName\n" . substr($pxeContent, 6);