def image_create(request, **kwargs):
    """Create image.

    :param kwargs:
        * copy_from: URL from which Glance server should immediately copy
            the data and store it in its configured image store.
        * data: Form data posted from client.
        * location: URL where the data for this image already resides.

    In the case of 'copy_from' and 'location', the Glance server
    will give us a immediate response from create and handle the data
    asynchronously.

    In the case of 'data' the process of uploading the data may take
    some time and is handed off to a separate thread.
    """
    data = kwargs.pop('data', None)
    location = None
    if VERSIONS.active >= 2:
        location = kwargs.pop('location', None)

    image = glanceclient(request).images.create(**kwargs)
    if location is not None:
        glanceclient(request).images.add_location(image.id, location, {})

    if data:
        if isinstance(data, six.string_types):
            # The image data is meant to be uploaded externally, return a
            # special wrapper to bypass the web server in a subsequent upload
            return ExternallyUploadedImage(image, request)
        elif isinstance(data, TemporaryUploadedFile):
            # Hack to fool Django, so we can keep file open in the new thread.
            if six.PY2:
                data.file.close_called = True
            else:
                data.file._closer.close_called = True
        elif isinstance(data, InMemoryUploadedFile):
            # Clone a new file for InMemeoryUploadedFile.
            # Because the old one will be closed by Django.
            data = SimpleUploadedFile(data.name,
                                      data.read(),
                                      data.content_type)
        if VERSIONS.active < 2:
            thread.start_new_thread(image_update,
                                    (request, image.id),
                                    {'data': data})
        else:
            def upload():
                try:
                    return glanceclient(request).images.upload(image.id, data)
                finally:
                    filename = str(data.file.name)
                    try:
                        os.remove(filename)
                    except OSError as e:
                        LOG.warning('Failed to remove temporary image file '
                                    '%(file)s (%(e)s)',
                                    {'file': filename, 'e': e})
            thread.start_new_thread(upload, ())

    return Image(image)
Create image.

    :param kwargs:
        * copy_from: URL from which Glance server should immediately copy
            the data and store it in its configured image store.
        * data: Form data posted from client.
        * location: URL where the data for this image already resides.

    In the case of 'copy_from' and 'location', the Glance server
    will give us a immediate response from create and handle the data
    asynchronously.

    In the case of 'data' the process of uploading the data may take
    some time and is handed off to a separate thread.