refs #1113 InterfaceAdm function call updates
parent
2d94e3742e
commit
150685fe75
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
#!/usr/bin/env python3
|
||||
import NetLib
|
||||
import SystemLib
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
|
@ -10,35 +11,35 @@ def main():
|
|||
sys.exit(1)
|
||||
|
||||
mode = sys.argv[1]
|
||||
repo_ip = og_get_repo_ip()
|
||||
repo_ip = NetLib.ogGetRepoIp()
|
||||
|
||||
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():
|
||||
og_raise_error("OG_ERR_LOCKED", f"repo {repo_ip}")
|
||||
if SystemLib.ogIsRepoLocked():
|
||||
SystemLib.ogRaiseError("OG_ERR_LOCKED", f"repo {repo_ip}")
|
||||
|
||||
proto = os.getenv("ogprotocol", "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":
|
||||
mount_mode = "rw"
|
||||
elif mode == "user":
|
||||
mount_mode = "ro"
|
||||
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")
|
||||
ogunit = os.getenv("ogunit", "")
|
||||
if ogunit:
|
||||
ogunit = f"/{ogunit}"
|
||||
OGIMG = os.getenv("OGIMG", "/mnt/OGIMG")
|
||||
OGUNIT = os.getenv("OGUNIT", "")
|
||||
if OGUNIT:
|
||||
OGUNIT = f"/{OGUNIT}"
|
||||
|
||||
subprocess.run(["umount", ogimg], check=True)
|
||||
og_echo("info", f"Montar repositorio {repo_ip} por {proto} en modo {mode}")
|
||||
subprocess.run(["umount", OGIMG], check=True)
|
||||
SystemLib.ogEcho("info", f"Montar repositorio {repo_ip} por {proto} en modo {mode}")
|
||||
|
||||
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":
|
||||
with open("/scripts/ogfunctions", "r") as f:
|
||||
for line in f:
|
||||
|
@ -47,7 +48,7 @@ def main():
|
|||
break
|
||||
else:
|
||||
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__":
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import SystemLib
|
||||
|
||||
# Load engine configurator from engine.cfg file.
|
||||
# Carga el configurador del engine desde el fichero engine.cfg
|
||||
og_engine_configurate = os.getenv('OGENGINECONFIGURATE')
|
||||
if not og_engine_configurate:
|
||||
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)
|
||||
# Registro de inicio de ejecución
|
||||
def og_echo(log_type, message):
|
||||
def SystemLib.ogEcho(log_type, message):
|
||||
# Implement the logging function here
|
||||
pass
|
||||
|
||||
print("os.getenv('MSG_INTERFACE_START')", os.getenv('MSG_INTERFACE_START'))
|
||||
msg_interface_start = os.getenv('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.
|
||||
path = os.getenv('PATH')
|
||||
|
@ -143,4 +143,4 @@ subprocess.run(["ogEcho", "log", "session", f"{os.getenv('MSG_INTERFACE_END')} {
|
|||
|
||||
# Return
|
||||
coproc.kill()
|
||||
sys.exit(0)
|
||||
sys.exit(0)
|
||||
|
|
|
@ -2,18 +2,8 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
# Error codes
|
||||
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
|
||||
import NetLib
|
||||
import ogGlobals
|
||||
|
||||
def load_engine_config():
|
||||
engine_config_path = "/opt/opengnsys/etc/engine.cfg"
|
||||
|
@ -27,20 +17,10 @@ def clear_temp_logs():
|
|||
open(f"{os.getenv('OGLOGCOMMAND')}.tmp", 'w').close()
|
||||
|
||||
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):
|
||||
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()
|
||||
SystemLib.ogEcho("log session", f"{os.getenv('MSG_INTERFACE_END')} {retval}")
|
||||
|
||||
def ogCheckIpAddress(ip):
|
||||
try:
|
||||
|
@ -49,14 +29,6 @@ def ogCheckIpAddress(ip):
|
|||
except subprocess.CalledProcessError:
|
||||
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):
|
||||
if subprocess.call(["which", "createImageCustom"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0:
|
||||
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():
|
||||
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]
|
||||
|
||||
|
@ -76,13 +48,13 @@ def main():
|
|||
log_session_start(sys.argv[0], sys.argv[1:])
|
||||
|
||||
repo = repo if repo else "REPO"
|
||||
if repo == ogGetIpAddress():
|
||||
if repo == NetLib.ogGetIpAddress():
|
||||
repo = "CACHE"
|
||||
|
||||
if ogCheckIpAddress(repo) == 0 or repo == "REPO":
|
||||
ogunit = os.getenv('ogunit', "")
|
||||
if not ogChangeRepo(repo, ogunit):
|
||||
sys.exit(ogRaiseError(OG_ERR_NOTFOUND, f"{repo}"))
|
||||
OGUNIT = os.getenv('OGUNIT', "")
|
||||
if not NetLib.ogChangeRepo(repo, OGUNIT):
|
||||
sys.exit(SystemLib.ogRaiseError(OG_ERR_NOTFOUND, f"{repo}"))
|
||||
|
||||
if repo == "REPO" and os.getenv('boot') != "admin":
|
||||
retval = CambiarAcceso("admin")
|
||||
|
@ -98,4 +70,4 @@ def main():
|
|||
sys.exit(retval)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -2,11 +2,10 @@ import os
|
|||
import time
|
||||
import subprocess
|
||||
import sys
|
||||
import SystemLib
|
||||
import ogGlobals
|
||||
|
||||
os.environ.setdefault('MSG_INTERFACE_START', 'Inicio de la interfaz')
|
||||
|
||||
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
from SystemLib import ogEcho
|
||||
#sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
|
||||
def main(script_path):
|
||||
start_time = time.time()
|
||||
|
@ -25,7 +24,7 @@ def main(script_path):
|
|||
f.write("")
|
||||
|
||||
# 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:
|
||||
log_file.write("\n Instrucciones a ejecutar: *****************************\n"
|
||||
|
@ -45,13 +44,13 @@ def main(script_path):
|
|||
|
||||
elapsed_time = time.time() - start_time
|
||||
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:
|
||||
ogRaiseError('log session', ret_val)
|
||||
ogEcho('log session', 'error "Operacion no realizada"')
|
||||
SystemLib.ogRaiseError('log session', ret_val)
|
||||
SystemLib.ogEcho('log session', 'error "Operacion no realizada"')
|
||||
|
||||
# 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)
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
#sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
#from DiskLib import ogDiskToDev
|
||||
#from InventoryLib import ogGetSerialNumber
|
||||
#!/usr/bin/env python3
|
||||
import FileSystemLib
|
||||
import DiskLib
|
||||
|
||||
# No registrar los errores
|
||||
os.environ["DEBUG"] = "no"
|
||||
|
||||
# Obtener el número de serie y configuración inicial
|
||||
|
@ -16,40 +13,75 @@ cfg = ""
|
|||
# Obtener el número de discos
|
||||
disks = len(subprocess.getoutput("ogDiskToDev").split())
|
||||
|
||||
# Recorrer discos
|
||||
for dsk in range(1, disks + 1):
|
||||
|
||||
for dsk in disk_list:
|
||||
# Número de particiones
|
||||
particiones = subprocess.getoutput(f"ogGetPartitionsNumber {dsk}") or "0"
|
||||
particiones = FileSystemLib.ogGetPartitionsNumber(dsk) or "0"
|
||||
particiones = int(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 = ptt_mapping.get(ptt, 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
|
||||
for par in range(1, particiones + 1):
|
||||
# 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
|
||||
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
|
||||
tam = subprocess.getoutput(f"ogGetPartitionSize {dsk} {par} 2>/dev/null") or "0"
|
||||
tam = DiskLib.ogGetPartitionSize(dsk, par) or "0"
|
||||
|
||||
# Sistema operativo instalado
|
||||
soi = ""
|
||||
uso = 0
|
||||
if fsi not in ["", "EMPTY", "LINUX-SWAP", "LINUX-LVM", "ZVOL"]:
|
||||
if subprocess.getoutput(f"ogMount {dsk} {par} 2>/dev/null"):
|
||||
soi = subprocess.getoutput(f"getOsVersion {dsk} {par} 2>/dev/null | cut -f2 -d:")
|
||||
mount_point = DiskLib.ogMount(dsk, par)
|
||||
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"]:
|
||||
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};"
|
||||
|
||||
|
|
|
@ -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())
|
|
@ -15,4 +15,4 @@ if __name__ == "__main__":
|
|||
additional_args = sys.argv[7:]
|
||||
|
||||
exit_code = deploy_image(ip, image_name, disk, partition, protocol, protocol_options, *additional_args)
|
||||
sys.exit(exit_code)
|
||||
sys.exit(exit_code)
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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("IP Address:", get_ip_address())
|
||||
print(get_ip_address())
|
||||
|
|
Loading…
Reference in New Issue