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.).

API

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.

__init__(path)[source]

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.

Parameters:
  • 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.
Returns:

DiskRepresentation -- Converted disk

Raises:

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.

Parameters:
  • 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.
Raises:
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.

Parameters:
  • 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.
Returns:

DiskRepresentation -- representation of the created file.

Raises:

NotImplementedError -- if disk_format is not supported.

static from_file(path)[source]

Get a DiskRepresentation instance appropriate to the given file.

Parameters:

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

Returns:

DiskRepresentation -- Representation of this file.

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

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

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

NotImplementedError -- Subclasses may implement this.

static subclasses()[source]

List of subclasses of DiskRepresentation.

Wraps the class.__subclasses__() builtin.

capacity

Capacity of this disk image, in bytes.

disk_format = None

Disk format represented by this class.

disk_subformat

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

files

List of files embedded in this disk image.

path

System path to this disk file.

predicted_drive_type

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

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