COT.commands module

Package describing various operations COT can perform on a VM description.

API

Command Abstract interface for COT commands.
ReadCommand Command, such as 'deploy', that reads from a VM file to create its vm.
ReadWriteCommand Command that reads from and writes to a VM description.

Command modules

COT.commands.add_disk Module for adding disks to VMs.
COT.commands.add_file Module for adding files to VM definitions.
COT.commands.deploy Module for deploying VM descriptions to a hypervisor to instantiate VMs.
COT.commands.deploy_esxi Module for deploying VMs to ESXi, vCenter, and vSphere.
COT.commands.edit_hardware Module for editing hardware details of a VM.
COT.commands.edit_product Module for editing product information in a VM description.
COT.commands.edit_properties Module for managing VM environment configuration properties.
COT.commands.help Provide 'help' keyword for COT CLI.
COT.commands.info Implements "info" subcommand.
COT.commands.inject_config Implements "inject-config" command.
COT.commands.install_helpers Implements "install-helpers" command.
COT.commands.remove_file Module for removing files from VM definitions.
class Command(ui)[source]

Bases: object

Abstract interface for COT commands.

Attributes: vm, ui

Note

Generally a command should not inherit directly from this class, but should instead subclass ReadCommand or ReadWriteCommand as appropriate.

__init__(ui)[source]

Instantiate this command with the given UI.

Parameters:ui (UI) -- User interface instance.
check_disk_space(required_size, location, label='File', context=None, force_check=False, die=False)[source]

Check if there is sufficient disk space available at a location.

If there is insufficient space, warn the user before continuing.

Caches space requirements per location, so it's safe to call repeatedly, as it will only re-check (and possibly re-prompt the user) if:

  1. a different location is requested
  2. or the required size changes
  3. or force_check is True.
Parameters:
  • required_size (int) -- Bytes required
  • location (str) -- Path to check availability of.
  • label (str) -- Descriptive label to display in user messages.
  • context (str) -- Optional string for additional context to provide when prompting the user.
  • force_check (bool) -- If True, re-check and re-prompt the user even if this location has previously been checked and its required_size has not changed.
  • die (bool) -- If True, use confirm_or_die() instead of confirm()
Returns:

bool --

Whether sufficient space is available (or if not,

whether the user has opted to continue anyway).

Raises:

SystemExit -- if disk space is insufficient and die is True and the user declines to continue.

create_subparser()[source]

Add subparser for the CLI of this command.

destroy()[source]

Destroy any VM associated with this command.

finished()[source]

Do any final actions before being destroyed.

This class does nothing; subclasses may choose to do things like write their VM state out to a file.

ready_to_run()[source]

Check whether the module is ready to run().

Returns:tuple -- (True, ready_message) or (False, reason_why_not)
run()[source]

Do the actual work of this command.

Raises:InvalidInputError -- if ready_to_run() reports False
working_dir_disk_space_required()[source]

How much space this module will require in working_dir.

By default, assumes the entire VM may be written to working directory. Subclasses may wish to extend or override this.

Returns:int -- Predicted temporary storage requirements.
ui = None

User interface instance (UI or subclass).

vm = None

Virtual machine description (VMDescription).

class ReadCommand(ui)[source]

Bases: COT.commands.command.Command

Command, such as 'deploy', that reads from a VM file to create its vm.

Inherited attributes: vm, ui

Attributes: package

__init__(ui)[source]

Instantiate this command with the given UI.

Parameters:ui (UI) -- User interface instance.
ready_to_run()[source]

Check whether the module is ready to run().

Returns:tuple -- (True, ready_message) or (False, reason_why_not)
package

VM description file to read from.

Calls COT.vm_description.VMDescription.factory() to instantiate self.vm from the provided file.

Raises:InvalidInputError -- if the file does not exist.
class ReadWriteCommand(ui)[source]

Bases: COT.commands.command.ReadCommand

Command that reads from and writes to a VM description.

Inherited attributes: vm, ui

Attributes: package, output

__init__(ui)[source]

Instantiate this command with the given UI.

Parameters:ui (UI) -- User interface instance.
finished()[source]

Write the current VM state out to disk if requested.

ready_to_run()[source]

Check whether the module is ready to run().

Returns:tuple -- (True, ready_message) or (False, reason_why_not)
run()[source]

Do the actual work of this command.

If output was not previously set, automatically sets it to the value of PACKAGE.

Raises:InvalidInputError -- if ready_to_run() reports False
output

Output file for this command.

If the specified file already exists, will prompt the user (confirm_or_die()) to confirm overwriting the existing file.

package

VM description file to read from.

Calls COT.vm_description.VMDescription.factory() to instantiate self.vm from the provided file.

Raises:InvalidInputError -- if the file does not exist.