From 3ef13339a003d6799dd303c7764606c76c5fb1ad Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 18 Oct 2010 13:32:45 -0700 Subject: Makes disk.partition resize root drive to 10G, unless it is m1.tiny which just leaves it as is. Larger images are just used as is. --- nova/compute/disk.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/disk.py b/nova/compute/disk.py index c340c5a79..8d2198b67 100644 --- a/nova/compute/disk.py +++ b/nova/compute/disk.py @@ -28,10 +28,17 @@ import tempfile from twisted.internet import defer from nova import exception +from nova import flags + + +FLAGS = flags.FLAGS +FLAGS.define_int('minimum_root_size', 1024 * 1024 * 1024 * 10, + 'minimum size in bytes of root partition') @defer.inlineCallbacks -def partition(infile, outfile, local_bytes=0, local_type='ext2', execute=None): +def partition(infile, outfile, local_bytes=0, resize=True, + local_type='ext2', execute=None): """Takes a single partition represented by infile and writes a bootable drive image into outfile. @@ -49,7 +56,14 @@ def partition(infile, outfile, local_bytes=0, local_type='ext2', execute=None): """ sector_size = 512 file_size = os.path.getsize(infile) - if file_size % sector_size != 0: + if resize and file_size < FLAGS.minimum_root_size: + last_sector = FLAGS.minimum_root_size / sector_size - 1 + yield execute('dd if=/dev/zero of=%s count=1 seek=%d bs=%d' + % (infile, last_sector, sector_size)) + yield execute('e2fsck -fp %s' % infile, check_exit_code=False) + yield execute('resize2fs %s' % infile) + file_size = FLAGS.minimum_root_size + elif file_size % sector_size != 0: logging.warn("Input partition size not evenly divisible by" " sector size: %d / %d", file_size, sector_size) primary_sectors = file_size / sector_size -- cgit From 03a74592ed2dba8d82432fb7eaa76c9dce2351c8 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 18 Oct 2010 13:40:03 -0700 Subject: it is flags.DEFINE_integer, not FLAGS.define_int --- nova/compute/disk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/disk.py b/nova/compute/disk.py index 8d2198b67..447a29004 100644 --- a/nova/compute/disk.py +++ b/nova/compute/disk.py @@ -32,8 +32,8 @@ from nova import flags FLAGS = flags.FLAGS -FLAGS.define_int('minimum_root_size', 1024 * 1024 * 1024 * 10, - 'minimum size in bytes of root partition') +flags.DEFINE_integer('minimum_root_size', 1024 * 1024 * 1024 * 10, + 'minimum size in bytes of root partition') @defer.inlineCallbacks -- cgit