COT.disks package reference

Package for handling various disk file types (VMDK, ISO, QCOW2, etc.).

Tries to provide an API that abstracts away differences in how the various types need to be operated on (e.g., qemu-img, mkisofs, etc.).


DiskRepresentation Abstract disk image file representation.

Disk modules

COT.disks.iso Handling of ISO files.
COT.disks.qcow2 Handling of QCOW2 files.
COT.disks.raw Handling of raw disk image files.
COT.disks.vmdk Handling of VMDK files.
class DiskRepresentation(path)[source]

Bases: object

Abstract disk image file representation.


Create a representation of an existing disk.

Parameters:path (str) -- Path to existing file.
static class_for_format(disk_format)[source]

Get the DiskRepresentation subclass associated with the given format.

Parameters:disk_format (str) -- Disk format string such as 'iso' or 'vmdk'
Returns:DiskRepresentation -- appropriate subclass object.
convert_to(new_format, new_directory, new_subformat=None)[source]

Convert the disk file to a new format and return the new instance.

  • new_format (str) -- Format to convert to.
  • new_subformat (str) -- (optional) Sub-format to convert to.
  • new_directory (str) -- Directory path to store new image into.

DiskRepresentation -- Converted disk


NotImplementedError -- if new_format is not a supported type

classmethod create_file(path, files=None, capacity=None, **kwargs)[source]

Create a new disk image file of this type.

  • path (str) -- Location to create disk file.
  • files (list) -- List of files to include in the disk's filesystem.
  • capacity (str) -- Disk capacity.
  • **kwargs -- Subclasses and _create_file() may accept additional parameters.
classmethod file_is_this_type(path)[source]

Check if the given file is image type represented by this class.

Parameters:path (str) -- Path to file to check.
Returns:int -- Confidence that this file matches. 0 is definitely not a match, 100 is definitely a match.
Raises:HelperError -- if no file exists at path.
classmethod for_new_file(path, disk_format, **kwargs)[source]

Create a new disk file and return a DiskRepresentation.

  • path (str) -- Path to create file at.
  • disk_format (str) -- Disk format to create, such as 'iso' or 'vmdk'.
  • **kwargs -- Arguments to pass through to appropriate DiskRepresentation subclass for this format.

DiskRepresentation -- representation of the created file.


NotImplementedError -- if disk_format is not supported.

static from_file(path)[source]

Get a DiskRepresentation instance appropriate to the given file.


path (str) -- Path of existing file to represent.


DiskRepresentation -- Representation of this file.

classmethod from_other_image(input_image, output_dir, output_subformat=None)[source]

Convert the other disk image into an image of this type.

  • input_image (DiskRepresentation) -- Existing image representation.
  • output_dir (str) -- Output directory to store the new image in.
  • output_subformat (str) -- Any relevant subformat information.

NotImplementedError -- Subclasses may implement this.

static subclasses()[source]

List of subclasses of DiskRepresentation.

Wraps the class.__subclasses__() builtin.


Capacity of this disk image, in bytes.

disk_format = None

Sub-format of the disk, such as 'rockridge' or 'streamOptimized'.


List of files embedded in this disk image.


System path to this disk file.


Disk drive type typically used for a Disk of this type.

Returns:str -- 'cdrom' or 'harddisk'