Image API v2

For details on how to use image, see Using OpenStack Image

The Image v2 Class

The image high-level interface is available through the image member of a Connection object. The image member will only be added if the service is detected.

Image Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
create_image(name, *, filename=None, data=None, container=None, md5=None, sha256=None, disk_format=None, container_format=None, tags=None, disable_vendor_agent=True, allow_duplicates=False, meta=None, wait=False, timeout=3600, validate_checksum=False, use_import=False, stores=None, all_stores=None, all_stores_must_succeed=None, **kwargs)

Create an image and optionally upload data

Create a new image. If filename or data are provided, it will also upload data to this image.

Note that uploading image data is actually quite a complicated procedure. There are three ways to upload an image:

  • Image upload

  • Image import

  • Image tasks

If the image tasks API is enabled, this must be used. However, this API is deprecated since the Image service’s Mitaka (12.0.0) release and is now admin-only. Assuming this API is not enabled, you may choose between image upload or image import. Image import is more powerful and allows you to upload data from multiple sources including other glance instances. It should be preferred on all services that support it.

Parameters:
  • name (str) – Name of the image to create. If it is a pathname of an image, the name will be constructed from the extensionless basename of the path.

  • filename (str) – The path to the file to upload, if needed. (optional, defaults to None)

  • data – Image data (string or file-like object). It is mutually exclusive with filename

  • container (str) – Name of the container in swift where images should be uploaded for import if the cloud requires such a thing. (optional, defaults to ‘images’)

  • md5 (str) – md5 sum of the image file. If not given, an md5 will be calculated.

  • sha256 (str) – sha256 sum of the image file. If not given, an md5 will be calculated.

  • disk_format (str) – The disk format the image is in. (optional, defaults to the os-client-config config value for this cloud)

  • container_format (str) – The container format the image is in. (optional, defaults to the os-client-config config value for this cloud)

  • tags (list) – List of tags for this image. Each tag is a string of at most 255 chars.

  • disable_vendor_agent (bool) – Whether or not to append metadata flags to the image to inform the cloud in question to not expect a vendor agent to be runing. (optional, defaults to True)

  • allow_duplicates – If true, skips checks that enforce unique image name. (optional, defaults to False)

  • meta – A dict of key/value pairs to use for metadata that bypasses automatic type conversion.

  • wait (bool) – If true, waits for image to be created. Defaults to true - however, be aware that one of the upload methods is always synchronous.

  • timeout – Seconds to wait for image creation. None is forever.

  • validate_checksum (bool) – If true and cloud returns checksum, compares return value with the one calculated or passed into this call. If value does not match - raises exception. Default is ‘false’

  • use_import (bool) – Use the ‘glance-direct’ method of the interoperable image import mechanism to import the image. This defaults to false because it is harder on the target cloud so should only be used when needed, such as when the user needs the cloud to transform image format. If the cloud has disabled direct uploads, this will default to true. If you wish to use other import methods, use the import_image method instead.

  • stores – List of stores to be used when enabled_backends is activated in glance. List values can be the id of a store or a Store instance. Implies use_import equals True.

  • all_stores – Upload to all available stores. Mutually exclusive with store and stores. Implies use_import equals True.

  • all_stores_must_succeed – When set to True, if an error occurs during the upload in at least one store, the worfklow fails, the data is deleted from stores where copying is done (not staging), and the state of the image is unchanged. When set to False, the workflow will fail (data deleted from stores, …) only if the import fails on all stores specified by the user. In case of a partial success, the locations added to the image will be the stores where the data has been correctly uploaded. Default is True. Implies use_import equals True.

Additional kwargs will be passed to the image creation as additional metadata for the image and will have all values converted to string except for min_disk, min_ram, size and virtual_size which will be converted to int.

If you are sure you have all of your data types correct or have an advanced need to be explicit, use meta. If you are just a normal consumer, using kwargs is likely the right choice.

If a value is in meta and kwargs, meta wins.

Returns:

The results of image creation

Return type:

Image

Raises:

SDKException if there are problems uploading

import_image(image, method='glance-direct', *, uri=None, remote_region=None, remote_image_id=None, remote_service_interface=None, store=None, stores=None, all_stores=None, all_stores_must_succeed=None)

Import data to an existing image

