Update oglog changes
oginstaller/pipeline/head There was a failure building this commit Details
oginstaller/pipeline/pr-main There was a failure building this commit Details

pull/4/head
Nicolas Arenas 2025-08-08 12:54:31 +02:00
parent 3e727dec3a
commit 1d7b426703
1 changed files with 167 additions and 4 deletions

View File

@ -184,6 +184,11 @@ class MononodoConfigForm(npyscreen.ActionForm):
name="IP del servidor (mononodo):",
value=get_default_ip()
)
self.oglog_ip = self.add(
npyscreen.TitleText,
name="IP del servidor oglog:",
value=get_default_ip()
)
self.samba_user = self.add(
npyscreen.TitleText,
name="Usuario Samba:",
@ -200,6 +205,7 @@ class MononodoConfigForm(npyscreen.ActionForm):
"""Guardar la configuración y pasar al siguiente formulario."""
logging.debug(f"Entrando en MononodoConfigForm")
self.parentApp.server_ip = self.server_ip.value
self.parentApp.oglog_ip = self.oglog_ip.value
self.parentApp.samba_user = self.samba_user.value
self.parentApp.samba_pass = self.samba_pass.value
self.parentApp.setNextForm("MAIN")
@ -232,6 +238,11 @@ class MultinodoConfigForm(npyscreen.ActionForm):
name="IP del servidor Boot:",
value=get_default_ip()
)
self.oglog_ip = self.add(
npyscreen.TitleText,
name="IP del servidor oglog:",
value=get_default_ip()
)
self.samba_user = self.add(
npyscreen.TitleText,
name="Usuario Samba:",
@ -250,6 +261,7 @@ class MultinodoConfigForm(npyscreen.ActionForm):
self.parentApp.dhcp_ip = self.dhcp_ip.value
self.parentApp.core_ip = self.core_ip.value
self.parentApp.boot_ip = self.boot_ip.value
self.parentApp.oglog_ip = self.oglog_ip.value
self.parentApp.samba_user = self.samba_user.value
self.parentApp.samba_pass = self.samba_pass.value
self.parentApp.setNextForm("MAIN")
@ -265,7 +277,7 @@ class ComponentSelectionForm(npyscreen.ActionForm):
npyscreen.TitleMultiSelect,
max_height=6,
name="Selecciona los componentes",
values=["ogCore", "ogGui", "ogDhcp", "ogBoot", "ogRepository"],
values=["ogCore", "ogGui", "ogDhcp", "ogBoot", "ogRepository","oglog"],
scroll_exit=True
)
self.versions = get_available_versions() # Obtener las versiones desde el archivo JSON
@ -402,6 +414,7 @@ class OgCoreForm(ComponentForm):
def configure_fields(self):
ip_oglog= self.parentApp.oglog_ip if self.parentApp.installation_type == "mononodo" else self.parentApp.core_ip
self.add(npyscreen.FixedText, value="Usuario Administrador: ", editable=False, rely=2, relx=2, color="SAFE" , highlighted=True)
self.fields["adminUser"] = {
"widget": self.add(
@ -423,6 +436,7 @@ class OgCoreForm(ComponentForm):
)
}
class OgGuiForm(ComponentForm):
component_name = "oggui"
@ -477,6 +491,7 @@ class OgGuiForm(ComponentForm):
class OgDhcpForm(ComponentForm):
component_name = "ogdhcp"
def get_dhcp_ip(self):
"""Obtiene la IP del servidor DHCP."""
if self.parentApp.installation_type == "mononodo":
@ -527,6 +542,7 @@ class OgDhcpForm(ComponentForm):
)
}
def on_ok(self):
available_interfaces = self.fields["dhcp_interfaces"]["widget"].values
selected_indices = self.fields["dhcp_interfaces"]["widget"].value
@ -565,6 +581,7 @@ class OgDhcpForm(ComponentForm):
class OgBootForm(ComponentForm):
component_name = "ogboot"
download_url = "https://ognproject.evlt.uma.es/oglive/"
def get_boot_ip(self):
"""Obtiene la IP del servidor Boot."""
if self.parentApp.installation_type == "mononodo":
@ -635,6 +652,7 @@ class OgBootForm(ComponentForm):
highlighted=True
)
}
# # self.fields["sambaUser"] = {"widget": self.add(npyscreen.TitleText, name="Usuario Samba:", value="opengnsys", rely=20)}
# self.add(npyscreen.FixedText, value="Usuario Samba:", editable=False, rely=14, relx=2, color="SAFE" , highlighted=True)
# self.fields["sambaUser"] = {
@ -772,6 +790,70 @@ class OgRepositoryForm(ComponentForm):
# )
# }
class OgLogForm(ComponentForm):
component_name = "oglog"
def configure_fields(self):
ogCoreIp = self.parentApp.core_ip if self.parentApp.installation_type == "multinodo" else self.parentApp.server_ip
self.add(npyscreen.FixedText, value="Configuración de oglog:", editable=False, rely=2, relx=2, color="SAFE", highlighted=True)
self.fields["certificateAltNames"] = {
"widget": self.add(
npyscreen.TitleText,
name="Dominios para los certificados:",
value="oglog.local,oglog.example.com",
rely=4,
relx=2
)
}
self.fields["opensearchInitialPassword"] = {
"widget": self.add(
npyscreen.TitlePassword,
name="Password inicial Opensearch:",
value="OpenSearch1234;",
rely=6,
relx=2
)
}
self.fields["ogCoreIp"] = {
"widget": self.add(
npyscreen.TitleText,
name="IP ogCore:",
value=self.parentApp.core_ip if self.parentApp.installation_type == "multinodo" else self.parentApp.server_ip,
rely=8,
relx=2
)
}
self.fields["ogLogIp"] = {
"widget": self.add(
npyscreen.TitleText,
name="IP ogLog:",
value= self.parentApp.oglog_ip ,
rely=10,
relx=2
)
}
self.fields["subdomain"] = {
"widget": self.add(
npyscreen.TitleText,
name="Subdominio:",
value="local",
rely=12,
relx=2
)
}
self.fields["nodeExporterTargets"] = {
"widget": self.add(
npyscreen.TitleText,
name="Node Exporter targets:",
value=f"localhost,{ogCoreIp}",
rely=14,
relx=2
)
}
class InstallationProgressForm(npyscreen.Form):
"""Formulario para mostrar el progreso de instalación y el log en tiempo real."""
def create(self):
@ -843,7 +925,18 @@ def install_components_with_ui(form, components, selected_tag):
for index, package in enumerate(components, start=1):
form.update_progress(f"Instalando paquete {index}/{total_packages}: {package}", current=index, total=total_packages)
install_command = f"DEBIAN_FRONTEND=noninteractive apt-get install -y {package}"
# Si el paquete es oglog, añade la variable de entorno OPENSEARCH_INITIAL_ADMIN_PASSWORD
if package == "oglog":
oglog_config = form.parentApp.configurations.get("oglog", {})
opensearch_password = oglog_config.get("opensearchInitialPassword", "changeme")
install_command = (
f"OPENSEARCH_INITIAL_ADMIN_PASSWORD='{opensearch_password}' "
"DEBIAN_FRONTEND=noninteractive apt-get install -y oglog"
)
else:
install_command = f"DEBIAN_FRONTEND=noninteractive apt-get install -y {package}"
process = subprocess.Popen(
install_command, shell=True, text=True, stdout=log_file, stderr=log_file, bufsize=1
)
@ -880,7 +973,8 @@ def install_components_with_ui(form, components, selected_tag):
ogDhcpIp = form.parentApp.server_ip if form.parentApp.installation_type == "mononodo" else form.parentApp.dhcp_ip
ogCoreIp = form.parentApp.server_ip if form.parentApp.installation_type == "mononodo" else form.parentApp.core_ip
ogBootIp = form.parentApp.server_ip if form.parentApp.installation_type == "mononodo" else form.parentApp.boot_ip
ogBootIp = form.parentApp.server_ip if form.parentApp.installation_type == "mononodo" else form.parentApp.boot_ip
ogLogIp = form.parentApp.oglog_ip
env_path = "/opt/opengnsys/ogcore/api/env.json"
shutil.copy(env_path, env_path + ".bak") # Hacer una copia de seguridad del archivo original
@ -891,10 +985,77 @@ def install_components_with_ui(form, components, selected_tag):
data["vars"]["OG_DHCP_API_URL"] = f"{ogDhcpIp}:8081"
data["vars"]["OG_CORE_IP"] = ogCoreIp
data["vars"]["OG_BOOT_IP"] = ogBootIp
data["vars"]["OG_LOG_IP"] = ogLogIp
with open(env_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
form.update_progress("Variables de entorno para ogcore configuradas correctamente.")
## Si no hemos instalado oglog, configuramos systemd-journal-remote y prometheus-node-exporter para que envie los logs a oglog
if "oglog" not in installed_packages:
try:
form.update_progress("Instalando systemd-journal-remote y prometheus-node-exporter...")
subprocess.run(
"DEBIAN_FRONTEND=noninteractive apt-get install -y systemd-journal-remote prometheus-node-exporter",
shell=True,
text=True,
stdout=log_file,
stderr=log_file,
bufsize=1
)
log_file.flush()
form.update_progress("Systemd-journal-remote instalado correctamente.")
ogLogIp = form.parentApp.oglog_ip
form.update_progress("Configurando variables de entorno para oglog...")
config_path = "/etc/systemd/journal-upload.conf"
config_content = f"""[Upload]
URL=http://{ogLogIp}:19532
# ServerKeyFile=/etc/ssl/private/journal-upload.pem
# ServerCertificateFile=/etc/ssl/certs/journal-upload.pem
# TrustedCertificateFile=/etc/ssl/ca/trusted.pem
"""
with open(config_path, "w") as config_file:
config_file.write(config_content)
form.update_progress("Variables de entorno para oglog configuradas correctamente.")
# Habilitar y reiniciar el servicio systemd-journal-upload
subprocess.run(
"systemctl restart systemd-journal-upload",
shell=True,
text=True,
stdout=log_file,
stderr=log_file,
bufsize=1
)
subprocess.run(
"systemctl enable systemd-journal-upload",
shell=True,
text=True,
stdout=log_file,
stderr=log_file,
bufsize=1
)
subprocess.run(
"systemctl restart prometheus-node-exporter",
shell=True,
text=True,
stdout=log_file,
stderr=log_file,
bufsize=1
)
subprocess.run(
"systemctl enable prometheus-node-exporter",
shell=True,
text=True,
stdout=log_file,
stderr=log_file,
bufsize=1
)
log_file.flush()
form.update_progress("systemd-journal-remote y prometheus-node-exporter instalados y configurados correctamente.")
except Exception as e:
form.update_progress(f"Error instalando o configurando systemd-journal-remote: {e}")
failed_packages.append("systemd-journal-remote")
## Si la password de samba no es la por defecto o el usuario samba no es por defecto, cambiarla en los oglives y en el sistema con el comando smbpasswd
## Si el paquete ogboot está instalado se cambia la password en los oglives. Si el paquete ogrepository está instalado se cambia la password en el sistema.
@ -980,7 +1141,8 @@ class MyApp(npyscreen.NPSAppManaged):
self.repo_ip = None # IP del servidor Repository
self.dhcp_ip = None # IP del servidor DHCP
self.core_ip = None # IP del servidor Core
self.boot_ip = None # IP del servidor Boot dpkg
self.boot_ip = None # IP del servidor Boot
self.oglog_ip = None # IP del servidor oglog
self.selected_components = [] # Componentes seleccionados
self.selected_tag = None # Versión seleccionada
self.configurations = {} # Configuraciones de los componentes
@ -995,6 +1157,7 @@ class MyApp(npyscreen.NPSAppManaged):
self.addForm("ogdhcp", OgDhcpForm)
self.addForm("ogboot", OgBootForm)
self.addForm("ogrepository", OgRepositoryForm)
self.addForm("oglog", OgLogForm)
self.addForm("INSTALLATION_PROGRESS", InstallationProgressForm)
# Configurar el formulario inicial