refs #1113 InterfaceAdm function call updates
parent
2d94e3742e
commit
150685fe75
|
@ -1,8 +1,9 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import NetLib
|
||||||
#!/usr/bin/env python3
|
import SystemLib
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
|
@ -10,35 +11,35 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
mode = sys.argv[1]
|
mode = sys.argv[1]
|
||||||
repo_ip = og_get_repo_ip()
|
repo_ip = NetLib.ogGetRepoIp()
|
||||||
|
|
||||||
if not repo_ip:
|
if not repo_ip:
|
||||||
og_raise_error("OG_ERR_NOTFOUND", "repo no montado")
|
SystemLib.ogRaiseError("OG_ERR_NOTFOUND", "repo no montado")
|
||||||
|
|
||||||
if og_is_repo_locked():
|
if SystemLib.ogIsRepoLocked():
|
||||||
og_raise_error("OG_ERR_LOCKED", f"repo {repo_ip}")
|
SystemLib.ogRaiseError("OG_ERR_LOCKED", f"repo {repo_ip}")
|
||||||
|
|
||||||
proto = os.getenv("ogprotocol", "smb")
|
proto = os.getenv("ogprotocol", "smb")
|
||||||
if proto not in ["nfs", "smb"]:
|
if proto not in ["nfs", "smb"]:
|
||||||
og_raise_error("OG_ERR_FORMAT", f"protocolo desconocido {proto}")
|
SystemLib.ogRaiseError("OG_ERR_FORMAT", f"protocolo desconocido {proto}")
|
||||||
|
|
||||||
if mode == "admin":
|
if mode == "admin":
|
||||||
mount_mode = "rw"
|
mount_mode = "rw"
|
||||||
elif mode == "user":
|
elif mode == "user":
|
||||||
mount_mode = "ro"
|
mount_mode = "ro"
|
||||||
else:
|
else:
|
||||||
og_raise_error("OG_ERR_FORMAT", f"modo desconocido {mode}")
|
SystemLib.ogRaiseError("OG_ERR_FORMAT", f"modo desconocido {mode}")
|
||||||
|
|
||||||
ogimg = os.getenv("OGIMG", "/mnt/ogimg")
|
OGIMG = os.getenv("OGIMG", "/mnt/OGIMG")
|
||||||
ogunit = os.getenv("ogunit", "")
|
OGUNIT = os.getenv("OGUNIT", "")
|
||||||
if ogunit:
|
if OGUNIT:
|
||||||
ogunit = f"/{ogunit}"
|
OGUNIT = f"/{OGUNIT}"
|
||||||
|
|
||||||
subprocess.run(["umount", ogimg], check=True)
|
subprocess.run(["umount", OGIMG], check=True)
|
||||||
og_echo("info", f"Montar repositorio {repo_ip} por {proto} en modo {mode}")
|
SystemLib.ogEcho("info", f"Montar repositorio {repo_ip} por {proto} en modo {mode}")
|
||||||
|
|
||||||
if proto == "nfs":
|
if proto == "nfs":
|
||||||
subprocess.run(["mount", "-t", "nfs", f"{repo_ip}:{ogimg}{ogunit}", ogimg, "-o", mount_mode], check=True)
|
subprocess.run(["mount", "-t", "nfs", f"{repo_ip}:{OGIMG}{OGUNIT}", OGIMG, "-o", mount_mode], check=True)
|
||||||
elif proto == "smb":
|
elif proto == "smb":
|
||||||
with open("/scripts/ogfunctions", "r") as f:
|
with open("/scripts/ogfunctions", "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
@ -47,7 +48,7 @@ def main():
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
pass_option = "og"
|
pass_option = "og"
|
||||||
subprocess.run(["mount.cifs", f"//{repo_ip}/ogimages{ogunit}", ogimg, "-o", f"{mount_mode},serverino,acl,username=opengnsys,password={pass_option}"], check=True)
|
subprocess.run(["mount.cifs", f"//{repo_ip}/ogimages{OGUNIT}", OGIMG, "-o", f"{mount_mode},serverino,acl,username=opengnsys,password={pass_option}"], check=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -1,9 +1,9 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import SystemLib
|
||||||
|
|
||||||
# Load engine configurator from engine.cfg file.
|
# Load engine configurator from engine.cfg file.
|
||||||
# Carga el configurador del engine desde el fichero engine.cfg
|
|
||||||
og_engine_configurate = os.getenv('OGENGINECONFIGURATE')
|
og_engine_configurate = os.getenv('OGENGINECONFIGURATE')
|
||||||
if not og_engine_configurate:
|
if not og_engine_configurate:
|
||||||
with open('/opt/opengnsys/client/etc/engine.cfg') as f:
|
with open('/opt/opengnsys/client/etc/engine.cfg') as f:
|
||||||
|
@ -40,14 +40,14 @@ if og_log_command:
|
||||||
|
|
||||||
print("og_log_session", og_log_session)
|
print("og_log_session", og_log_session)
|
||||||
# Registro de inicio de ejecución
|
# Registro de inicio de ejecución
|
||||||
def og_echo(log_type, message):
|
def SystemLib.ogEcho(log_type, message):
|
||||||
# Implement the logging function here
|
# Implement the logging function here
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print("os.getenv('MSG_INTERFACE_START')", os.getenv('MSG_INTERFACE_START'))
|
print("os.getenv('MSG_INTERFACE_START')", os.getenv('MSG_INTERFACE_START'))
|
||||||
msg_interface_start = os.getenv('MSG_INTERFACE_START')
|
msg_interface_start = os.getenv('MSG_INTERFACE_START')
|
||||||
if msg_interface_start:
|
if msg_interface_start:
|
||||||
og_echo('log', f"session {msg_interface_start} {__name__} {' '.join(os.sys.argv[1:])}")
|
SystemLib.ogEcho('log', f"session {msg_interface_start} {__name__} {' '.join(os.sys.argv[1:])}")
|
||||||
|
|
||||||
# Solo ejecutable por OpenGnsys Client.
|
# Solo ejecutable por OpenGnsys Client.
|
||||||
path = os.getenv('PATH')
|
path = os.getenv('PATH')
|
||||||
|
|
|
@ -2,18 +2,8 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import NetLib
|
||||||
# Error codes
|
import ogGlobals
|
||||||
OG_ERR_NOTEXEC = 1
|
|
||||||
OG_ERR_LOCKED = 4
|
|
||||||
OG_ERR_FORMAT = 1
|
|
||||||
OG_ERR_PARTITION = 3
|
|
||||||
OG_ERR_IMAGE = 5
|
|
||||||
OG_ERR_NOTWRITE = 14
|
|
||||||
OG_ERR_NOTCACHE = 15
|
|
||||||
OG_ERR_CACHESIZE = 16
|
|
||||||
OG_ERR_REDUCEFS = 17
|
|
||||||
OG_ERR_EXTENDFS = 18
|
|
||||||
|
|
||||||
def load_engine_config():
|
def load_engine_config():
|
||||||
engine_config_path = "/opt/opengnsys/etc/engine.cfg"
|
engine_config_path = "/opt/opengnsys/etc/engine.cfg"
|
||||||
|
@ -27,20 +17,10 @@ def clear_temp_logs():
|
||||||
open(f"{os.getenv('OGLOGCOMMAND')}.tmp", 'w').close()
|
open(f"{os.getenv('OGLOGCOMMAND')}.tmp", 'w').close()
|
||||||
|
|
||||||
def log_session_start(script_name, args):
|
def log_session_start(script_name, args):
|
||||||
ogEcho("log session", f"{os.getenv('MSG_INTERFACE_START')} {script_name} {' '.join(args)}")
|
SystemLib.ogEcho("log session", f"{os.getenv('MSG_INTERFACE_START')} {script_name} {' '.join(args)}")
|
||||||
|
|
||||||
def log_session_end(retval):
|
def log_session_end(retval):
|
||||||
ogEcho("log session", f"{os.getenv('MSG_INTERFACE_END')} {retval}")
|
SystemLib.ogEcho("log session", f"{os.getenv('MSG_INTERFACE_END')} {retval}")
|
||||||
|
|
||||||
def ogEcho(*args):
|
|
||||||
print(" ".join(args))
|
|
||||||
|
|
||||||
def ogRaiseError(error_code, message):
|
|
||||||
print(f"Error {error_code}: {message}", file=sys.stderr)
|
|
||||||
return error_code
|
|
||||||
|
|
||||||
def ogGetIpAddress():
|
|
||||||
return subprocess.check_output(["hostname", "-I"]).decode().strip()
|
|
||||||
|
|
||||||
def ogCheckIpAddress(ip):
|
def ogCheckIpAddress(ip):
|
||||||
try:
|
try:
|
||||||
|
@ -49,14 +29,6 @@ def ogCheckIpAddress(ip):
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def ogChangeRepo(repo, unit):
|
|
||||||
# Placeholder for actual implementation
|
|
||||||
return True
|
|
||||||
|
|
||||||
def CambiarAcceso(mode):
|
|
||||||
# Placeholder for actual implementation
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def create_image(disk_num, partition_num, repo, image_name):
|
def create_image(disk_num, partition_num, repo, image_name):
|
||||||
if subprocess.call(["which", "createImageCustom"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0:
|
if subprocess.call(["which", "createImageCustom"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0:
|
||||||
return subprocess.call(["createImageCustom", disk_num, partition_num, repo, f"/{image_name}"])
|
return subprocess.call(["createImageCustom", disk_num, partition_num, repo, f"/{image_name}"])
|
||||||
|
@ -65,7 +37,7 @@ def create_image(disk_num, partition_num, repo, image_name):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 5:
|
if len(sys.argv) != 5:
|
||||||
sys.exit(ogRaiseError(OG_ERR_FORMAT, "Incorrect number of arguments"))
|
sys.exit(SystemLib.ogRaiseError(OG_ERR_FORMAT, "Incorrect number of arguments"))
|
||||||
|
|
||||||
disk_num, partition_num, image_name, repo = sys.argv[1:5]
|
disk_num, partition_num, image_name, repo = sys.argv[1:5]
|
||||||
|
|
||||||
|
@ -76,13 +48,13 @@ def main():
|
||||||
log_session_start(sys.argv[0], sys.argv[1:])
|
log_session_start(sys.argv[0], sys.argv[1:])
|
||||||
|
|
||||||
repo = repo if repo else "REPO"
|
repo = repo if repo else "REPO"
|
||||||
if repo == ogGetIpAddress():
|
if repo == NetLib.ogGetIpAddress():
|
||||||
repo = "CACHE"
|
repo = "CACHE"
|
||||||
|
|
||||||
if ogCheckIpAddress(repo) == 0 or repo == "REPO":
|
if ogCheckIpAddress(repo) == 0 or repo == "REPO":
|
||||||
ogunit = os.getenv('ogunit', "")
|
OGUNIT = os.getenv('OGUNIT', "")
|
||||||
if not ogChangeRepo(repo, ogunit):
|
if not NetLib.ogChangeRepo(repo, OGUNIT):
|
||||||
sys.exit(ogRaiseError(OG_ERR_NOTFOUND, f"{repo}"))
|
sys.exit(SystemLib.ogRaiseError(OG_ERR_NOTFOUND, f"{repo}"))
|
||||||
|
|
||||||
if repo == "REPO" and os.getenv('boot') != "admin":
|
if repo == "REPO" and os.getenv('boot') != "admin":
|
||||||
retval = CambiarAcceso("admin")
|
retval = CambiarAcceso("admin")
|
||||||
|
|
|
@ -2,11 +2,10 @@ import os
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import SystemLib
|
||||||
|
import ogGlobals
|
||||||
|
|
||||||
os.environ.setdefault('MSG_INTERFACE_START', 'Inicio de la interfaz')
|
#sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||||
|
|
||||||
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
|
||||||
from SystemLib import ogEcho
|
|
||||||
|
|
||||||
def main(script_path):
|
def main(script_path):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
@ -25,7 +24,7 @@ def main(script_path):
|
||||||
f.write("")
|
f.write("")
|
||||||
|
|
||||||
# Registro de inicio de ejecución
|
# Registro de inicio de ejecución
|
||||||
ogEcho('log session', f"{os.environ['MSG_INTERFACE_START']} {sys.argv[0]} {' '.join(sys.argv[1:])}")
|
SystemLib.ogEcho('log session', f"{os.environ['MSG_INTERFACE_START']} {sys.argv[0]} {' '.join(sys.argv[1:])}")
|
||||||
|
|
||||||
with open(os.environ['OGLOGFILE'], 'a') as log_file:
|
with open(os.environ['OGLOGFILE'], 'a') as log_file:
|
||||||
log_file.write("\n Instrucciones a ejecutar: *****************************\n"
|
log_file.write("\n Instrucciones a ejecutar: *****************************\n"
|
||||||
|
@ -45,13 +44,13 @@ def main(script_path):
|
||||||
|
|
||||||
elapsed_time = time.time() - start_time
|
elapsed_time = time.time() - start_time
|
||||||
if ret_val == 0:
|
if ret_val == 0:
|
||||||
ogEcho('log session', f"[100] Duracion de la operacion {int(elapsed_time // 60)}m {int(elapsed_time % 60)}s")
|
SystemLib.ogEcho('log session', f"[100] Duracion de la operacion {int(elapsed_time // 60)}m {int(elapsed_time % 60)}s")
|
||||||
else:
|
else:
|
||||||
ogRaiseError('log session', ret_val)
|
SystemLib.ogRaiseError('log session', ret_val)
|
||||||
ogEcho('log session', 'error "Operacion no realizada"')
|
SystemLib.ogEcho('log session', 'error "Operacion no realizada"')
|
||||||
|
|
||||||
# Registro de fin de ejecución
|
# Registro de fin de ejecución
|
||||||
ogEcho('log session', f"{os.environ['MSG_INTERFACE_END']} {ret_val}")
|
SystemLib.ogEcho('log session', f"{os.environ['MSG_INTERFACE_END']} {ret_val}")
|
||||||
|
|
||||||
sys.exit(ret_val)
|
sys.exit(ret_val)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
#sys.path.append('/opt/opengnsys/lib/engine/bin')
|
import FileSystemLib
|
||||||
#from DiskLib import ogDiskToDev
|
import DiskLib
|
||||||
#from InventoryLib import ogGetSerialNumber
|
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# No registrar los errores
|
|
||||||
os.environ["DEBUG"] = "no"
|
os.environ["DEBUG"] = "no"
|
||||||
|
|
||||||
# Obtener el número de serie y configuración inicial
|
# Obtener el número de serie y configuración inicial
|
||||||
|
@ -16,40 +13,75 @@ cfg = ""
|
||||||
# Obtener el número de discos
|
# Obtener el número de discos
|
||||||
disks = len(subprocess.getoutput("ogDiskToDev").split())
|
disks = len(subprocess.getoutput("ogDiskToDev").split())
|
||||||
|
|
||||||
# Recorrer discos
|
|
||||||
for dsk in range(1, disks + 1):
|
for dsk in disk_list:
|
||||||
# Número de particiones
|
# Número de particiones
|
||||||
particiones = subprocess.getoutput(f"ogGetPartitionsNumber {dsk}") or "0"
|
particiones = FileSystemLib.ogGetPartitionsNumber(dsk) or "0"
|
||||||
particiones = int(particiones)
|
particiones = int(particiones)
|
||||||
|
|
||||||
# Tipo de tabla de particiones
|
# Tipo de tabla de particiones
|
||||||
ptt = subprocess.getoutput(f"ogGetPartitionTableType {dsk}")
|
ptt = DiskLib.ogGetPartitionTableType(dsk)
|
||||||
ptt_mapping = {"MSDOS": 1, "GPT": 2, "LVM": 3, "ZPOOL": 4}
|
ptt_mapping = {"MSDOS": 1, "GPT": 2, "LVM": 3, "ZPOOL": 4}
|
||||||
ptt = ptt_mapping.get(ptt, 0)
|
ptt = ptt_mapping.get(ptt, 0)
|
||||||
|
|
||||||
# Información de disco (partición 0)
|
# Información de disco (partición 0)
|
||||||
cfg += f"{dsk}:0:{ptt}:::{subprocess.getoutput(f'ogGetDiskSize {dsk}')}:0;"
|
disk_size = DiskLib.ogGetDiskSize(dsk)
|
||||||
|
cfg += f"{dsk}:0:{ptt}:::{disk_size}:0;"
|
||||||
|
|
||||||
# Recorrer particiones
|
# Recorrer particiones
|
||||||
for par in range(1, particiones + 1):
|
for par in range(1, particiones + 1):
|
||||||
# Código del identificador de tipo de partición
|
# Código del identificador de tipo de partición
|
||||||
cod = subprocess.getoutput(f"ogGetPartitionId {dsk} {par} 2>/dev/null")
|
cod = DiskLib.ogGetPartitionId(dsk, par)
|
||||||
|
|
||||||
# Tipo del sistema de ficheros
|
# Tipo del sistema de ficheros
|
||||||
fsi = subprocess.getoutput(f"getFsType {dsk} {par} 2>/dev/null") or "EMPTY"
|
fsi = FileSystemLib.getFsType(dsk, par) or "EMPTY"
|
||||||
|
|
||||||
# Tamaño de la partición
|
# Tamaño de la partición
|
||||||
tam = subprocess.getoutput(f"ogGetPartitionSize {dsk} {par} 2>/dev/null") or "0"
|
tam = DiskLib.ogGetPartitionSize(dsk, par) or "0"
|
||||||
|
|
||||||
# Sistema operativo instalado
|
# Sistema operativo instalado
|
||||||
soi = ""
|
soi = ""
|
||||||
uso = 0
|
uso = 0
|
||||||
if fsi not in ["", "EMPTY", "LINUX-SWAP", "LINUX-LVM", "ZVOL"]:
|
if fsi not in ["", "EMPTY", "LINUX-SWAP", "LINUX-LVM", "ZVOL"]:
|
||||||
if subprocess.getoutput(f"ogMount {dsk} {par} 2>/dev/null"):
|
mount_point = DiskLib.ogMount(dsk, par)
|
||||||
soi = subprocess.getoutput(f"getOsVersion {dsk} {par} 2>/dev/null | cut -f2 -d:")
|
if mount_point:
|
||||||
|
# Obtener la versión del sistema operativo instalado
|
||||||
|
try:
|
||||||
|
# Asumiendo que getOsVersion es una función disponible
|
||||||
|
import OsLib # Debes tener OsLib.py disponible con la función getOsVersion
|
||||||
|
soi_output = OsLib.getOsVersion(dsk, par)
|
||||||
|
except ImportError:
|
||||||
|
# Si no está disponible, usar subprocess como alternativa
|
||||||
|
soi_output = subprocess.getoutput(f"getOsVersion {dsk} {par} 2>/dev/null")
|
||||||
|
|
||||||
|
soi = soi_output.split(':')[1] if ':' in soi_output else ''
|
||||||
|
# Hacer un segundo intento para algunos casos especiales
|
||||||
|
if not soi:
|
||||||
|
soi_output = subprocess.getoutput(f"getOsVersion {dsk} {par} 2>/dev/null")
|
||||||
|
soi = soi_output.split(':')[1] if ':' in soi_output else ''
|
||||||
|
|
||||||
|
# Sistema de archivos para datos (sistema operativo "DATA")
|
||||||
if not soi and fsi not in ["EMPTY", "CACHE"]:
|
if not soi and fsi not in ["EMPTY", "CACHE"]:
|
||||||
soi = "DATA"
|
soi = "DATA"
|
||||||
uso = int(subprocess.getoutput(f"df $(ogGetMountPoint {dsk} {par}) | awk '{{getline; printf \"%d\",$5}}'") or "0")
|
|
||||||
|
# Obtener porcentaje de uso
|
||||||
|
mount_point = DiskLib.ogGetMountPoint(dsk, par)
|
||||||
|
df_output = subprocess.getoutput(f"df {mount_point}")
|
||||||
|
lines = df_output.splitlines()
|
||||||
|
if len(lines) >= 2:
|
||||||
|
uso_str = lines[1].split()[4] # Esta debería ser la quinta columna
|
||||||
|
if uso_str.endswith('%'):
|
||||||
|
uso = int(uso_str.rstrip('%'))
|
||||||
|
else:
|
||||||
|
uso = int(uso_str)
|
||||||
|
else:
|
||||||
|
uso = 0
|
||||||
|
else:
|
||||||
|
soi = ""
|
||||||
|
uso = 0
|
||||||
|
else:
|
||||||
|
soi = ""
|
||||||
|
uso = 0
|
||||||
|
|
||||||
cfg += f"{dsk}:{par}:{cod}:{fsi}:{soi}:{tam}:{uso};"
|
cfg += f"{dsk}:{par}:{cod}:{fsi}:{soi}:{tam}:{uso};"
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
import socket
|
|
||||||
|
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
def get_ip_address():
|
|
||||||
hostname = socket.gethostname()
|
|
||||||
ip_address = socket.gethostbyname(hostname)
|
|
||||||
return ip_address
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print(get_ip_address())
|
|
|
@ -1,5 +1,11 @@
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
def get_ip_address():
|
||||||
|
hostname = socket.gethostname()
|
||||||
|
ip_address = socket.gethostbyname(hostname)
|
||||||
|
return ip_address
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("IP Address:", get_ip_address())
|
print(get_ip_address())
|
||||||
|
|
Loading…
Reference in New Issue