Interoperable image import process are introduced in the Image API v2.6. It mainly allow image importing from an external url and let Image Service download it by itself without sending binary data at image creation.

Parameters:
  • image – The value can be the ID of a image or a Image instance.

  • method – Method to use for importing the image. Not all deployments support all methods. One of: glance-direct (default), web-download, glance-download, or copy-image. Use of glance-direct requires the image be first staged.

  • uri – Required only if using the web-download import method. This url is where the data is made available to the Image service.

  • remote_region – The remote glance region to download the image from when using glance-download.

  • remote_image_id – The ID of the image to import from the remote glance when using glance-download.

  • remote_service_interface – The remote glance service interface to use when using glance-download.

  • store – Used when enabled_backends is activated in glance. The value can be the id of a store or a. Store instance.

  • stores – List of stores to be used when enabled_backends is activated in glance. List values can be the id of a store or a Store instance.

  • all_stores – Upload to all available stores. Mutually exclusive with store and stores.

  • all_stores_must_succeed – When set to True, if an error occurs during the upload in at least one store, the worfklow fails, the data is deleted from stores where copying is done (not staging), and the state of the image is unchanged. When set to False, the workflow will fail (data deleted from stores, …) only if the import fails on all stores specified by the user. In case of a partial success, the locations added to the image will be the stores where the data has been correctly uploaded. Default is True.

Returns:

The raw response from the request.

stage_image(image, *, filename=None, data=None)

Stage binary image data

Parameters:
  • image – The value can be the ID of a image or a Image instance.

  • filename – Optional name of the file to read data from.

  • data – Optional data to be uploaded as an image.

Returns:

The results of image creation

Return type:

Image

upload_image(container_format=None, disk_format=None, data=None, **attrs)

Create and upload a new image from attributes

Parameters:
  • container_format – Format of the container. A valid value is ami, ari, aki, bare, ovf, ova, or docker.

  • disk_format – The format of the disk. A valid value is ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, or iso.

  • data – The data to be uploaded as an image.

  • attrs (dict) – Keyword arguments which will be used to create a Image, comprised of the properties on the Image class.

Returns:

The results of image creation

Return type:

Image

download_image(image, *, stream=False, output=None, chunk_size=1048576)

Download an image

This will download an image to memory when stream=False, or allow streaming downloads using an iterator when stream=True. For examples of working with streamed responses, see Downloading an Image with stream=True.

Parameters:
  • image – The value can be either the ID of an image or a Image instance.

  • stream (bool) –

    When True, return a requests.Response instance allowing you to iterate over the response data stream instead of storing its entire contents in memory. See requests.Response.iter_content() for more details.

    NOTE: If you do not consume the entirety of the response you must explicitly call requests.Response.close() or otherwise risk inefficiencies with the requests library’s handling of connections.

    When False, return the entire contents of the response.

  • output – Either a file object or a path to store data into.

  • chunk_size (int) – size in bytes to read from the wire and buffer at one time. Defaults to 1024 * 1024 = 1 MiB

Returns:

When output is not given - the bytes comprising the given Image when stream is False, otherwise a requests.Response instance. When output is given - a Image instance.

delete_image(image, *, store=None, ignore_missing=True)

Delete an image

Parameters:
  • image – The value can be either the ID of an image or a Image instance.

  • store – The value can be either the ID of a store or a Store instance that the image is associated with. If specified, the image will only be deleted from the specified store.

  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the image does not exist. When set to True, no exception will be set when attempting to delete a nonexistent image.

Returns:

None

find_image(name_or_id, ignore_missing=True)

Find a single image

Parameters:
  • name_or_id – The name or ID of a image.

  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.

Returns:

One Image or None

get_image(image)

Get a single image

Parameters:

image – The value can be the ID of a image or a Image instance.

Returns:

One Image

Raises:

ResourceNotFound when no resource can be found.

images(**query)

Return a generator of images

Parameters:

query (kwargs) – Optional query parameters to be sent to limit the resources being returned.

Returns:

A generator of image objects

Return type:

Image

update_image(image, **attrs)

Update a image

Parameters:
  • image – Either the ID of a image or a Image instance.

  • attrs – The attributes to update on the image represented by image.

Returns:

The updated image

Return type:

Image

deactivate_image(image)

Deactivate an image

