COT.helpers.qemu_img module¶
Give COT access to qemu-img for manipulating disk image formats.
-
class
QEMUImg[source]¶ Bases:
COT.helpers.helper.HelperHelper provider for
qemu-img(http://www.qemu.org).Methods
install_helperInstall qemu-img.get_disk_formatGet the major disk image format of the given file. get_disk_capacityGet the storage capacity of the given disk image. convert_disk_imageConvert the given disk image to the requested format/subformat. create_blank_diskCreate an unformatted disk image at the requested location. -
convert_disk_image(file_path, output_dir, new_format, new_subformat=None)[source]¶ Convert the given disk image to the requested format/subformat.
If the disk is already in this format then it is unchanged; otherwise, will convert to a new disk in the specified output_dir and return its path.
Current supported conversions:
- .vmdk (any format) to .vmdk (streamOptimized)
- .img to .vmdk (streamOptimized)
Parameters: - file_path (str) – Disk image file to inspect/convert
- output_dir (str) – Directory to place converted image into, if needed
- new_format (str) – Desired final format
- new_subformat (str) – Desired final subformat
Returns: file_path, if no conversion was required- or a file path in
output_dircontaining the converted image
Raises NotImplementedError: if the
new_formatand/ornew_subformatare not supported conversion targets.
-
create_blank_disk(file_path, capacity, file_format=None)[source]¶ Create an unformatted disk image at the requested location.
Parameters: - file_path (str) – Desired location of new disk image
- capacity – Disk capacity. A string like ‘16M’ or ‘1G’.
- file_format (str) – Desired image format (if not specified, this
will be derived from the file extension of
file_path)
-
get_disk_capacity(file_path)[source]¶ Get the storage capacity of the given disk image.
Parameters: file_path (str) – Path to disk image file to inspect Returns: Disk capacity, in bytes
-
get_disk_format(file_path)[source]¶ Get the major disk image format of the given file.
Warning
If
file_pathrefers to a file which is not a disk image at all, this function will return'raw'.Parameters: file_path (str) – Path to disk image file to inspect. Returns: Disk image format ( 'vmdk','raw','qcow2', etc.)
-