89 lines
3.0 KiB
Python
89 lines
3.0 KiB
Python
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
|
|
|
|
# No registrar los errores
|
|
os.environ["DEBUG"] = "no"
|
|
|
|
# Obtener el número de serie y configuración inicial
|
|
ser = subprocess.getoutput("ogGetSerialNumber")
|
|
cfg = ""
|
|
|
|
# Obtener el número de discos
|
|
disks = len(subprocess.getoutput("ogDiskToDev").split())
|
|
|
|
# Recorrer discos
|
|
for dsk in range(1, disks + 1):
|
|
# Número de particiones
|
|
particiones = subprocess.getoutput(f"ogGetPartitionsNumber {dsk}") or "0"
|
|
particiones = int(particiones)
|
|
|
|
# Tipo de tabla de particiones
|
|
ptt = subprocess.getoutput(f"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;"
|
|
|
|
# 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")
|
|
|
|
# Tipo del sistema de ficheros
|
|
fsi = subprocess.getoutput(f"getFsType {dsk} {par} 2>/dev/null") or "EMPTY"
|
|
|
|
# Tamaño de la partición
|
|
tam = subprocess.getoutput(f"ogGetPartitionSize {dsk} {par} 2>/dev/null") 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:")
|
|
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")
|
|
|
|
cfg += f"{dsk}:{par}:{cod}:{fsi}:{soi}:{tam}:{uso};"
|
|
|
|
# Configuración por defecto para cliente sin disco
|
|
if not cfg:
|
|
cfg = "1:0:0:::0;"
|
|
|
|
# Guardar salida en fichero temporal
|
|
cfgfile = "/tmp/getconfig"
|
|
with open(cfgfile, 'w') as f:
|
|
f.write(f"{ser + ';' if ser else ''}{cfg}")
|
|
|
|
# Crear el menú por defecto desde el archivo generado
|
|
subprocess.run(["generateMenuDefault"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
# Componer salida formateada
|
|
formatted_output = []
|
|
with open(cfgfile, 'r') as f:
|
|
content = f.read().strip().split(";")
|
|
for item in content:
|
|
fields = item.split(":")
|
|
if len(fields) == 1:
|
|
formatted_output.append(f"ser={fields[0]}")
|
|
else:
|
|
formatted_output.append(
|
|
f"disk={fields[0]}\tpar={fields[1]}\tcpt={fields[2]}\tfsi={fields[3]}\tsoi={fields[4]}\ttam={fields[5]}\tuso={fields[6]}"
|
|
)
|
|
|
|
# Mostrar la salida formateada
|
|
print("\n".join(formatted_output))
|
|
|
|
# Borrar marcas de arranque de Windows
|
|
subprocess.run(["rm", "-f", "/mnt/*/ogboot.*", "/mnt/*/*/ogboot.*"])
|
|
|
|
# Volver a registrar los errores
|
|
os.environ.pop("DEBUG", None)
|