Parameters:

image – Either the ID of a image or a Image instance.

Returns:

None

reactivate_image(image)

Reactivate an image

Parameters:

image – Either the ID of a image or a Image instance.

Returns:

None

add_tag(image, tag)

Add a tag to an image

Parameters:
  • image – The value can be the ID of a image or a Image instance that the member will be created for.

  • tag (str) – The tag to be added

Returns:

None

remove_tag(image, tag)

Remove a tag to an image

Parameters:
  • image – The value can be the ID of a image or a Image instance that the member will be created for.

  • tag (str) – The tag to be removed

Returns:

None

Member Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
add_member(image, **attrs)

Create a new member from attributes

Parameters:
  • image – The value can be the ID of a image or a Image instance that the member will be created for.

  • attrs (dict) – Keyword arguments which will be used to create a Member, comprised of the properties on the Member class.

See Image Sharing Reference for details.

Returns:

The results of member creation

Return type:

Member

remove_member(member, image=None, ignore_missing=True)

Delete a member

Parameters:
  • member – The value can be either the ID of a member or a Member instance.

  • image – The value can be either the ID of an image or a Image instance that the member is part of. This is required if member is an ID.

  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the member does not exist. When set to True, no exception will be set when attempting to delete a nonexistent member.

Returns:

None

find_member(name_or_id, image, ignore_missing=True)

Find a single member

Parameters:
  • name_or_id – The name or ID of a member.

  • image – This is the image that the member belongs to, the value can be the ID of a image or a Image instance.

  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.

Returns:

One Member or None

get_member(member, image)

Get a single member on an image

Parameters:
  • member – The value can be the ID of a member or a Member instance.

  • image – This is the image that the member belongs to. The value can be the ID of a image or a Image instance.

Returns:

One Member

Raises:

ResourceNotFound when no resource can be found.

members(image, **query)

Return a generator of members

Parameters:
  • image – This is the image that the member belongs to, the value can be the ID of a image or a Image instance.

  • query (kwargs) – Optional query parameters to be sent to limit the resources being returned.

Returns:

A generator of member objects

Return type:

Member

update_member(member, image, **attrs)

Update the member of an image

Parameters:
  • member – Either the ID of a member or a Member instance.

  • image – This is the image that the member belongs to. The value can be the ID of a image or a Image instance.

  • attrs – The attributes to update on the member represented by member.

See Image Sharing Reference for details.

Returns:

The updated member

Return type:

Member

Task Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
tasks(**query)

Return a generator of tasks

Parameters:

query (kwargs) – Optional query parameters to be sent to limit the resources being returned.

Returns:

A generator of task objects

Return type:

Task

get_task(task)

Get task details

Parameters:

task – The value can be the ID of a task or a Task instance.

Returns:

One Task

Raises:

ResourceNotFound when no resource can be found.

create_task(**attrs)

Create a new task from attributes

Parameters:

attrs (dict) – Keyword arguments which will be used to create a Task, comprised of the properties on the Task class.

Returns:

The results of task creation

Return type:

Task

wait_for_task(task, status='success', failures=None, interval=2, wait=120)

Wait for a task to be in a particular status.

Parameters:
  • task – The resource to wait on to reach the specified status. The resource must have a status attribute.

  • status – Desired status.

  • failures (list) – Statuses that would be interpreted as failures.

  • interval – Number of seconds to wait before to consecutive checks. Default to 2.

  • wait – Maximum number of seconds to wait before the change. Default to 120.

Returns:

The resource is returned on success.

Raises:

ResourceTimeout if transition to the desired status failed to occur in specified seconds.

Raises:

ResourceFailure if the resource has transited to one of the failure statuses.

Raises:

AttributeError if the resource does not have a status attribute.

Schema Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
get_images_schema()

Get images schema

Returns:

One Schema

Raises:

ResourceNotFound when no resource can be found.

get_image_schema()

Get single image schema

Returns:

One Schema

Raises:

ResourceNotFound when no resource can be found.

get_members_schema()

Get image members schema

Returns:

One Schema

Raises:

ResourceNotFound when no resource can be found.

get_member_schema()

Get image member schema

Returns:

One Schema

Raises:

ResourceNotFound when no resource can be found.

get_tasks_schema()

Get image tasks schema

