Create image directly in 'copy_from' and 'location' case

The Glance API will return immediately with a response. We need this
response to give a errror message back to the user in case of invalid
URL.

Any download operation will be executed in the background by the
Glance API server and there is no need for executing this step in a
separate thread.

Keep current logic for updating image with posted data in a background thread
One can argue that this too is uneccessary, but I can see that it may save
time for large images or when bandwidth between Horizon and Glance is limited.

Change-Id: I2ec9f714f9cfd6ca2271750133d6fcac29b94f35
Partial-Bug: 1438975
This commit is contained in:
Frode Nordahl 2015-04-02 10:37:28 +02:00
parent f255cb2886
commit 4590f5fbde
1 changed files with 15 additions and 12 deletions

View File

@ -123,9 +123,22 @@ def image_update(request, image_id, **kwargs):
def image_create(request, **kwargs):
copy_from = kwargs.pop('copy_from', None)
"""Create image.
Keyword arguments:
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 seperate thread.
"""
data = kwargs.pop('data', None)
location = kwargs.pop('location', None)
image = glanceclient(request).images.create(**kwargs)
@ -134,16 +147,6 @@ def image_create(request, **kwargs):
(request, image.id),
{'data': data,
'purge_props': False})
elif copy_from:
thread.start_new_thread(image_update,
(request, image.id),
{'copy_from': copy_from,
'purge_props': False})
elif location:
thread.start_new_thread(image_update,
(request, image.id),
{'location': location,
'purge_props': False})
return image