refs #401 adds clientes creation functions to ogboot installer
parent
144265b66d
commit
9b4a218c84
|
@ -0,0 +1,5 @@
|
|||
ServidorAdm=SERVERIP
|
||||
PUERTO=2008
|
||||
PATHINTERFACE=/opt/opengnsys/interfaceAdm
|
||||
UrlMenu=OPENGNSYSURL/varios/menubrowser.php
|
||||
UrlMsg=http://localhost/cgi-bin/httpd-log.sh
|
|
@ -533,6 +533,180 @@ def tftpConfigure():
|
|||
# time.sleep(1)
|
||||
# testPxe()
|
||||
|
||||
|
||||
|
||||
def servicesCompilation():
|
||||
hayErrores = 0
|
||||
|
||||
# Compilar OpenGnsys Client
|
||||
echoAndLog(f"{servicesCompilation.__name__}(): Compiling OpenGnsys Admin Client")
|
||||
subprocess.run(["make"], cwd=f"{WORKDIR}/ogboot/sources/clients/ogAdmClient")
|
||||
subprocess.run(["mv", f"{WORKDIR}/ogboot/sources/clients/ogAdmClient/ogAdmClient", f"{WORKDIR}/client/shared/bin"])
|
||||
if subprocess.returncode != 0:
|
||||
echoAndLog(f"{servicesCompilation.__name__}(): error while compiling OpenGnsys Admin Client")
|
||||
hayErrores = 1
|
||||
|
||||
return hayErrores
|
||||
|
||||
|
||||
# Copiar carpeta de Interface
|
||||
def copyInterfaceAdm():
|
||||
hayErrores = 0
|
||||
|
||||
# Crear carpeta y copiar Interface
|
||||
echoAndLog(f"{copyInterfaceAdm.__name__}(): Copying Administration Interface Folder")
|
||||
subprocess.run(["cp", "-ar", f"{WORKDIR}/ogboot/sources/interface", f"{INSTALL_TARGET}/client/interfaceAdm"])
|
||||
if subprocess.returncode != 0:
|
||||
echoAndLog(f"{copyInterfaceAdm.__name__}(): error while copying Administration Interface Folder")
|
||||
hayErrores = 1
|
||||
|
||||
return hayErrores
|
||||
|
||||
|
||||
def copyClientFiles():
|
||||
errstatus = 0
|
||||
|
||||
echoAndLog(f"{copyClientFiles.__name__}(): Copying OpenGnsys Client files.")
|
||||
subprocess.run(["cp", "-a", f"{WORKDIR}/ogboot/client/shared/*", f"{INSTALL_TARGET}/client"])
|
||||
if subprocess.returncode != 0:
|
||||
errorAndLog(f"{copyClientFiles.__name__}(): error while copying client structure")
|
||||
errstatus = 1
|
||||
|
||||
echoAndLog(f"{copyClientFiles.__name__}(): Copying OpenGnsys Cloning Engine files.")
|
||||
subprocess.run(["mkdir", "-p", f"{INSTALL_TARGET}/client/lib/engine/bin"])
|
||||
subprocess.run(["cp", "-a", f"{WORKDIR}/ogboot/client/engine/*.lib*", f"{INSTALL_TARGET}/client/lib/engine/bin"])
|
||||
if subprocess.returncode != 0:
|
||||
errorAndLog(f"{copyClientFiles.__name__}(): error while copying engine files")
|
||||
errstatus = 1
|
||||
|
||||
if errstatus == 0:
|
||||
echoAndLog(f"{copyClientFiles.__name__}(): client copy files success.")
|
||||
else:
|
||||
errorAndLog(f"{copyClientFiles.__name__}(): client copy files with errors")
|
||||
|
||||
return errstatus
|
||||
|
||||
|
||||
# Configuración básica de servicios de OpenGnsys
|
||||
|
||||
def cidr2mask(bits):
|
||||
# Number of args to shift, 255..255, first non-255 byte, zeroes
|
||||
args = [5 - (bits // 8), 255, 255, 255, 255, (255 << (8 - (bits % 8))) & 255, 0, 0, 0]
|
||||
if args[0] > 1:
|
||||
args = args[args[0]:]
|
||||
else:
|
||||
args = args[1:]
|
||||
return ".".join(str(arg) for arg in args)
|
||||
|
||||
def mask2cidr(mask):
|
||||
addr = mask.split(".")
|
||||
cidr = 0
|
||||
for i in addr:
|
||||
cidr += bin(int(i)).count("1")
|
||||
return cidr
|
||||
|
||||
# Obtener los parámetros de red de la interfaz por defecto.
|
||||
def getNetworkSettings():
|
||||
# Arrays globales definidas:
|
||||
# - DEVICE: nombres de dispositivos de red activos.
|
||||
# - SERVERIP: IPs locales del servidor.
|
||||
# - NETIP: IPs de redes.
|
||||
# - NETMASK: máscaras de red.
|
||||
# - NETBROAD: IPs de difusión de redes.
|
||||
# - ROUTERIP: IPs de routers.
|
||||
# Otras variables globales:
|
||||
# - DEFAULTDEV: dispositivo de red por defecto.
|
||||
# - DNSIP: IP del servidor DNS principal.
|
||||
|
||||
DEVICE = []
|
||||
SERVERIP = []
|
||||
NETIP = []
|
||||
NETMASK = []
|
||||
NETBROAD = []
|
||||
ROUTERIP = []
|
||||
|
||||
print("getNetworkSettings(): Detecting network parameters.")
|
||||
output = subprocess.check_output(["ip", "-o", "link", "show", "up"]).decode("utf-8")
|
||||
lines = output.strip().split("\n")
|
||||
for line in lines:
|
||||
dev = line.split(":")[1].split("@")[0].strip()
|
||||
print("DEV:", dev)
|
||||
output = subprocess.check_output(["ip", "-o", "addr", "show", "dev", dev]).decode("utf-8")
|
||||
addr_lines = output.strip().split("\n")
|
||||
for addr_line in addr_lines:
|
||||
addr_parts = addr_line.split()
|
||||
# Por aquí revisar lógica en caso de que haya una interfaz de red sin IP para que no reviente
|
||||
if len(addr_parts) >= 4 and addr_parts[2] == "inet":
|
||||
SERVERIP.append(addr_parts[3].split("/")[0])
|
||||
NETMASK.append(cidr2mask(int(addr_parts[3].split("/")[1])))
|
||||
NETBROAD.append(addr_parts[5])
|
||||
NETIP.append(subprocess.check_output(["ip", "route", "list", "proto", "kernel"]).decode("utf-8").split()[0])
|
||||
print("NETIP:", NETIP[-1])
|
||||
ROUTERIP.append(subprocess.check_output(["ip", "route", "list", "default"]).decode("utf-8").split()[2])
|
||||
if DHCPNET == NETIP[-1]:
|
||||
print("DHCPNET:", NETIP[-1], "if yes")
|
||||
DEFAULTDEV = dev
|
||||
else:
|
||||
print("DHCPNET:", NETIP[-1], "if no")
|
||||
DEFAULTDEV = DEFAULTDEV if "DEFAULTDEV" in locals() else dev
|
||||
# Habria que añadir logica para el caso en el que no este systemd-resolve para que a continuación busque en /etc/resolv.conf
|
||||
# output = subprocess.check_output(["systemd-resolve", "--status"]).decode("utf-8")
|
||||
# dns_servers = output.split("DNS Servers:")[1].split()[0]
|
||||
# DNSIP = dns_servers if dns_servers else open("/etc/resolv.conf").read().splitlines()[0].split()[1]
|
||||
|
||||
if not NETIP or not NETMASK:
|
||||
print("Error: Network not detected.")
|
||||
exit(1)
|
||||
|
||||
print("getNetworkSettings(): Default network device:", DEFAULTDEV)
|
||||
|
||||
# Print variable names and values
|
||||
print("DEVICE:", DEVICE)
|
||||
print("SERVERIP:", SERVERIP)
|
||||
print("NETIP:", NETIP)
|
||||
print("NETMASK:", NETMASK)
|
||||
print("NETBROAD:", NETBROAD)
|
||||
print("ROUTERIP:", ROUTERIP)
|
||||
print("DEFAULTDEV:", DEFAULTDEV)
|
||||
# print("DNSIP:", DNSIP)
|
||||
|
||||
|
||||
def openGnsysConfigure():
|
||||
DEVICE = []
|
||||
SERVERIP = []
|
||||
DEFAULTDEV = ""
|
||||
APACHE_RUN_USER = ""
|
||||
APACHE_RUN_GROUP = ""
|
||||
OPENGNSYS_CONSOLEURL = ""
|
||||
|
||||
i = 0
|
||||
dev = ""
|
||||
CONSOLEURL = ""
|
||||
|
||||
# Mientras networkConfigure no funcione, utilizar una variable global que apunte al servidor Opengnsys
|
||||
# Para nuetra demo 172.17.8.82
|
||||
print(f"{openGnsysConfigure.__name__}(): Creating OpenGnsys config files.")
|
||||
for dev in DEVICE:
|
||||
if SERVERIP[i]:
|
||||
CONSOLEURL = f"https://{SERVERIP[i]}/opengnsys"
|
||||
with open(f"{WORKDIR}/opengnsys/admin/Sources/Clients/ogAdmClient/ogAdmClient.cfg") as file:
|
||||
content = file.read()
|
||||
content = content.replace("SERVERIP", SERVERIP[i])
|
||||
content = content.replace("OPENGNSYSURL", CONSOLEURL.replace("/", "\\/"))
|
||||
with open(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{dev}.cfg", "w") as outfile:
|
||||
outfile.write(content)
|
||||
if dev == DEFAULTDEV:
|
||||
OPENGNSYS_CONSOLEURL = CONSOLEURL
|
||||
i += 1
|
||||
|
||||
os.link(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg")
|
||||
|
||||
TZ = subprocess.check_output(["timedatectl", "status"]).decode().split("\n")[2].split(":")[1].strip()
|
||||
with open(f"{INSTALL_TARGET}/client/etc/engine.cfg", "a") as file:
|
||||
file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ.replace(' ', '')}\"\n")
|
||||
|
||||
print(f"{openGnsysConfigure.__name__}(): OpenGnsys config files created.")
|
||||
|
||||
def mount_NFS():
|
||||
if subprocess.call(["sudo", "mount", "-t", "nfs", "ognartefactos.evlt.uma.es:/", "/mnt"]) == 0:
|
||||
print("Sistema NFS montado correctamente.")
|
||||
|
@ -663,6 +837,11 @@ autoConfigure()
|
|||
Missing = get_missing_packages (required_packages_18)
|
||||
install_packages(Missing)
|
||||
|
||||
# Detectar parámetros de red y comprobar si hay conexión.
|
||||
if getNetworkSettings() != 0:
|
||||
errorAndLog("Error reading default network settings.")
|
||||
exit(1)
|
||||
|
||||
if REMOTE == 1:
|
||||
downloadCode(GIT_REPO)
|
||||
if os.system("echo $?") != 0:
|
||||
|
@ -685,6 +864,23 @@ if os.system("echo $?") != 0:
|
|||
# Configuración de TFTP.
|
||||
tftpConfigure()
|
||||
|
||||
# Compilar código fuente de los servicios de OpenGnsys.
|
||||
servicesCompilation()
|
||||
if subprocess.run(["echo", "$?"]).returncode != 0:
|
||||
errorAndLog("Error while compiling OpenGnsys services")
|
||||
exit(1)
|
||||
|
||||
# Copiar carpeta Interface entre administración y motor de clonación.
|
||||
copyInterfaceAdm()
|
||||
if subprocess.run(["echo", "$?"]).returncode != 0:
|
||||
errorAndLog("Error while copying Administration Interface")
|
||||
exit(1)
|
||||
|
||||
# Crear la estructura de los accesos al servidor desde el cliente (shared)
|
||||
copyClientFiles()
|
||||
if subprocess.run(["echo", "$?"]).returncode != 0:
|
||||
errorAndLog("Error creating client structure")
|
||||
|
||||
generate_ipxe_script()
|
||||
|
||||
# Montar sistema NFS.
|
||||
|
|
Loading…
Reference in New Issue