Returns:

One Schema

Raises:

ResourceNotFound when no resource can be found.

get_task_schema()

Get image task schema

Returns:

One Schema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_namespace_schema()

Get metadata definition namespace schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_namespaces_schema()

Get metadata definition namespaces schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_resource_type_schema()

Get metadata definition resource type association schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_resource_types_schema()

Get metadata definition resource type associations schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_object_schema()

Get metadata definition object schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_objects_schema()

Get metadata definition objects schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_property_schema()

Get metadata definition property schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_properties_schema()

Get metadata definition properties schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_tag_schema()

Get metadata definition tag schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

get_metadef_tags_schema()

Get metadata definition tags schema

Returns:

One MetadefSchema

Raises:

ResourceNotFound when no resource can be found.

Service Info Discovery Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
stores(details=False, **query)

Return a generator of supported image stores

Returns:

A generator of store objects

Return type:

Store

get_import_info()

Get a info about image constraints

Returns:

One Import

Raises:

ResourceNotFound when no resource can be found.

Metadef Namespace Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
create_metadef_namespace(**attrs)

Create a new metadef namespace from attributes

Parameters:

attrs (dict) – Keyword arguments which will be used to create a MetadefNamespace comprised of the properties on the MetadefNamespace class.

Returns:

The results of metadef namespace creation

Return type:

MetadefNamespace

delete_metadef_namespace(metadef_namespace, ignore_missing=True)

Delete a metadef namespace

Parameters:
  • metadef_namespace – The value can be either the name of a metadef namespace or a MetadefNamespace instance.

  • ignore_missing (bool) – When set to False, ResourceNotFound will be raised when the metadef namespace does not exist.

Returns:

None

get_metadef_namespace(metadef_namespace)

Get a single metadef namespace

Parameters:

metadef_namespace – Either the name of a metadef namespace or an MetadefNamespace instance.

Returns:

One MetadefNamespace

Raises:

ResourceNotFound when no resource can be found.

metadef_namespaces(**query)

Return a generator of metadef namespaces

Returns:

A generator object of metadef namespaces

Return type:

MetadefNamespace

Raises:

ResourceNotFound when no resource can be found.

update_metadef_namespace(metadef_namespace, **attrs)

Update a server

Parameters:
  • metadef_namespace – Either the name of a metadef namespace or an MetadefNamespace instance.

  • attrs – The attributes to update on the metadef namespace represented by metadef_namespace.

Returns:

The updated metadef namespace

Return type:

MetadefNamespace

Metadef Object Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
create_metadef_object(namespace, **attrs)

Create a new object from namespace

Parameters:
  • namespace – The value can be either the name of a metadef namespace or a MetadefNamespace instance.

  • attrs (dict) – Keyword arguments which will be used to create a MetadefObject, comprised of the properties on the Metadef object class.

Returns:

A metadef namespace

Return type:

MetadefObject

get_metadef_object(metadef_object, namespace)

Get a single metadef object

Parameters:
  • metadef_object – The value can be the ID of a metadef_object or a MetadefObject instance.

  • namespace – The value can be either the name of a metadef namespace or a MetadefNamespace instance.

Returns:

One MetadefObject

Raises:

ResourceNotFound when no resource can be found.

metadef_objects(namespace)

Get metadef object list of the namespace

Parameters:

namespace – The value can be either the name of a metadef namespace or a MetadefNamespace instance.

Returns:

One MetadefObject

Raises:

ResourceNotFound when no resource can be found.

update_metadef_object(metadef_object, namespace, **attrs)

Update a single metadef object

Parameters:
  • metadef_object – The value can be the ID of a metadef_object or a MetadefObject instance.

  • namespace – The value can be either the name of a metadef namespace or a MetadefNamespace instance.

  • attrs (dict) – Keyword arguments which will be used to update a MetadefObject

Returns:

One MetadefObject

Raises:

ResourceNotFound when no resource can be found.

delete_metadef_object(metadef_object, namespace, **attrs)

Removes a single metadef object

Parameters:
  • metadef_object – The value can be the ID of a metadef_object or a MetadefObject instance.

  • namespace – The value can be either the name of a metadef namespace or a MetadefNamespace instance.

  • attrs (dict) – Keyword arguments which will be used to update a MetadefObject

