Support zero-size image creation via the v1 API
Addresses LP 1025353 for the v1 API. Transition image status to active immediately on creation (as opposed to leaving it queued forever) if the size is set to zero from the get-go. This change allows an image to be created that simply acts as a properties bucket, but requires no image data. For example, an image created from a booted-from-volume instance where only the kernel, ramdisk ID, and block device mappings are required. Change-Id: I61e96f3fe5f5245fec791170b4a8b4c72135c3de
This commit is contained in:
parent
e20e2c8094
commit
55cf240cad
|
@ -22,7 +22,8 @@ Images in Glance can be in one the following statuses:
|
|||
* ``queued``
|
||||
|
||||
The image identifier has been reserved for an image in the Glance
|
||||
registry. No image data has been uploaded to Glance.
|
||||
registry. No image data has been uploaded to Glance and the image
|
||||
size was not explicitly set to zero on creation.
|
||||
|
||||
* ``saving``
|
||||
|
||||
|
@ -34,7 +35,9 @@ Images in Glance can be in one the following statuses:
|
|||
|
||||
* ``active``
|
||||
|
||||
Denotes an image that is fully available in Glance.
|
||||
Denotes an image that is fully available in Glance. This occurs when
|
||||
the image data is uploaded, or the image size is explicitly set to
|
||||
zero on creation.
|
||||
|
||||
* ``killed``
|
||||
|
||||
|
|
|
@ -272,8 +272,11 @@ class Controller(controller.BaseController):
|
|||
self._enforce(req, 'get_image')
|
||||
image_meta = self.get_active_image_meta_or_404(req, id)
|
||||
|
||||
image_iterator, size = self._get_from_store(image_meta['location'])
|
||||
image_meta['size'] = size or image_meta['size']
|
||||
if image_meta.get('size') == 0:
|
||||
image_iterator = iter([])
|
||||
else:
|
||||
image_iterator, size = self._get_from_store(image_meta['location'])
|
||||
image_meta['size'] = size or image_meta['size']
|
||||
|
||||
del image_meta['location']
|
||||
return {
|
||||
|
@ -295,6 +298,10 @@ class Controller(controller.BaseController):
|
|||
:raises HTTPBadRequest if image metadata is not valid
|
||||
"""
|
||||
location = self._external_source(image_meta, req)
|
||||
|
||||
image_meta['status'] = ('active' if image_meta.get('size') == 0
|
||||
else 'queued')
|
||||
|
||||
if location:
|
||||
store = get_store_from_location(location)
|
||||
# check the store exists before we hit the registry, but we
|
||||
|
@ -309,8 +316,6 @@ class Controller(controller.BaseController):
|
|||
# to a non-zero value during upload
|
||||
image_meta['size'] = image_meta.get('size', 0)
|
||||
|
||||
image_meta['status'] = 'queued'
|
||||
|
||||
try:
|
||||
image_meta = registry.add_image_metadata(req.context, image_meta)
|
||||
return image_meta
|
||||
|
|
Loading…
Reference in New Issue