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 ++++++++++++++++-- nova/virt/libvirt_conn.py | 15 +++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) 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 diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 58a5a941c..7250d31e5 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -329,10 +329,10 @@ class LibvirtConnection(object): if not os.path.exists(basepath('ramdisk')): yield images.fetch(inst.ramdisk_id, basepath('ramdisk'), user, project) - execute = lambda cmd, process_input=None: \ + execute = lambda cmd, process_input=None, check_exit_code=True: \ process.simple_execute(cmd=cmd, process_input=process_input, - check_exit_code=True) + check_exit_code=check_exit_code) key = str(inst['key_data']) net = None @@ -359,10 +359,13 @@ class LibvirtConnection(object): if os.path.exists(basepath('disk')): yield process.simple_execute('rm -f %s' % basepath('disk')) - bytes = (instance_types.INSTANCE_TYPES[inst.instance_type]['local_gb'] - * 1024 * 1024 * 1024) - yield disk.partition( - basepath('disk-raw'), basepath('disk'), bytes, execute=execute) + local_bytes = (instance_types.INSTANCE_TYPES[inst.instance_type] + ['local_gb'] + * 1024 * 1024 * 1024) + + resize = inst['instance_type'] != 'm1.tiny' + yield disk.partition(basepath('disk-raw'), basepath('disk'), + local_bytes, resize, execute=execute) if FLAGS.libvirt_type == 'uml': yield process.simple_execute('sudo chown root %s' % -- 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(-) 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