The glance.api.v1.images Module

/images endpoint for Glance v1 API

class glance.api.v1.images.Controller[source]

Bases: glance.api.v1.controller.BaseController

WSGI controller for images resource in Glance v1 API

The images resource API is a RESTful web service for image data. The API is as follows:

GET /images -- Returns a set of brief metadata about images
GET /images/detail -- Returns a set of detailed metadata about
                      images
HEAD /images/<ID> -- Return metadata about an image with id <ID>
GET /images/<ID> -- Return image data for image with id <ID>
POST /images -- Store image data and return metadata about the
                newly-stored image
PUT /images/<ID> -- Update image metadata and/or upload image
                    data for a previously-reserved image
DELETE /images/<ID> -- Delete the image with id <ID>
create(req, *args, **kwargs)[source]

Adds a new image to Glance. Four scenarios exist when creating an image:

  1. If the image data is available directly for upload, create can be passed the image data as the request body and the metadata as the request headers. The image will initially be ‘queued’, during upload it will be in the ‘saving’ status, and then ‘killed’ or ‘active’ depending on whether the upload completed successfully.
  2. If the image data exists somewhere else, you can upload indirectly from the external source using the x-glance-api-copy-from header. Once the image is uploaded, the external store is not subsequently consulted, i.e. the image content is served out from the configured glance image store. State transitions are as for option #1.
  3. If the image data exists somewhere else, you can reference the source using the x-image-meta-location header. The image content will be served out from the external store, i.e. is never uploaded to the configured glance image store.
  4. If the image data is not available yet, but you’d like reserve a spot for it, you can omit the data and a record will be created in the ‘queued’ state. This exists primarily to maintain backwards compatibility with OpenStack/Rackspace API semantics.

The request body must be encoded as application/octet-stream, otherwise an HTTPBadRequest is returned.

Upon a successful save of the image data and metadata, a response containing metadata about the image is returned, including its opaque identifier.

Parameters:
  • req – The WSGI/Webob Request object
  • image_meta – Mapping of metadata about image
  • image_data – Actual image data that is to be stored
Raises:

HTTPBadRequest – if x-image-meta-location is missing and the request body is not application/octet-stream image data.

delete(req, *args, **kwargs)[source]

Deletes the image and all its chunks from the Glance

Parameters:
  • req – The WSGI/Webob Request object
  • id – The opaque image identifier
Raises:
  • HttpBadRequest – if image registry is invalid
  • HttpNotFound – if image or any chunk is not available
  • HttpUnauthorized – if image or any chunk is not deleteable by the requesting user
detail(req)[source]

Returns detailed information for all available images

Parameters:req – The WSGI/Webob Request object
Returns:The response body is a mapping of the following form
{'images':
    [{
        'id': <ID>,
        'name': <NAME>,
        'size': <SIZE>,
        'disk_format': <DISK_FORMAT>,
        'container_format': <CONTAINER_FORMAT>,
        'checksum': <CHECKSUM>,
        'min_disk': <MIN_DISK>,
        'min_ram': <MIN_RAM>,
        'store': <STORE>,
        'status': <STATUS>,
        'created_at': <TIMESTAMP>,
        'updated_at': <TIMESTAMP>,
        'deleted_at': <TIMESTAMP>|<NONE>,
        'properties': {'distro': 'Ubuntu 10.04 LTS', {...}}
     }, {...}]
}
get_store_or_400(request, scheme)[source]

Grabs the storage backend for the supplied store name or raises an HTTPBadRequest (400) response

Parameters:
  • request – The WSGI/Webob Request object
  • scheme – The backend store scheme
Raises:

HTTPBadRequest – if store does not exist

index(req)[source]

Returns the following information for all public, available images:

  • id – The opaque image identifier
  • name – The name of the image
  • disk_format – The disk image format
  • container_format – The “container” format of the image
  • checksum – MD5 checksum of the image data
  • size – Size of image data in bytes
Parameters:req – The WSGI/Webob Request object
Returns:The response body is a mapping of the following form
{'images': [
    {'id': <ID>,
     'name': <NAME>,
     'disk_format': <DISK_FORMAT>,
     'container_format': <DISK_FORMAT>,
     'checksum': <CHECKSUM>,
     'size': <SIZE>}, {...}]
}
meta(req, id)[source]

Returns metadata about an image in the HTTP headers of the response object

Parameters:
  • req – The WSGI/Webob Request object
  • id – The opaque image identifier
Returns:

similar to ‘show’ method but without image_data

Raises:

HTTPNotFound – if image metadata is not available to user

show(req, id)[source]

Returns an iterator that can be used to retrieve an image’s data along with the image metadata.

Parameters:
  • req – The WSGI/Webob Request object
  • id – The opaque image identifier
Raises:

HTTPNotFound – if image is not available to user

update(req, *args, **kwargs)[source]

Updates an existing image with the registry.

Parameters:
  • request – The WSGI/Webob Request object
  • id – The opaque image identifier
Returns:

Returns the updated image information as a mapping

class glance.api.v1.images.ImageDeserializer[source]

Bases: glance.common.wsgi.JSONRequestDeserializer

Handles deserialization of specific controller method requests.

create(request)[source]
update(request)[source]
class glance.api.v1.images.ImageSerializer[source]

Bases: glance.common.wsgi.JSONResponseSerializer

Handles serialization of specific controller method responses.

create(response, result)[source]
meta(response, result)[source]
show(response, result)[source]
update(response, result)[source]
glance.api.v1.images.create_resource()[source]

Images resource factory method

glance.api.v1.images.redact_loc(image_meta, copy_dict=True)[source]

Create a shallow copy of image meta with ‘location’ removed for security (as it can contain credentials).

glance.api.v1.images.validate_image_meta(req, values)[source]
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.