refs #1101 add ogGetRepoIp()

pull/1/head
Natalia Serrano 2024-11-12 17:48:38 +01:00
parent e8f7996470
commit b245b5b877
1 changed files with 85 additions and 22 deletions

View File

@ -2,9 +2,19 @@ import subprocess
import sys import sys
import os import os
import ogGlobals
import NetLib import NetLib
import SystemLib import SystemLib
#/**
# ogChangeRepo IPREPO [ OgUnit ]
#@brief Cambia el repositorio para el recurso remoto images.
#@param 1 Ip Repositorio
#@param 2 Abreviatura Unidad Organizativa
#@return Cambio recurso remoto en OGIMG.
#*/
def ogChangeRepo(): def ogChangeRepo():
SRCIMG = "" SRCIMG = ""
NEWREPO = "" NEWREPO = ""
@ -62,6 +72,15 @@ def ogChangeRepo():
SystemLib.ogRaiseError("session", OG_ERR_REPO, NEWREPO) SystemLib.ogRaiseError("session", OG_ERR_REPO, NEWREPO)
return subprocess.returncode return subprocess.returncode
#/**
# ogGetGroupDir [ str_repo ]
#@brief Devuelve el camino del directorio para el grupo del cliente.
#@param str_repo repositorio de imágenes (opcional)
#@return path_dir - Camino al directorio del grupo.
#@note repo = { REPO, CACHE } REPO por defecto
#@exception OG_ERR_FORMAT formato incorrecto.
#*/
def ogGetGroupDir(): def ogGetGroupDir():
REPO = "" REPO = ""
DIR = "" DIR = ""
@ -84,6 +103,12 @@ def ogGetGroupDir():
return 0 return 0
#/**
# ogGetGroupName
#@brief Devuelve el nombre del grupo al que pertenece el cliente.
#@return str_group - Nombre de grupo.
#*/
def ogGetGroupName(): def ogGetGroupName():
if len(sys.argv) >= 2 and sys.argv[1] == "help": if len(sys.argv) >= 2 and sys.argv[1] == "help":
SystemLib.ogHelp("ogGetGroupName", "ogGetGroupName", "ogGetGroupName => Grupo1") SystemLib.ogHelp("ogGetGroupName", "ogGetGroupName", "ogGetGroupName => Grupo1")
@ -94,6 +119,12 @@ def ogGetGroupName():
return 0 return 0
#/**
# ogGetHostname
#@brief Muestra el nombre del cliente.
#@return str_host - nombre de máquina
#*/ ##
def ogGetHostname(): def ogGetHostname():
HOST = "" HOST = ""
@ -126,6 +157,13 @@ def ogGetHostname():
if HOST: if HOST:
print(HOST) print(HOST)
#/**
# ogGetIpAddress
#@brief Muestra la dirección IP del sistema
#@return str_ip - Dirección IP
#@note Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
#*/ ##
def ogGetIpAddress(): def ogGetIpAddress():
IP = "" IP = ""
@ -150,6 +188,12 @@ def ogGetIpAddress():
return 0 return 0
#/**
# ogGetMacAddress
#@brief Muestra la dirección Ethernet del cliente.
#@return str_ether - Dirección Ethernet
#*/ ##
def ogGetMacAddress(): def ogGetMacAddress():
MAC = "" MAC = ""
@ -171,6 +215,13 @@ def ogGetMacAddress():
return 0 return 0
#/**
# ogGetNetInterface
#@brief Muestra la interfaz de red del sistema
#@return str_interface - interfaz de red
#@note Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
#*/ ##
def ogGetNetInterface(): def ogGetNetInterface():
if len(sys.argv) >= 2 and sys.argv[1] == "help": if len(sys.argv) >= 2 and sys.argv[1] == "help":
SystemLib.ogHelp("ogGetNetInterface", "ogGetNetInterface", "ogGetNetInterface => eth0") SystemLib.ogHelp("ogGetNetInterface", "ogGetNetInterface", "ogGetNetInterface => eth0")
@ -181,32 +232,35 @@ def ogGetNetInterface():
return 0 return 0
def ogRepoIp():
# Variables locales.
SOURCE = ""
FSTYPE = ""
# Mostrar ayuda. #/**
if len(sys.argv) >= 2 and sys.argv[1] == "help": # ogGetRepoIp
SystemLib.ogHelp("ogRepoIp", "ogRepoIp", "ogRepoIp => 192.168.0.2") #@brief Muestra la dirección IP del repositorio de datos.
return #@return str_ip - Dirección IP
#*/ ##
def ogGetRepoIp():
out = subprocess.run (["findmnt", "--json", "--output", "SOURCE,FSTYPE", ogGlobals.OGIMG], capture_output=True, text=True).stdout
try:
j = json.loads (out)
except json.decoder.JSONDecodeError:
return None
# Obtener direcciones IP, según el tipo de montaje. if 'filesystems' not in j: return None
output = subprocess.run(["findmnt", "-P", "-o", "SOURCE,FSTYPE", OGIMG], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().strip() source = j['filesystems']['source']
lines = output.split("\n") fstype = j['filesystems']['fstype']
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: if 'nfs' == fstype: return source.split(":")[0]
print(SOURCE) elif 'cifs' == fstype: return source.split("/")[2]
return 0 return None
#/**
# ogGetServerIp
#@brief Muestra la dirección IP del Servidor de OpenGnSys.
#@return str_ip - Dirección IP
#@note Comprobacion segun protocolo de conexion al Repo
#*/ ##
def ogGetServerIp(): def ogGetServerIp():
# Variables locales. # Variables locales.
SOURCE = "" SOURCE = ""
@ -233,6 +287,15 @@ def ogGetServerIp():
return 0 return 0
#/**
# ogMakeGroupDir [ str_repo ]
#@brief Crea el directorio para el grupo del cliente.
#@param str_repo repositorio de imágenes (opcional)
#@return (nada)
#@note repo = { REPO, CACHE } REPO por defecto
#@exception OG_ERR_FORMAT formato incorrecto.
#*/
def ogMakeGroupDir(): def ogMakeGroupDir():
REPO = "" REPO = ""
DIR = "" DIR = ""