For details on how to use image, see Using OpenStack Image
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.
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, container=None, md5=None, sha256=None, disk_format=None, container_format=None, disable_vendor_agent=True, allow_duplicates=False, meta=None, wait=False, timeout=3600, data=None, validate_checksum=True, **kwargs)¶Upload an image.
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)
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’
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.
A munch.Munch
of the Image object
SDKException if there are problems uploading
import_image
(image, method='glance-direct', uri=None, store=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.
image – The value can be the ID of a image or a
Image
instance.
method – Method to use for importing the image. A valid value is glance-direct or web-download.
uri – Required only if using the web-download import method. This url is where the data is made available to the Image service.
store – Used when enabled_backends is activated in glance
The value can be the id of a store or a
Store
instance.
None
upload_image
(container_format=None, disk_format=None, data=None, **attrs)¶Create and upload a new image from attributes
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.
The results of image creation
download_image
(image, stream=False, output=None, chunk_size=1024)¶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.
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
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.
update_image
(image, **attrs)¶Update a image
delete_image
(image, ignore_missing=True)¶Delete an image
image – The value can be either the ID of an image or a
Image
instance.
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.
None
get_image
(image)¶Get a single image
find_image
(name_or_id, ignore_missing=True)¶Find a single image
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.
One Image
or None
images
(**query)¶Return a generator of images
query (kwargs) – Optional query parameters to be sent to limit the resources being returned.
A generator of image objects
deactivate_image
(image)¶Deactivate an image
image – Either the ID of a image or a
Image
instance.
None
reactivate_image
(image)¶Deactivate an image
image – Either the ID of a image or a
Image
instance.
None
stage_image
(image, filename=None, data=None)¶Stage binary image data
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
remove_member
(member, image, ignore_missing=True)¶Delete a member
member – The value can be either the ID of a member or a
Member
instance.
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.
None
update_member
(member, image, **attrs)¶Update the member of an image
get_member
(member, image)¶Get a single member on an image
find_member
(name_or_id, image, ignore_missing=True)¶Find a single member
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.
One Member
or None
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
query (kwargs) – Optional query parameters to be sent to limit the resources being returned.
A generator of task objects
create_task
(**attrs)¶Create a new task from attributes
get_task
(task)¶Get task details
wait_for_task
(task, status='success', failures=None, interval=2, wait=120)¶Wait for a task to be in a particular status.
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.
The resource is returned on success.
ResourceTimeout
if transition
to the desired status failed to occur in specified seconds.
ResourceFailure
if the resource
has transited to one of the failure statuses.
AttributeError
if the resource does not have a
status
attribute.
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
One Schema
ResourceNotFound
when no resource can be found.
get_image_schema
()¶Get single image schema
One Schema
ResourceNotFound
when no resource can be found.
get_members_schema
()¶Get image members schema
One Schema
ResourceNotFound
when no resource can be found.
get_member_schema
()¶Get image member schema
One Schema
ResourceNotFound
when no resource can be found.
get_tasks_schema
()¶Get image tasks schema
One Schema
ResourceNotFound
when no resource can be found.
get_task_schema
()¶Get image task schema
One Schema
ResourceNotFound
when no resource can be found.
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
(**query)¶Return a generator of supported image stores
A generator of store objects
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.