'Creates volume from image.
This method only supports Glance image of VMDK disk format.
Uses flat vmdk file copy for "sparse" and "preallocated" disk types
Uses HttpNfc import API for "streamOptimized" disk types. This API
creates a backing VM that wraps the VMDK in the vCenter inventory.
:param context: context
:param volume: Volume object
:param image_service: Glance image service
:param image_id: Glance image id'

def copy_image_to_volume(self, context, volume, image_service, image_id):

    LOG.debug('Copy    glance    image:    %s    to    create    new    volume.', image_id)
    metadata = image_service.show(context, image_id)
    VMwareVcVmdkDriver._validate_disk_format(metadata['disk_format'])
    container_format = metadata.get('container_format')
    if (container_format and (container_format not in ['bare', 'ova'])):
        msg = (_("Container    format:    %s    is    unsupported,    only    'bare'    and    'ova'    are    supported.") % container_format)
        LOG.error(msg)
        raise exception.ImageUnacceptable(image_id=image_id, reason=msg)
    image_disk_type = ImageDiskType.PREALLOCATED
    image_adapter_type = self._get_adapter_type(volume)
    image_size_in_bytes = metadata['size']
    properties = metadata['properties']
    if properties:
        if ('vmware_disktype' in properties):
            image_disk_type = properties['vmware_disktype']
        if ('vmware_adaptertype' in properties):
            image_adapter_type = properties['vmware_adaptertype']
    try:
        volumeops.VirtualDiskAdapterType.validate(image_adapter_type)
        ImageDiskType.validate(image_disk_type)
        if (image_disk_type == ImageDiskType.STREAM_OPTIMIZED):
            self._fetch_stream_optimized_image(context, volume, image_service, image_id, image_size_in_bytes, image_adapter_type)
        else:
            self._create_volume_from_non_stream_optimized_image(context, volume, image_service, image_id, image_size_in_bytes, image_adapter_type, image_disk_type)
    except (exceptions.VimException, exceptions.VMwareDriverException):
        with excutils.save_and_reraise_exception():
            LOG.exception('Error    occurred    while    copying    image:    %(id)s    to    volume:    %(vol)s.', {'id': image_id, 'vol': volume['name']})
    LOG.debug('Volume:    %(id)s    created    from    image:    %(image_id)s.', {'id': volume['id'], 'image_id': image_id})
    volume_size = (volume['size'] * units.Gi)
    backing = self.volumeops.get_backing(volume['name'])
    disk_size = self.volumeops.get_disk_size(backing)
    if (volume_size > disk_size):
        LOG.debug("Extending    volume:    %(name)s    since    the    user    specified    volume    size    (bytes):    %(vol_size)d    is    greater    than    backing's    current    disk    size    (bytes):    %(disk_size)d.", {'name': volume['name'], 'vol_size': volume_size, 'disk_size': disk_size})
        self._extend_backing(backing, volume['size'])
