'Creates virtual disk from an image which is a flat extent.'

def _create_virtual_disk_from_preallocated_image(self, context, image_service, image_id, image_size_in_bytes, dest_dc_ref, dest_ds_name, dest_folder_path, dest_disk_name, adapter_type):

    (dc_ref, ds_name, folder_path) = self._get_temp_image_folder(image_size_in_bytes)
    if ((ds_name == dest_ds_name) and (dc_ref.value == dest_dc_ref.value)):
        path = volumeops.FlatExtentVirtualDiskPath(dest_ds_name, dest_folder_path, dest_disk_name)
        dest_path = path
    else:
        disk_name = uuidutils.generate_uuid()
        path = volumeops.FlatExtentVirtualDiskPath(ds_name, folder_path, disk_name)
        dest_path = volumeops.FlatExtentVirtualDiskPath(dest_ds_name, dest_folder_path, dest_disk_name)
    LOG.debug('Creating    virtual    disk:    %(path)s    from    (flat    extent)    image:    %(image_id)s.', {'path': path.get_descriptor_ds_file_path(), 'image_id': image_id})
    self.volumeops.create_flat_extent_virtual_disk_descriptor(dc_ref, path, (image_size_in_bytes // units.Ki), adapter_type, EAGER_ZEROED_THICK_VMDK_TYPE)
    try:
        self._copy_image(context, dc_ref, image_service, image_id, image_size_in_bytes, ds_name, path.get_flat_extent_file_path())
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.exception('Error    occurred    while    copying    image:    %(image_id)s    to    %(path)s.', {'path': path.get_descriptor_ds_file_path(), 'image_id': image_id})
            LOG.debug('Deleting    descriptor:    %s.', path.get_descriptor_ds_file_path())
            try:
                self.volumeops.delete_file(path.get_descriptor_ds_file_path(), dc_ref)
            except exceptions.VimException:
                LOG.warning('Error    occurred    while    deleting    descriptor:    %s.', path.get_descriptor_ds_file_path(), exc_info=True)
    if (dest_path != path):
        self._copy_temp_virtual_disk(dc_ref, path, dest_dc_ref, dest_path)
    LOG.debug('Created    virtual    disk:    %s    from    flat    extent    image.', dest_path.get_descriptor_ds_file_path())
    return dest_path
