refs #1678 add interfaceAdm/InventarioHardware.py
parent
2d0c77b073
commit
e89143bab2
|
@ -1,33 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
#!/usr/bin/python3
|
||||
# Script de interfaz para guardar en un fichero el inventario de hardware de un cliente.
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
def main(output_file):
|
||||
# Ejecutar el comando `listHardwareInfo.py` y capturar el resultado
|
||||
try:
|
||||
print(f"------------------------------------------ loading listHardwareInfo.py")
|
||||
result = subprocess.run(
|
||||
["python3", "/opt/opengnsys/scripts/listHardwareInfo.py"],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
output_lines = result.stdout.strip().split('\n')
|
||||
file_path = output_lines[-1] # Obtener la última línea como la ruta del archivo de salida
|
||||
print(f"------------------------------------------ archivo:{file_path}")
|
||||
import ogGlobals
|
||||
from SystemLib import ogRaiseError
|
||||
|
||||
# Leer desde la segunda línea del archivo y escribir en el archivo de salida especificado
|
||||
with open(file_path, 'r') as input_file, open(output_file, 'w') as output:
|
||||
lines = input_file.readlines()[1:] # Saltar la primera línea
|
||||
output.writelines(lines)
|
||||
prog = sys.argv[0]
|
||||
if len (sys.argv) != 2:
|
||||
print (f'Usage: {prog} <output_file>')
|
||||
sys.exit (1)
|
||||
output_file = sys.argv[1]
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error ejecutando listHardwareInfo.py:", e.stderr, file=sys.stderr)
|
||||
sys.exit(e.returncode)
|
||||
except FileNotFoundError as e:
|
||||
print(f"Archivo no encontrado: {e.filename}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
listhi_out = subprocess.run ( [f'{ogGlobals.OGSCRIPTS}/listHardwareInfo.py'], capture_output=True, text=True).stdout
|
||||
if listhi_out:
|
||||
inventory_path = listhi_out.splitlines()[0]
|
||||
else:
|
||||
ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, 'listHardwareInfo.py failed')
|
||||
sys.exit (1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Uso: python3 InventarioHardware.py <archivo_salida>")
|
||||
sys.exit(1)
|
||||
main(sys.argv[1])
|
||||
with open (inventory_path, 'r') as fdin, open (output_file, 'w') as fdout:
|
||||
lines = fdin.readlines()[1:] # 'tail -n +2'
|
||||
fdout.writelines (lines)
|
||||
|
|
|
@ -115,7 +115,6 @@ def ogIsEfiActive():
|
|||
def ogListHardwareInfo():
|
||||
ret = ''
|
||||
|
||||
SystemLib.ogEcho ([], 'info', ogGlobals.lang.MSG_HARDWAREINVENTORY)
|
||||
# Ejecutar dmidecode y obtener tipo de chasis
|
||||
dmi_out = subprocess.run (['dmidecode', '-s', 'chassis-type'], capture_output=True, text=True).stdout
|
||||
dmi_out = '\n'.join ([ x for x in dmi_out.splitlines() if 'Other' not in x ])
|
||||
|
|
|
@ -1,43 +1,28 @@
|
|||
import subprocess
|
||||
#!/usr/bin/python3
|
||||
# Scirpt de ejemplo para almacenear en fichero temporal el listado de hardware.
|
||||
# Nota: se usa como base para el programa de recogida de listado de hardware de OpenGnsys Admin.
|
||||
# Formato: listHardwareInfo
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
import subprocess
|
||||
|
||||
import ogGlobals
|
||||
from SystemLib import ogRaiseError
|
||||
from NetLib import ogGetIpAddress
|
||||
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
from InventoryLib import ogListHardwareInfo
|
||||
|
||||
def get_server_log_dir():
|
||||
# Obtener el directorio de logs del servidor
|
||||
oglog = os.getenv("OGLOG")
|
||||
if not oglog:
|
||||
return ""
|
||||
result = subprocess.run(["mount"], capture_output=True, text=True)
|
||||
for line in result.stdout.splitlines():
|
||||
parts = line.split()
|
||||
if len(parts) >= 4 and parts[3] == oglog:
|
||||
return parts[1]
|
||||
return ""
|
||||
prog = sys.argv[0]
|
||||
if len (sys.argv) > 1:
|
||||
ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'{ogGlobals.lang.MSG_FORMAT} {prog}')
|
||||
sys.exit (1)
|
||||
|
||||
def list_hardware_info():
|
||||
oglog = os.getenv("OGLOG", "/tmp") # Usar /tmp como valor por defecto para OGLOG
|
||||
ip_address = ogGetIpAddress()
|
||||
# Fichero de listado de hardware basado en la IP obtenida
|
||||
hardfile = f"hard-{ogGetIpAddress()}"
|
||||
print(f"hardfile:{hardfile}")
|
||||
# Ejecutar ogListHardwareInfo y redirigir al archivo de listado
|
||||
hardware_info_path = os.path.join(oglog, hardfile)
|
||||
with open(hardware_info_path, 'w') as output_file:
|
||||
output_file.write(ogListHardwareInfo())
|
||||
|
||||
return hardware_info_path
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Obtener el directorio del servidor donde se exportan los ficheros de registro
|
||||
server_log_dir = get_server_log_dir()
|
||||
|
||||
# Generar el archivo de listado de hardware y obtener su ruta
|
||||
hardware_info_path = list_hardware_info()
|
||||
|
||||
# Imprimir la ruta del archivo generado
|
||||
print(hardware_info_path)
|
||||
# Directorio del servidor donde se exportan los ficheros de registro.
|
||||
#SERVERLOGDIR = unused
|
||||
|
||||
# Fichero de listado: hard-IP
|
||||
HARDFILE = f'{ogGlobals.OGLOG}/hard-{ogGetIpAddress()}'
|
||||
out = ogListHardwareInfo()
|
||||
with open (HARDFILE, 'w') as fd:
|
||||
fd.write (out)
|
||||
print (HARDFILE)
|
||||
|
|
Loading…
Reference in New Issue