refs #1093 rebuild ogGetServerIp
parent
c066725bce
commit
3058a3798f
|
@ -263,30 +263,39 @@ def ogGetRepoIp():
|
|||
#@note Comprobacion segun protocolo de conexion al Repo
|
||||
#*/ ##
|
||||
def ogGetServerIp():
|
||||
# Variables locales.
|
||||
SOURCE = ""
|
||||
FSTYPE = ""
|
||||
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
|
||||
|
||||
# Mostrar ayuda.
|
||||
if len(sys.argv) >= 2 and sys.argv[1] == "help":
|
||||
SystemLib.ogHelp("ogGetServerIp", "ogGetServerIp", "ogGetServerIp => 192.168.0.2")
|
||||
return
|
||||
try:
|
||||
mounts = json.loads(output)
|
||||
except json.decoder.JSONDecodeError:
|
||||
SystemLib.ogEcho("session", "error", "Error to decode JSON de findmnt.")
|
||||
return None
|
||||
|
||||
# Obtener direcciones IP, según el tipo de montaje.
|
||||
output = subprocess.run(["findmnt", "-P", "-o", "SOURCE,FSTYPE", OGIMG], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().strip()
|
||||
lines = output.split("\n")
|
||||
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 '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
|
||||
|
||||
if SOURCE:
|
||||
print(SOURCE)
|
||||
for fs in mounts['filesystems']:
|
||||
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
|
||||
|
||||
|
||||
#/**
|
||||
|
|
Loading…
Reference in New Issue