refs #1596 add initCache.py
parent
4b4d004743
commit
7c9fbc014f
|
@ -64,8 +64,9 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0):
|
||||||
if ENDPREVPART: break
|
if ENDPREVPART: break
|
||||||
i += 1
|
i += 1
|
||||||
if not ENDPREVPART:
|
if not ENDPREVPART:
|
||||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, ndsk)
|
ENDPREVPART=0
|
||||||
return None
|
#SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, ndsk)
|
||||||
|
#return None
|
||||||
# Error si tamaño no está entre límites permitidos o si se solapa con la partición anterior.
|
# Error si tamaño no está entre límites permitidos o si se solapa con la partición anterior.
|
||||||
MINSIZE = 25000
|
MINSIZE = 25000
|
||||||
MAXSIZE = END
|
MAXSIZE = END
|
||||||
|
@ -245,7 +246,7 @@ def ogGetCacheSize():
|
||||||
cachepart = ogFindCache()
|
cachepart = ogFindCache()
|
||||||
if cachepart is None:
|
if cachepart is None:
|
||||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, ogGlobals.lang.MSG_NOCACHE)
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, ogGlobals.lang.MSG_NOCACHE)
|
||||||
return
|
return None
|
||||||
|
|
||||||
disk, par = cachepart.split()
|
disk, par = cachepart.split()
|
||||||
return DiskLib.ogGetPartitionSize (disk, par)
|
return DiskLib.ogGetPartitionSize (disk, par)
|
||||||
|
@ -321,7 +322,7 @@ def ogMountCache():
|
||||||
m = FileSystemLib.ogMountFs (c[0], c[1])
|
m = FileSystemLib.ogMountFs (c[0], c[1])
|
||||||
if not m:
|
if not m:
|
||||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, ogGlobals.lang.MSG_NOCACHE)
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, ogGlobals.lang.MSG_NOCACHE)
|
||||||
#return
|
return None
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,94 +1,123 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# Scirpt de iniciación de la caché local de disco.
|
||||||
|
# Nota: se usa como base para el programa de configuración de equipos de OpenGnsys Admin).
|
||||||
|
# Formato: initCache [int_ndisk [int_npart]] {-1 | 0 | int_size} [NOMOUNT]
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import ogGlobals
|
||||||
import SystemLib
|
import SystemLib
|
||||||
import FileSystemLib
|
import FileSystemLib
|
||||||
import CacheLib
|
import CacheLib
|
||||||
import DiskLib
|
import DiskLib
|
||||||
|
|
||||||
#!/usr/bin/env python3
|
def main (NDISK, NPART, SIZE, MOUNT):
|
||||||
|
|
||||||
def main():
|
|
||||||
TIME1 = time.time()
|
TIME1 = time.time()
|
||||||
PROG = sys.argv[0]
|
|
||||||
EXECFORMAT = f"{PROG} [int_ndisk [int_npart]] {{-1 | 0 | int_size}} [NOMOUNT]"
|
|
||||||
|
|
||||||
args = sys.argv[1:]
|
# Si tamaño=0, no hacer nada.
|
||||||
if args and args[-1].upper() == "NOMOUNT":
|
if 0 == SIZE:
|
||||||
MOUNT = 0
|
|
||||||
args = args[:-1]
|
|
||||||
else:
|
|
||||||
MOUNT = 1
|
|
||||||
|
|
||||||
PARAMS = len(args)
|
|
||||||
if PARAMS == 1:
|
|
||||||
NDISK = 1
|
|
||||||
NPART = 4
|
|
||||||
SIZE = int(args[0])
|
|
||||||
elif PARAMS == 2:
|
|
||||||
NDISK = int(args[0])
|
|
||||||
NPART = 4
|
|
||||||
SIZE = int(args[1])
|
|
||||||
elif PARAMS == 3:
|
|
||||||
NDISK = int(args[0])
|
|
||||||
NPART = int(args[1])
|
|
||||||
SIZE = int(args[2])
|
|
||||||
else:
|
|
||||||
SystemLib.ogRaiseError("OG_ERR_FORMAT", f"{EXECFORMAT}")
|
|
||||||
|
|
||||||
if NDISK < 1 or NPART < 1:
|
|
||||||
SystemLib.ogRaiseError("OG_ERR_FORMAT", f"{EXECFORMAT}")
|
|
||||||
|
|
||||||
if SIZE < -1:
|
|
||||||
SystemLib.ogRaiseError("OG_ERR_FORMAT", f"{EXECFORMAT}")
|
|
||||||
|
|
||||||
if SIZE == 0:
|
|
||||||
print("No modificar la caché local.")
|
print("No modificar la caché local.")
|
||||||
return
|
return True
|
||||||
|
|
||||||
if SIZE == -1:
|
# Si tamaño=-1, borrar caché.
|
||||||
|
if -1 == SIZE:
|
||||||
print("[10] Trabajar sin caché local.")
|
print("[10] Trabajar sin caché local.")
|
||||||
CacheLib.ogUnmountCache()
|
CacheLib.ogUnmountCache()
|
||||||
CacheLib.ogDeleteCache()
|
CacheLib.ogDeleteCache()
|
||||||
else:
|
else:
|
||||||
|
# Si la caché actual está definida en otro disco y partición, se elimina.
|
||||||
current_cache = CacheLib.ogFindCache()
|
current_cache = CacheLib.ogFindCache()
|
||||||
if current_cache and f"{NDISK} {NPART}" != current_cache:
|
if current_cache and f"{NDISK} {NPART}" != current_cache:
|
||||||
print("[10] Detectada otra caché, eliminarla")
|
print("[10] Detectada otra caché, eliminarla")
|
||||||
CacheLib.ogUnmountCache()
|
CacheLib.ogUnmountCache()
|
||||||
CacheLib.ogDeleteCache()
|
CacheLib.ogDeleteCache()
|
||||||
|
|
||||||
try:
|
# Tomamos el tamaño actual. Si no existe cache será 0.
|
||||||
OLDSIZE = CacheLib.ogGetCacheSize()
|
CACHESIZE = CacheLib.ogGetCacheSize()
|
||||||
except ValueError:
|
if not CACHESIZE: CACHESIZE = 0 ## may be None
|
||||||
OLDSIZE = 0
|
|
||||||
|
|
||||||
|
# Error si tamaño definido no es >0.
|
||||||
if SIZE <= 0:
|
if SIZE <= 0:
|
||||||
SystemLib.ogRaiseError("OG_ERR_FORMAT", f"!({SIZE}>0)")
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f"!({SIZE}>0)")
|
||||||
|
return False
|
||||||
|
|
||||||
if SIZE != OLDSIZE:
|
# Si no existe caché o si cambia su tamaño, crearla.
|
||||||
|
if SIZE != CACHESIZE:
|
||||||
print("[10] Crear partición de caché local.")
|
print("[10] Crear partición de caché local.")
|
||||||
CacheLib.ogUnmountCache()
|
CacheLib.ogUnmountCache()
|
||||||
CacheLib.ogCreateCache (NDISK, NPART, SIZE)
|
CacheLib.ogCreateCache (NDISK, NPART, SIZE)
|
||||||
DiskLib.ogUpdatePartitionTable(NDISK)
|
DiskLib.ogUpdatePartitionTable()
|
||||||
|
|
||||||
|
# Si caché no montada y no formateada o cambia el tamaño: formatear.
|
||||||
cache = CacheLib.ogFindCache()
|
cache = CacheLib.ogFindCache()
|
||||||
if not FileSystemLib.ogIsFormated(cache) or SIZE != OLDSIZE:
|
if not cache:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTCACHE, '')
|
||||||
|
return False
|
||||||
|
cache = cache.split()
|
||||||
|
if not FileSystemLib.ogIsFormated (cache[0], cache[1]) or SIZE != CACHESIZE:
|
||||||
print("[50] Formatear caché local.")
|
print("[50] Formatear caché local.")
|
||||||
CacheLib.ogFormatCache()
|
CacheLib.ogFormatCache()
|
||||||
|
|
||||||
print("[70] Comprobar montaje de caché local.")
|
print("[70] Comprobar montaje de caché local.")
|
||||||
if CacheLib.ogMountCache() != 0:
|
# Si error al montar, chequear sistema de archivos y volver a montar.
|
||||||
|
if not CacheLib.ogMountCache():
|
||||||
print("[80] Comprobar consistencia y volver a montar caché local.")
|
print("[80] Comprobar consistencia y volver a montar caché local.")
|
||||||
FileSystem.ogCheckFs(cache)
|
FileSystem.ogCheckFs (cache[0], cache[1])
|
||||||
if CacheLib.ogMountCache() != 0:
|
if not CacheLib.ogMountCache():
|
||||||
sys.exit(1)
|
return False
|
||||||
|
|
||||||
if MOUNT == 0:
|
# Dejar desmontada la caché si se ha solicitado.
|
||||||
|
if not MOUNT:
|
||||||
print("[90] Dejar desmontada la caché local.")
|
print("[90] Dejar desmontada la caché local.")
|
||||||
CacheLib.ogUnmountCache()
|
CacheLib.ogUnmountCache()
|
||||||
|
|
||||||
|
# Duración del proceso.
|
||||||
TIME = time.time() - TIME1
|
TIME = time.time() - TIME1
|
||||||
print (f"[100] Duración de la operación {int(TIME // 60)}m {int(TIME % 60)}s")
|
print (f"[100] Duración de la operación {int(TIME // 60)}m {int(TIME % 60)}s")
|
||||||
|
return True
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
PROG = sys.argv[0]
|
||||||
|
EXECFORMAT = f"{PROG} [int_ndisk [int_npart]] {{-1 | 0 | int_size}} [NOMOUNT]"
|
||||||
|
|
||||||
|
args = sys.argv[1:]
|
||||||
|
if args and 'NOMOUNT' == args[-1].upper():
|
||||||
|
MOUNT = False
|
||||||
|
args = args[:-1]
|
||||||
|
else:
|
||||||
|
MOUNT = True
|
||||||
|
|
||||||
|
PARAMS = len (args)
|
||||||
|
try:
|
||||||
|
if 1 == PARAMS:
|
||||||
|
NDISK = 1
|
||||||
|
NPART = 4
|
||||||
|
SIZE = int (args[0])
|
||||||
|
elif 2 == PARAMS:
|
||||||
|
NDISK = int (args[0])
|
||||||
|
NPART = 4
|
||||||
|
SIZE = int (args[1])
|
||||||
|
elif 3 == PARAMS:
|
||||||
|
NDISK = int (args[0])
|
||||||
|
NPART = int (args[1])
|
||||||
|
SIZE = int (args[2])
|
||||||
|
else:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
|
||||||
|
sys.exit (1)
|
||||||
|
except ValueError:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
|
||||||
|
sys.exit (1)
|
||||||
|
|
||||||
|
# Si disco o partición no son mayores o iguales que 1, error.
|
||||||
|
if NDISK < 1 or NPART < 1:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
|
||||||
|
sys.exit (1)
|
||||||
|
|
||||||
|
# Si tamaño no es numérico o tamaño<-1, error.
|
||||||
|
if SIZE < -1:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, EXECFORMAT)
|
||||||
|
sys.exit (1)
|
||||||
|
|
||||||
|
rc = main (NDISK, NPART, SIZE, MOUNT)
|
||||||
|
sys.exit (not rc)
|
||||||
|
|
Loading…
Reference in New Issue