summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-10-20 02:49:28 +0000
committerTarmac <>2010-10-20 02:49:28 +0000
commit9145feeed99b02a2798fde909a2abe8d900b522c (patch)
tree0de90bf3de670dc5c84ee13beb663fb2e17a872e
parent38dd6ffabaaf6130b7f810f4cbf45d1cd5202205 (diff)
parent03a74592ed2dba8d82432fb7eaa76c9dce2351c8 (diff)
downloadnova-9145feeed99b02a2798fde909a2abe8d900b522c.tar.gz
nova-9145feeed99b02a2798fde909a2abe8d900b522c.tar.xz
nova-9145feeed99b02a2798fde909a2abe8d900b522c.zip
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.
-rw-r--r--nova/compute/disk.py18
-rw-r--r--nova/virt/libvirt_conn.py15
2 files changed, 25 insertions, 8 deletions
diff --git a/nova/compute/disk.py b/nova/compute/disk.py
index c340c5a79..447a29004 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_integer('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' %