refs #1219 add ogConfigureOgagent()

code-review
Natalia Serrano 2024-12-04 16:13:38 +01:00
parent bcc1e7bbe1
commit 1332b0b8bc
2 changed files with 47 additions and 31 deletions

View File

@ -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 ]

View File

@ -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)
#/**