Returns:

None

Raises:

ResourceNotFound when no resource can be found.

Metadef Resource Type Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
metadef_resource_types(**query)

Return a generator of metadef resource types

Returns:

A generator object of metadef resource types

Return type:

MetadefResourceType

Raises:

ResourceNotFound when no resource can be found.

create_metadef_resource_type_association(metadef_namespace, **attrs)
Creates a resource type association between a namespace

and the resource type specified in the body of the request.

Parameters:

attrs (dict) – Keyword arguments which will be used to create a MetadefResourceTypeAssociation comprised of the properties on the MetadefResourceTypeAssociation class.

Returns:

The results of metadef resource type association creation

Return type:

MetadefResourceTypeAssociation

delete_metadef_resource_type_association(metadef_resource_type, metadef_namespace, ignore_missing=True)

Removes a resource type association in a namespace.

Parameters:
  • metadef_resource_type – The value can be either the name of a metadef resource type association or an MetadefResourceTypeAssociation instance.

  • metadef_namespace – The value can be either the name of metadef namespace or an MetadefNamespace instance

  • ignore_missing (bool) – When set to False, ResourceNotFound will be raised when the metadef resource type association does not exist.

Returns:

None

metadef_resource_type_associations(metadef_namespace, **query)

Return a generator of metadef resource type associations

Parameters:

metadef_namespace – The value can be either the name of metadef namespace or an MetadefNamespace instance

Returns:

A generator object of metadef resource type associations

Return type:

MetadefResourceTypeAssociation

Raises:

ResourceNotFound when no resource can be found.

Metadef Property Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
create_metadef_property(metadef_namespace, **attrs)

Create a metadef property

Parameters:
  • metadef_namespace – The value can be either the name of metadef namespace or an MetadefNamespace instance

  • attrs – The attributes to create on the metadef property represented by metadef_property.

Returns:

The created metadef property

Return type:

MetadefProperty

update_metadef_property(metadef_property, metadef_namespace, **attrs)

Update a metadef property

Parameters:
  • metadef_property – The value can be either the name of metadef property or an MetadefProperty instance.

  • metadef_namespace – The value can be either the name of metadef namespace or an MetadefNamespace instance

  • attrs – The attributes to update on the metadef property represented by metadef_property.

Returns:

The updated metadef property

Return type:

MetadefProperty

delete_metadef_property(metadef_property, metadef_namespace, ignore_missing=True)

Delete a metadef property

Parameters:
  • metadef_property – The value can be either the name of metadef property or an MetadefProperty instance

  • metadef_namespace – The value can be either the name of metadef namespace or an MetadefNamespace instance

  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the instance does not exist. When set to True, no exception will be set when attempting to delete a nonexistent instance.

Returns:

None

get_metadef_property(metadef_property, metadef_namespace, **query)

Get a single metadef property

Parameters:
  • metadef_property – The value can be either the name of metadef property or an MetadefProperty instance.

  • metadef_namespace – The value can be either the name of metadef namespace or an MetadefNamespace instance

Returns:

One MetadefProperty

Raises:

ResourceNotFound when no resource can be found.

Helpers

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
wait_for_delete(res, interval=2, wait=120)

Wait for a resource to be deleted.

Parameters:
  • res – The resource to wait on to be deleted.

  • interval – Number of seconds to wait before to consecutive checks. Default to 2.

  • wait – Maximum number of seconds to wait before the change. Default to 120.

Returns:

The resource is returned on success.

Raises:

ResourceTimeout if transition to delete failed to occur in the specified seconds.

Cache Operations

class openstack.image.v2._proxy.Proxy(session, statsd_client=None, statsd_prefix=None, prometheus_counter=None, prometheus_histogram=None, influxdb_config=None, influxdb_client=None, *args, **kwargs)
cache_delete_image(image, ignore_missing=True)

Delete an image from cache.

Parameters:
  • image – The value can be either the name of an image or a Image instance.

  • ignore_missing (bool) – When set to False, ResourceNotFound will be raised when the metadef namespace does not exist.

Returns:

None

queue_image(image_id)

Queue image(s) for caching.

clear_cache(target)

Clear all images from cache, queue or both

Parameters:

target – Specify which target you want to clear One of: both``(default), ``cache, queue.