def _clone_image_volume_and_add_location(self, ctx, volume, image_service, image_meta):
    'Create a cloned volume and register its location to the image.'
    if ((image_meta['disk_format'] != 'raw') or (image_meta['container_format'] != 'bare')):
        return False
    image_volume_context = ctx
    if self.driver.configuration.image_upload_use_internal_tenant:
        internal_ctx = context.get_internal_tenant_context()
        if internal_ctx:
            image_volume_context = internal_ctx
    image_volume = self._clone_image_volume(image_volume_context, volume, image_meta)
    if (not image_volume):
        return False
    uri = ('cinder://%s' % image_volume.id)
    image_registered = None
    try:
        image_registered = image_service.add_location(ctx, image_meta['id'], uri, {})
    except (exception.NotAuthorized, exception.Invalid, exception.NotFound):
        LOG.exception(_LE('Failed to register image volume location %(uri)s.'), {'uri': uri})
    if (not image_registered):
        LOG.warning(_LW('Registration of image volume URI %(uri)s to image %(image_id)s failed.'), {'uri': uri, 'image_id': image_meta['id']})
        try:
            self.delete_volume(image_volume_context, image_volume)
        except exception.CinderException:
            LOG.exception(_LE('Could not delete failed image volume %(id)s.'), {'id': image_volume.id})
        return False
    image_volume_meta = {'glance_image_id': image_meta['id'], 'image_owner': ctx.project_id}
    self.db.volume_metadata_update(image_volume_context, image_volume.id, image_volume_meta, False)
    return True
Create a cloned volume and register its location to the image.
def _clone_image_volume_and_add_location(self, ctx, volume, image_service, image_meta):
    
    if ((image_meta['disk_format'] != 'raw') or (image_meta['container_format'] != 'bare')):
        return False
    image_volume_context = ctx
    if self.driver.configuration.image_upload_use_internal_tenant:
        internal_ctx = context.get_internal_tenant_context()
        if internal_ctx:
            image_volume_context = internal_ctx
    image_volume = self._clone_image_volume(image_volume_context, volume, image_meta)
    if (not image_volume):
        return False
    uri = ('cinder://%s' % image_volume.id)
    image_registered = None
    try:
        image_registered = image_service.add_location(ctx, image_meta['id'], uri, {})
    except (exception.NotAuthorized, exception.Invalid, exception.NotFound):
        LOG.exception(_LE('Failed to register image volume location %(uri)s.'), {'uri': uri})
    if (not image_registered):
        LOG.warning(_LW('Registration of image volume URI %(uri)s to image %(image_id)s failed.'), {'uri': uri, 'image_id': image_meta['id']})
        try:
            self.delete_volume(image_volume_context, image_volume)
        except exception.CinderException:
            LOG.exception(_LE('Could not delete failed image volume %(id)s.'), {'id': image_volume.id})
        return False
    image_volume_meta = {'glance_image_id': image_meta['id'], 'image_owner': ctx.project_id}
    self.db.volume_metadata_update(image_volume_context, image_volume.id, image_volume_meta, False)
    return True