COT.helpers.api module

API for abstract access to third-party helper tools.

Abstracts away operations that require third-party helper programs, especially those that are not available through PyPI.

The actual helper programs are provided by individual classes in this package.

Functions

convert_disk_image Convert the given disk image to the requested format/subformat.
create_disk_image Create a new disk image at the requested location.
get_checksum Get the checksum of the given file.
get_disk_capacity Get the storage capacity of the given disk image.
get_disk_format Get the disk image format of the given file.
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_dir containing the converted image

Raises ValueUnsupportedError:
 

if the new_format and/or new_subformat are not supported conversion targets.

create_disk_image(file_path, file_format=None, capacity=None, contents=[])[source]

Create a new disk image at the requested location.

Either capacity or contents or both must be specified.

Parameters:
  • file_path (str) – Desired location of new disk image
  • file_format (str) – Desired image format (if not specified, this will be derived from the file extension of file_path)
  • capacity – Disk capacity. A string like ‘16M’ or ‘1G’.
  • contents (list) – List of file paths to package into the created image. If not specified, the image will be left blank and unformatted.
get_checksum(file_path, checksum_type)[source]

Get the checksum of the given file.

Parameters:
  • file_path (str) – Path to file to checksum
  • checksum_type (str) – Supported values are ‘md5’ and ‘sha1’.
Returns:

String containing hexadecimal file checksum

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 disk image format of the given file.

Warning

If file_path refers to a file which is not a disk image at all, this function will return ('raw', None).

Parameters:file_path (str) – Path to disk image file to inspect.
Returns:(format, subformat)
  • format may be 'vmdk', 'raw', or 'qcow2'
  • subformat may be None, or various strings for 'vmdk' files.