refs #1496 add ogGetDiskSize
parent
e12cc1150f
commit
b4fe9232ba
|
@ -595,30 +595,27 @@ def ogDiskToDev (arg_disk=None, arg_part=None):
|
||||||
#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
|
#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
|
||||||
#@note Requisitos: sfdisk, awk
|
#@note Requisitos: sfdisk, awk
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def ogGetDiskSize(*args):
|
def ogGetDiskSize (disk):
|
||||||
# Variables locales
|
DISK = ogDiskToDev (disk)
|
||||||
DISK = SIZE = None
|
if not DISK: return None
|
||||||
|
|
||||||
# Si se solicita, mostrar ayuda.
|
bn = os.path.basename (DISK)
|
||||||
if len(args) == 1 and args[0] == "help":
|
SIZE = None
|
||||||
SystemLib.ogHelp('ogGetDiskSize', 'ogGetDiskSize int_ndisk', 'ogGetDiskSize 1 => 244198584')
|
with open ('/proc/partitions', 'r') as fd:
|
||||||
return
|
while True:
|
||||||
|
l = fd.readline()
|
||||||
|
if not l: break
|
||||||
|
items = l.split()
|
||||||
|
if len(items) < 4: continue
|
||||||
|
if items[3] == bn:
|
||||||
|
SIZE = int (items[2])
|
||||||
|
break
|
||||||
|
if not SIZE:
|
||||||
|
vgs_out = subprocess.run (['vgs', '--noheadings', '--units=B', '-o', 'dev_size', DISK], capture_output=True, text=True).stdout
|
||||||
|
items = vgs_out.split()
|
||||||
|
SIZE = int (items[0]) // 1024
|
||||||
|
|
||||||
# Error si no se recibe 1 parámetro.
|
return SIZE
|
||||||
if len(args) != 1:
|
|
||||||
SystemLib.ogRaiseError(OG_ERR_FORMAT)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Obtener el tamaño del disco.
|
|
||||||
DISK = ogDiskToDev(args[0])
|
|
||||||
if DISK is None:
|
|
||||||
return
|
|
||||||
SIZE = subprocess.getoutput(f"lsblk -n -b -o SIZE {DISK}")
|
|
||||||
|
|
||||||
# Mostrar salida.
|
|
||||||
if SIZE:
|
|
||||||
print(SIZE)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from DiskLib import ogGetDiskSize
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogGetDiskSize', 'ogGetDiskSize int_ndisk', ['ogGetDiskSize 1'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
ret = ogGetDiskSize (args.disk)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
Loading…
Reference in New Issue