glance.api.v1 package

Submodules

glance.api.v1.controller module

class glance.api.v1.controller.BaseController[source]

Bases: object

get_active_image_meta_or_error(request, image_id)[source]

Same as get_image_meta_or_404 except that it will raise a 403 if the image is deactivated or 404 if the image is otherwise not ‘active’.

get_image_meta_or_404(request, image_id)[source]

Grabs the image metadata for an image with a supplied identifier or raises an HTTPNotFound (404) response

Parameters:
  • request – The WSGI/Webob Request object
  • image_id – The opaque image identifier
Raises:

HTTPNotFound if image does not exist

update_store_acls(req, image_id, location_uri, public=False)[source]

glance.api.v1.filters module

glance.api.v1.filters.validate(filter, value)[source]
glance.api.v1.filters.validate_boolean(v)[source]
glance.api.v1.filters.validate_int_in_range(min=0, max=None)[source]

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

Raises:

HttpNotFound if image or any chunk is not available

Raises:

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

:retval 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

:retval 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

:retval 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

:retval 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]

glance.api.v1.members module

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

Bases: glance.api.v1.controller.BaseController

default(req, image_id, id, body=None)[source]

This will cover the missing ‘show’ and ‘create’ actions

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

Removes a membership from the image.

index(req, image_id)[source]

Return a list of dictionaries indicating the members of the image, i.e., those tenants the image is shared with.

Parameters:
  • req – the Request object coming from the wsgi layer
  • image_id – The opaque image identifier

:retval The response body is a mapping of the following form:

{'members': [
    {'member_id': <MEMBER>,
     'can_share': <SHARE_PERMISSION>, ...}, ...
]}
index_shared_images(req, id)[source]

Retrieves list of image memberships for the given member.

Parameters:
  • req – the Request object coming from the wsgi layer
  • id – the opaque member identifier

:retval The response body is a mapping of the following form:

{'shared_images': [
    {'image_id': <IMAGE>,
     'can_share': <SHARE_PERMISSION>, ...}, ...
]}
update(req, *args, **kwargs)[source]

Adds a membership to the image, or updates an existing one. If a body is present, it is a dict with the following format:

{"member": {
    "can_share": [True|False]
}}

If “can_share” is provided, the member’s ability to share is set accordingly. If it is not provided, existing memberships remain unchanged and new memberships default to False.

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

Replaces the members of the image with those specified in the body. The body is a dict with the following format:

{"memberships": [
    {"member_id": <MEMBER_ID>,
     ["can_share": [True|False]]}, ...
]}
glance.api.v1.members.create_resource()[source]

Image members resource factory method

glance.api.v1.router module

class glance.api.v1.router.API(mapper)[source]

Bases: glance.common.wsgi.Router

WSGI router for Glance v1 API requests.

glance.api.v1.upload_utils module

glance.api.v1.upload_utils.initiate_deletion(req, location_data, id)[source]

Deletes image data from the location of backend store.

Parameters:
  • req – The WSGI/Webob Request object
  • location_data – Location to the image data in a data store
  • id – Opaque image identifier
glance.api.v1.upload_utils.safe_kill(req, image_id, from_state)[source]

Mark image killed without raising exceptions if it fails.

Since _kill is meant to be called from exceptions handlers, it should not raise itself, rather it should just log its error.

Parameters:
  • req – The WSGI/Webob Request object
  • image_id – Opaque image identifier
  • from_state – Permitted current status for transition to ‘killed’
glance.api.v1.upload_utils.upload_data_to_store(req, image_meta, image_data, store, notifier)[source]

Upload image data to specified store.

Upload image data to the store and cleans up on error.

Module contents