'Create a new image from the specified volume.'

@wrap_check_policy
def copy_volume_to_image(self, context, volume, metadata, force):

    if ((not CONF.enable_force_upload) and force):
        LOG.info('Force    upload    to    image    is    disabled,    Force    option    will    be    ignored.', resource={'type': 'volume', 'id': volume['id']})
        force = False
    expected = {'status': (('available', 'in-use') if force else 'available')}
    values = {'status': 'uploading', 'previous_status': volume.model.status}
    result = volume.conditional_update(values, expected)
    if (not result):
        msg = (_('Volume    %(vol_id)s    status    must    be    %(statuses)s') % {'vol_id': volume.id, 'statuses': utils.build_or_str(expected['status'])})
        raise exception.InvalidVolume(reason=msg)
    try:
        glance_core_props = CONF.glance_core_properties
        if glance_core_props:
            try:
                vol_img_metadata = self.get_volume_image_metadata(context, volume)
                custom_property_set = set(vol_img_metadata).difference(glance_core_props)
                if custom_property_set:
                    metadata['properties'] = {custom_prop: vol_img_metadata[custom_prop] for custom_prop in custom_property_set}
            except exception.GlanceMetadataNotFound:
                pass
        recv_metadata = self.image_service.create(context, self.image_service._translate_to_glance(metadata))
    except Exception:
        with excutils.save_and_reraise_exception():
            volume.conditional_update({'status': volume.model.previous_status, 'previous_status': None}, {'status': 'uploading'})
    self.volume_rpcapi.copy_volume_to_image(context, volume, recv_metadata)
    response = {'id': volume['id'], 'updated_at': volume['updated_at'], 'status': 'uploading', 'display_description': volume['display_description'], 'size': volume['size'], 'volume_type': volume['volume_type'], 'image_id': recv_metadata['id'], 'container_format': recv_metadata['container_format'], 'disk_format': recv_metadata['disk_format'], 'image_name': recv_metadata.get('name', None)}
    if ('protected' in recv_metadata):
        response['protected'] = recv_metadata.get('protected')
    if ('is_public' in recv_metadata):
        response['is_public'] = recv_metadata.get('is_public')
    elif ('visibility' in recv_metadata):
        response['visibility'] = recv_metadata.get('visibility')
    LOG.info('Copy    volume    to    image    completed    successfully.', resource=volume)
    return response
