From 3133096f2bf2c8de04c70c3f3209d727a4c8cfb3 Mon Sep 17 00:00:00 2001 From: Nikola Dipanov Date: Thu, 7 Mar 2013 15:54:07 +0100 Subject: Libvirt driver create images even without meta This patch allows the libvirt driver to call _create_image and create instance directory and other needed images even when there is no image metadata specified. As an added bonus, this patch refactors the code of _create_image method a bit to make it more clear to the reader when some of the images will and will not be created, especially with regard to booting from volume. Fixes bug: 1124441 Fixes bug: 1131913 Fixes bug: 1123274 blueprint: improve-boot-from-volume Change-Id: I5a028dc0585876d35be4fb86df3a423d89e054ee --- nova/virt/libvirt/driver.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 7960da90f..5e6b0e742 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1507,13 +1507,14 @@ class LibvirtDriver(driver.ComputeDriver): xml = self.to_xml(instance, network_info, disk_info, image_meta, block_device_info=block_device_info) - if image_meta: - self._create_image(context, instance, xml, - disk_info['mapping'], - network_info=network_info, - block_device_info=block_device_info, - files=injected_files, - admin_pass=admin_password) + + self._create_image(context, instance, xml, + disk_info['mapping'], + network_info=network_info, + block_device_info=block_device_info, + files=injected_files, + admin_pass=admin_password) + self._create_domain_and_network(xml, instance, network_info, block_device_info) LOG.debug(_("Instance is running"), instance=instance) @@ -1725,6 +1726,11 @@ class LibvirtDriver(driver.ComputeDriver): if not suffix: suffix = '' + booted_from_volume = ( + (not bool(instance.get('image_ref'))) + or 'disk' not in disk_mapping + ) + # syntactic nicety def basepath(fname='', suffix=suffix): return os.path.join(libvirt_utils.get_instance_path(instance), @@ -1772,14 +1778,18 @@ class LibvirtDriver(driver.ComputeDriver): user_id=instance['user_id'], project_id=instance['project_id']) - root_fname = imagecache.get_cache_fname(disk_images, 'image_id') - size = instance['root_gb'] * 1024 * 1024 * 1024 - inst_type = instance_types.extract_instance_type(instance) - if size == 0 or suffix == '.rescue': - size = None - if 'disk' in disk_mapping: + # NOTE(ndipanov): Even if disk_mapping was passed in, which + # currently happens only on rescue - we still don't want to + # create a base image. + if not booted_from_volume: + root_fname = imagecache.get_cache_fname(disk_images, 'image_id') + size = instance['root_gb'] * 1024 * 1024 * 1024 + + if size == 0 or suffix == '.rescue': + size = None + image('disk').cache(fetch_func=libvirt_utils.fetch_image, context=context, filename=root_fname, -- cgit