Helper methods to deal with images.
This is essentially a copy from nova.virt.images.py Some slight modifications, but at some point we should look at maybe pushing this up to Oslo
Bases: object
Manage temporarily downloaded images to avoid downloading it twice.
In the ‘with TemporaryImages.fetch(image_service, ctx, image_id) as tmp’ clause, ‘tmp’ can be used as the downloaded image path. In addition, image_utils.fetch() will use the pre-fetched image by the TemporaryImages. This is useful to inspect image contents before conversion.
Do some image format checks.
Verifies that the src_format matches what qemu-img thinks the image format is, and does some vmdk subformat checks. See Bug #1996188.
Does not check for a qcow2 backing file.
Will make a call out to qemu_img if data is None.
source – filename of the image to check
src_format – source image format recognized by qemu_img, or None
image_id – the image ID if this is a Glance image, or None
data – a imageutils.QemuImgInfo object from this image, or None
run_as_root – when ‘data’ is None, call ‘qemu-img info’ as root
ImageUnacceptable – when the image fails some format checks
ProcessExecutionError – if ‘qemu-img info’ fails
Check some rules about qcow2 images.
Does not check for a backing_file, because cinder has some legitimate use cases for qcow2 backing files.
Makes sure the image:
does not have a data_file
image_id – the image id
data – an imageutils.QemuImgInfo object
ImageUnacceptable – when the image fails the check
Check some rules about VMDK images.
Make sure the VMDK subformat (the “createType” in vmware docs) is one that we allow as determined by the ‘vmdk_allowed_types’ configuration option. The default set includes only types that do not reference files outside the VMDK file, which can otherwise be used in exploits to expose host information.
image_id – the image id
data – an imageutils.QemuImgInfo object
ImageUnacceptable – when the VMDK createType is not in the allowed list
Convert image to other format.
NOTE: If the qemu-img convert command fails and this function raises an exception, a non-empty dest file may be left in the filesystem. It is the responsibility of the caller to decide what to do with this file.
source – source filename
dest – destination filename
out_format – output image format of qemu-img
out_subformat – output image subformat
src_format – source image format (use image_utils.fixup_disk_format() to translate from a Glance format to one recognizable by qemu_img)
run_as_root – run qemu-img as root
throttle – a cinder.throttling.Throttle object, or None
cipher_spec – encryption details
passphrase_file – filename containing luks passphrase
compress – compress w/ qemu-img when possible (best effort)
src_passphrase_file – filename containing source volume’s luks passphrase
image_id – the image ID if this is a Glance image, or None
data – a imageutils.QemuImgInfo object from this image, or None
ImageUnacceptable – when the image fails some format checks
ProcessExecutionError – when something goes wrong during conversion
Decode a dm-crypt style cipher specification string
The assumed format being cipher-chainmode-ivmode, similar to that documented under linux/Documentation/admin-guide/device-mapper/dm-crypt.txt in the kernel source tree. Cinder does not support the [:keycount] or [:ivopts] options.
Return the format to be provided to qemu-img convert.
Return the conventional format derived from qemu-img format.
The qemu-img version will be cached until the process is restarted.
Return an object containing the parsed output from qemu-img info.
Changes the virtual size of the image.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.