refs #1093 rebuild ogGetServerIp

pull/1/head
Antonio Guerrero 2024-11-13 00:18:17 -06:00
parent c066725bce
commit 3058a3798f
1 changed files with 29 additions and 20 deletions

View File

@ -263,30 +263,39 @@ def ogGetRepoIp():
#@note Comprobacion segun protocolo de conexion al Repo #@note Comprobacion segun protocolo de conexion al Repo
#*/ ## #*/ ##
def ogGetServerIp(): def ogGetServerIp():
# Variables locales. try:
SOURCE = "" output = subprocess.run(
FSTYPE = "" ["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
# Mostrar ayuda. try:
if len(sys.argv) >= 2 and sys.argv[1] == "help": mounts = json.loads(output)
SystemLib.ogHelp("ogGetServerIp", "ogGetServerIp", "ogGetServerIp => 192.168.0.2") except json.decoder.JSONDecodeError:
return SystemLib.ogEcho("session", "error", "Error to decode JSON de findmnt.")
return None
# Obtener direcciones IP, según el tipo de montaje. if 'filesystems' not in mounts or not isinstance(mounts['filesystems'], list):
output = subprocess.run(["findmnt", "-P", "-o", "SOURCE,FSTYPE", OGIMG], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().strip() SystemLib.ogEcho("session", "error", "'filesystems' is not present o not valid in JSON.")
lines = output.split("\n") return None
for line in lines:
fields = line.split()
if len(fields) == 2:
if fields[1] == "nfs":
SOURCE = fields[0].split(":")[0]
elif fields[1] == "cifs":
SOURCE = fields[0].split("/")[2]
if SOURCE: for fs in mounts['filesystems']:
print(SOURCE) if 'source' in fs and 'fstype' in fs:
source = fs['source']
fstype = fs['fstype']
return 0 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
#/** #/**