diff --git a/dom0/qvm-core/qubesutils.py b/dom0/qvm-core/qubesutils.py index 2c77238f..5d65cff6 100644 --- a/dom0/qvm-core/qubesutils.py +++ b/dom0/qvm-core/qubesutils.py @@ -70,6 +70,23 @@ def size_to_human (size): else: return str(round(size/(1024.0*1024*1024),1)) + ' GiB' +def parse_size(size): + units = [ ('K', 1024), ('KB', 1024), + ('M', 1024*1024), ('MB', 1024*1024), + ('G', 1024*1024*1024), ('GB', 1024*1024*1024), + ] + + size = size.strip().upper() + if size.isdigit(): + return size + + for unit, multiplier in units: + if size.endswith(unit): + size = size[:-len(unit)].strip() + return int(size)*multiplier + + raise QubesException("Invalid size: {0}.".format(size)) + def print_stdout(text): print (text) diff --git a/dom0/qvm-tools/qvm-grow-private b/dom0/qvm-tools/qvm-grow-private index ffa114ae..5e778c1c 100755 --- a/dom0/qvm-tools/qvm-grow-private +++ b/dom0/qvm-tools/qvm-grow-private @@ -22,6 +22,7 @@ from qubes.qubes import QubesVmCollection from qubes.qubes import QubesException +from qubesutils import parse_size from optparse import OptionParser import subprocess import os @@ -30,24 +31,6 @@ import sys qvm_run_path = "/usr/bin/qvm-run" -def parse_size(size): - units = [ ('K', 1024), ('KB', 1024), - ('M', 1024*1024), ('MB', 1024*1024), - ('G', 1024*1024*1024), ('GB', 1024*1024*1024), - ] - - size = size.strip().upper() - if size.isdigit(): - return size - - for unit, multiplier in units: - if size.endswith(unit): - size = size[:-len(unit)].strip() - return int(size)*multiplier - - print >> sys.stderr, "Invalid size: {0}.".format(size) - exit(1) - def main(): usage = "usage: %prog " parser = OptionParser (usage)