From 1332b0b8bcdb86e2c510681b5f2366e9784ee155 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 4 Dec 2024 16:13:38 +0100 Subject: [PATCH] refs #1219 add ogConfigureOgagent() --- client/lib/engine/bin/NetLib.py | 42 ++++++++-------------------- client/lib/engine/bin/PostConfLib.py | 36 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/client/lib/engine/bin/NetLib.py b/client/lib/engine/bin/NetLib.py index 7bfe7d1..e36f863 100755 --- a/client/lib/engine/bin/NetLib.py +++ b/client/lib/engine/bin/NetLib.py @@ -272,39 +272,19 @@ def ogGetRepoIp(): #@note Comprobacion segun protocolo de conexion al Repo #*/ ## def ogGetServerIp(): - try: - output = subprocess.run( - ["findmnt", "--json", "--output", "SOURCE,FSTYPE", ogGlobals.OGIMG], - capture_output=True, - text=True, - check=True - ).stdout - except subprocess.CalledProcessError as e: - SystemLib.ogEcho("session", "error", f"Error to run findmnt: {e.stderr}") - return None + return os.environ['ogcore'] - try: - mounts = json.loads(output) - except json.decoder.JSONDecodeError: - SystemLib.ogEcho("session", "error", "Error to decode JSON de findmnt.") - return None +#/** +# ogGetServerPort +#@brief Muestra el puerto del Servidor de OpenGnSys. +#@return str_port - Puerto +#*/ ## +def ogGetServerPort(): + if 'ogcore_port' in os.environ: + return os.environ['ogcore_port'] + else: + return '8443' - if 'filesystems' not in mounts or not isinstance(mounts['filesystems'], list): - SystemLib.ogEcho("session", "error", "'filesystems' is not present o not valid in JSON.") - return None - - for fs in mounts['filesystems']: - if 'source' in fs and 'fstype' in fs: - source = fs['source'] - fstype = fs['fstype'] - - if fstype == "nfs": - return source.split(":")[0] - elif fstype == "cifs": - return source.split("/")[2] - - SystemLib.ogEcho("session", "info", "No valid file system found") - return None #/** # ogMakeGroupDir [ str_repo ] diff --git a/client/lib/engine/bin/PostConfLib.py b/client/lib/engine/bin/PostConfLib.py index d840f2a..3033d11 100644 --- a/client/lib/engine/bin/PostConfLib.py +++ b/client/lib/engine/bin/PostConfLib.py @@ -9,7 +9,11 @@ import os import subprocess +import ogGlobals +import SystemLib import FileSystemLib +import FileLib +import NetLib #/** # ogCleanOs int_ndisk int_nfilesys @@ -98,6 +102,38 @@ import FileSystemLib #@exception OG_ERR_NOTFOUND Fichero o dispositivo no encontrado. #@exception OG_ERR_LOCKED Sistema de archivos bloqueado. #*/ ## +def ogConfigureOgagent (disk, par): + mntdir = FileSystemLib.ogMount (disk, par) + if not mntdir: + return + + for agentdir in ['usr/share/OGAgent', 'Program Files/OGAgent', 'Program Files (x86)/OGAgent', 'Applications/OGAgent.app']: + cfgfile = FileLib.ogGetPath (file=f'{mntdir}/{agentdir}/cfg/ogagent.cfg') + if cfgfile: break + + if not cfgfile: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, 'ogagent.cfg') + return + + ogcore_scheme = 'https' + ogcore_ip = NetLib.ogGetServerIp() + ogcore_port = NetLib.ogGetServerPort() + cfgfile_patched = cfgfile + '.patched' + in_opengnsys_section = False + with open (cfgfile, 'r') as fdin: + with open (cfgfile_patched, 'w') as fdout: + while True: + lineout = linein = fdin.readline() + if not linein: break + if in_opengnsys_section: + if 'remote' == linein[0:6]: + lineout = f'remote={ogcore_scheme}://{ogcore_ip}:{ogcore_port}/opengnsys/rest/\n' + if '[' == linein[0:1]: + in_opengnsys_section = False + if '[opengnsys]' == linein[0:11]: + in_opengnsys_section = True + fdout.write (lineout) + os.rename (cfgfile_patched, cfgfile) #/**