def _create_image(self, context, instance, disk_mapping, suffix='', disk_images=None, network_info=None, block_device_info=None, files=None, admin_pass=None, inject_files=True):
    if (not suffix):
        suffix = ''
    booted_from_volume = self._is_booted_from_volume(instance, disk_mapping)

    def image(fname, image_type=CONF.libvirt.images_type):
        return self.image_backend.image(instance, (fname + suffix), image_type)

    def raw(fname):
        return image(fname, image_type='raw')
    fileutils.ensure_tree(libvirt_utils.get_instance_path(instance))
    LOG.info(_LI('Creating image'), instance=instance)
    self._chown_console_log_for_instance(instance)
    self._chown_disk_config_for_instance(instance)
    libvirt_utils.write_to_file(self._get_console_log_path(instance), '', 7)
    if (not disk_images):
        disk_images = {'image_id': instance['image_ref'], 'kernel_id': instance['kernel_id'], 'ramdisk_id': instance['ramdisk_id']}
    if disk_images['kernel_id']:
        fname = imagecache.get_cache_fname(disk_images, 'kernel_id')
        raw('kernel').cache(fetch_func=libvirt_utils.fetch_image, context=context, filename=fname, image_id=disk_images['kernel_id'], user_id=instance['user_id'], project_id=instance['project_id'])
        if disk_images['ramdisk_id']:
            fname = imagecache.get_cache_fname(disk_images, 'ramdisk_id')
            raw('ramdisk').cache(fetch_func=libvirt_utils.fetch_image, context=context, filename=fname, image_id=disk_images['ramdisk_id'], user_id=instance['user_id'], project_id=instance['project_id'])
    inst_type = flavors.extract_flavor(instance)
    if (not booted_from_volume):
        root_fname = imagecache.get_cache_fname(disk_images, 'image_id')
        size = (instance['root_gb'] * units.Gi)
        if ((size == 0) or (suffix == '.rescue')):
            size = None
        backend = image('disk')
        if backend.SUPPORTS_CLONE:

            def clone_fallback_to_fetch(*args, **kwargs):
                try:
                    backend.clone(context, disk_images['image_id'])
                except exception.ImageUnacceptable:
                    libvirt_utils.fetch_image(*args, **kwargs)
            fetch_func = clone_fallback_to_fetch
        else:
            fetch_func = libvirt_utils.fetch_image
        backend.cache(fetch_func=fetch_func, context=context, filename=root_fname, size=size, image_id=disk_images['image_id'], user_id=instance['user_id'], project_id=instance['project_id'])
    os_type_with_default = disk.get_fs_type_for_os_type(instance['os_type'])
    ephemeral_gb = instance['ephemeral_gb']
    if ('disk.local' in disk_mapping):
        disk_image = image('disk.local')
        fn = functools.partial(self._create_ephemeral, fs_label='ephemeral0', os_type=instance['os_type'], is_block_dev=disk_image.is_block_dev)
        fname = ('ephemeral_%s_%s' % (ephemeral_gb, os_type_with_default))
        size = (ephemeral_gb * units.Gi)
        disk_image.cache(fetch_func=fn, filename=fname, size=size, ephemeral_size=ephemeral_gb)
    for (idx, eph) in enumerate(driver.block_device_info_get_ephemerals(block_device_info)):
        disk_image = image(blockinfo.get_eph_disk(idx))
        specified_fs = eph.get('guest_format')
        if (specified_fs and (not self.is_supported_fs_format(specified_fs))):
            msg = (_('%s format is not supported') % specified_fs)
            raise exception.InvalidBDMFormat(details=msg)
        fn = functools.partial(self._create_ephemeral, fs_label=('ephemeral%d' % idx), os_type=instance['os_type'], is_block_dev=disk_image.is_block_dev)
        size = (eph['size'] * units.Gi)
        fname = ('ephemeral_%s_%s' % (eph['size'], os_type_with_default))
        disk_image.cache(fetch_func=fn, filename=fname, size=size, ephemeral_size=eph['size'], specified_fs=specified_fs)
    if ('disk.swap' in disk_mapping):
        mapping = disk_mapping['disk.swap']
        swap_mb = 0
        swap = driver.block_device_info_get_swap(block_device_info)
        if driver.swap_is_usable(swap):
            swap_mb = swap['swap_size']
        elif ((inst_type['swap'] > 0) and (not block_device.volume_in_mapping(mapping['dev'], block_device_info))):
            swap_mb = inst_type['swap']
        if (swap_mb > 0):
            size = (swap_mb * units.Mi)
            image('disk.swap').cache(fetch_func=self._create_swap, filename=('swap_%s' % swap_mb), size=size, swap_mb=swap_mb)
    if configdrive.required_by(instance):
        LOG.info(_LI('Using config drive'), instance=instance)
        extra_md = {}
        if admin_pass:
            extra_md['admin_pass'] = admin_pass
        inst_md = instance_metadata.InstanceMetadata(instance, content=files, extra_md=extra_md, network_info=network_info)
        with configdrive.ConfigDriveBuilder(instance_md=inst_md) as cdb:
            configdrive_path = self._get_disk_config_path(instance, suffix)
            LOG.info(_LI('Creating config drive at %(path)s'), {'path': configdrive_path}, instance=instance)
            try:
                cdb.make_drive(configdrive_path)
            except processutils.ProcessExecutionError as e:
                with excutils.save_and_reraise_exception():
                    LOG.error(_LE('Creating config drive failed with error: %s'), e, instance=instance)
    elif (inject_files and (CONF.libvirt.inject_partition != (- 2))):
        if booted_from_volume:
            LOG.warn(_LW('File injection into a boot from volume instance is not supported'), instance=instance)
        self._inject_data(instance, network_info, admin_pass, files, suffix)
    if (CONF.libvirt.virt_type == 'uml'):
        libvirt_utils.chown(image('disk').path, 'root')
def _create_image(self, context, instance, disk_mapping, suffix=, disk_images=None, network_info=None, block_device_info=None, files=None, admin_pass=None, inject_files=True):
    if (not suffix):
        suffix = 
    booted_from_volume = self._is_booted_from_volume(instance, disk_mapping)

    def image(fname, image_type=CONF.libvirt.images_type):
        return self.image_backend.image(instance, (fname + suffix), image_type)

    def raw(fname):
        return image(fname, image_type='raw')
    fileutils.ensure_tree(libvirt_utils.get_instance_path(instance))
    LOG.info(_LI('Creating image'), instance=instance)
    self._chown_console_log_for_instance(instance)
    self._chown_disk_config_for_instance(instance)
    libvirt_utils.write_to_file(self._get_console_log_path(instance), , 7)
    if (not disk_images):
        disk_images = {'image_id': instance['image_ref'], 'kernel_id': instance['kernel_id'], 'ramdisk_id': instance['ramdisk_id']}
    if disk_images['kernel_id']:
        fname = imagecache.get_cache_fname(disk_images, 'kernel_id')
        raw('kernel').cache(fetch_func=libvirt_utils.fetch_image, context=context, filename=fname, image_id=disk_images['kernel_id'], user_id=instance['user_id'], project_id=instance['project_id'])
        if disk_images['ramdisk_id']:
            fname = imagecache.get_cache_fname(disk_images, 'ramdisk_id')
            raw('ramdisk').cache(fetch_func=libvirt_utils.fetch_image, context=context, filename=fname, image_id=disk_images['ramdisk_id'], user_id=instance['user_id'], project_id=instance['project_id'])
    inst_type = flavors.extract_flavor(instance)
    if (not booted_from_volume):
        root_fname = imagecache.get_cache_fname(disk_images, 'image_id')
        size = (instance['root_gb'] * units.Gi)
        if ((size == 0) or (suffix == '.rescue')):
            size = None
        backend = image('disk')
        if backend.SUPPORTS_CLONE:

            def clone_fallback_to_fetch(*args, **kwargs):
                try:
                    backend.clone(context, disk_images['image_id'])
                except exception.ImageUnacceptable:
                    libvirt_utils.fetch_image(*args, **kwargs)
            fetch_func = clone_fallback_to_fetch
        else:
            fetch_func = libvirt_utils.fetch_image
        backend.cache(fetch_func=fetch_func, context=context, filename=root_fname, size=size, image_id=disk_images['image_id'], user_id=instance['user_id'], project_id=instance['project_id'])
    os_type_with_default = disk.get_fs_type_for_os_type(instance['os_type'])
    ephemeral_gb = instance['ephemeral_gb']
    if ('disk.local' in disk_mapping):
        disk_image = image('disk.local')
        fn = functools.partial(self._create_ephemeral, fs_label='ephemeral0', os_type=instance['os_type'], is_block_dev=disk_image.is_block_dev)
        fname = ('ephemeral_%s_%s' % (ephemeral_gb, os_type_with_default))
        size = (ephemeral_gb * units.Gi)
        disk_image.cache(fetch_func=fn, filename=fname, size=size, ephemeral_size=ephemeral_gb)
    for (idx, eph) in enumerate(driver.block_device_info_get_ephemerals(block_device_info)):
        disk_image = image(blockinfo.get_eph_disk(idx))
        specified_fs = eph.get('guest_format')
        if (specified_fs and (not self.is_supported_fs_format(specified_fs))):
            msg = (_('%s format is not supported') % specified_fs)
            raise exception.InvalidBDMFormat(details=msg)
        fn = functools.partial(self._create_ephemeral, fs_label=('ephemeral%d' % idx), os_type=instance['os_type'], is_block_dev=disk_image.is_block_dev)
        size = (eph['size'] * units.Gi)
        fname = ('ephemeral_%s_%s' % (eph['size'], os_type_with_default))
        disk_image.cache(fetch_func=fn, filename=fname, size=size, ephemeral_size=eph['size'], specified_fs=specified_fs)
    if ('disk.swap' in disk_mapping):
        mapping = disk_mapping['disk.swap']
        swap_mb = 0
        swap = driver.block_device_info_get_swap(block_device_info)
        if driver.swap_is_usable(swap):
            swap_mb = swap['swap_size']
        elif ((inst_type['swap'] > 0) and (not block_device.volume_in_mapping(mapping['dev'], block_device_info))):
            swap_mb = inst_type['swap']
        if (swap_mb > 0):
            size = (swap_mb * units.Mi)
            image('disk.swap').cache(fetch_func=self._create_swap, filename=('swap_%s' % swap_mb), size=size, swap_mb=swap_mb)
    if configdrive.required_by(instance):
        LOG.info(_LI('Using config drive'), instance=instance)
        extra_md = {}
        if admin_pass:
            extra_md['admin_pass'] = admin_pass
        inst_md = instance_metadata.InstanceMetadata(instance, content=files, extra_md=extra_md, network_info=network_info)
        with configdrive.ConfigDriveBuilder(instance_md=inst_md) as cdb:
            configdrive_path = self._get_disk_config_path(instance, suffix)
            LOG.info(_LI('Creating config drive at %(path)s'), {'path': configdrive_path}, instance=instance)
            try:
                cdb.make_drive(configdrive_path)
            except processutils.ProcessExecutionError as e:
                with excutils.save_and_reraise_exception():
                    LOG.error(_LE('Creating config drive failed with error: %s'), e, instance=instance)
    elif (inject_files and (CONF.libvirt.inject_partition != (- 2))):
        if booted_from_volume:
            LOG.warn(_LW('File injection into a boot from volume instance is not supported'), instance=instance)
        self._inject_data(instance, network_info, admin_pass, files, suffix)
    if (CONF.libvirt.virt_type == 'uml'):
        libvirt_utils.chown(image('disk').path, 'root')