COT.add_disk
module¶
Module for adding disks to VMs.
Functions
add_disk_worker |
Worker function for actually adding the disk. |
confirm_elements |
Get user confirmation of any risky or unusual operations. |
guess_controller_type |
If a controller type wasn’t specified, try to guess from context. |
guess_disk_type_from_extension |
Guess the disk type (harddisk/cdrom) from the disk file name. |
search_for_elements |
Search for a unique set of objects based on the given criteria. |
validate_elements |
Validate any existing file, disk, controller item, and disk item. |
validate_controller_address |
Check validity of the given address string for the given controller. |
Classes
COTAddDisk |
Add or replace a disk in a virtual machine. |
-
class
COTAddDisk
(ui)[source]¶ Bases:
COT.submodule.COTSubmodule
Add or replace a disk in a virtual machine.
Inherited attributes:
UI
,package
,output
Attributes:
disk_image
,type
,file_id
,controller
,subtype
,address
,diskname
,description
-
ready_to_run
()[source]¶ Check whether the module is ready to
run()
.Returns: (True, ready_message)
or(False, reason_why_not)
-
run
()[source]¶ Do the actual work of this submodule.
Raises: InvalidInputError – if ready_to_run()
reportsFalse
-
address
¶ Disk device address on controller (
1:0
, etc.).Raises: InvalidInputError
, seevalidate_controller_address()
-
controller
¶ Disk controller type (
ide
,scsi
).Raises: InvalidInputError
, seevalidate_controller_address()
-
description
= None¶ Description of the disk.
-
disk_image
¶ Path to disk image file to add to the VM.
Raises: InvalidInputError
if the file does not exist.
-
disk_type
= None¶ Disk type (‘harddisk’ or ‘cdrom’).
-
diskname
= None¶ Name string for the disk.
-
file_id
= None¶ File identifier to map disk to file.
-
subtype
= None¶ Controller subtype, such as “virtio”.
-
-
add_disk_worker
(vm, ui, disk_image, disk_type=None, file_id=None, controller=None, subtype=None, address=None, diskname=None, description=None)[source]¶ Worker function for actually adding the disk.
All parameters except
vm
,ui
, anddisk_image
are optional and will be automatically determined by COT if unspecified.Parameters: - vm (
OVF
or otherVMDescription
subclass) – The virtual machine being edited. - ui (instance of
UI
or subclass.) – User interface in effect. - disk_image (str) – path to disk image to add to the VM.
- disk_type (str) – Disk type:
'cdrom'
or'harddisk'
. If not specified, will be derived automatically from the disk_image file name extension. - file_id (str) – Identifier of the disk file in the VM. If not specified, the VM will automatically derive an appropriate value.
- controller (str) – Disk controller type:
'ide'
or'scsi'
. If not specified, will be derived from the type and the platform of the given vm. - subtype (str) – Controller subtype (‘virtio’, ‘lsilogic’, etc.)
- address (str) – Disk device address on its controller
(such as
'1:0'
). If this matches an existing disk device, that device will be overwritten. If not specified, the first available address not already occupied by an existing device will be selected. - diskname (str) – Name for disk device
- description (str) – Description of disk device
- vm (
-
confirm_elements
(vm, ui, file_obj, disk_image, disk_obj, disk_item, disk_type, controller, ctrl_item, subtype)[source]¶ Get user confirmation of any risky or unusual operations.
-
guess_controller_type
(vm, ctrl_item, disk_type)[source]¶ If a controller type wasn’t specified, try to guess from context.
-
guess_disk_type_from_extension
(disk_file)[source]¶ Guess the disk type (harddisk/cdrom) from the disk file name.
-
search_for_elements
(vm, disk_file, file_id, controller, address)[source]¶ Search for a unique set of objects based on the given criteria.
A disk is defined by up to four different sections in the OVF:
File (references the actual disk image file) Disk (references the File, only used for HD not CD-ROM) Item (defines the SCSI/IDE controller) Item (defines the disk drive, links to controller and File or Disk)
For each of these four sections, we need to know whether to add a new one or overwrite an existing one. Depending on the user arguments, we can do this by as many as three different approaches:
- Check whether the DISK_IMAGE file name matches an existing File in the OVF (and from there, find the associated Disk and Items)
- Check whether the file-id matches an existing File and/or Disk in the OVF (and from there, find the associated Items)
- Check whether controller type and/or device address match existing Items in the OVF (and from there, find the associated Disk and/or File)
Where it gets extra fun is if the user has specified more than one of the above arguments - in which case we need to make sure that all relevant approaches agree on what sections we’re talking about...
Raises: ValueMismatchError – if the criteria select a non-unique set. Returns: (file_object, disk_object, controller_item, disk_item)
-
validate_controller_address
(controller, address)[source]¶ Check validity of the given address string for the given controller.
Helper method for the
controller
/address
setters.Parameters: - controller (str) –
'ide'
or'scsi'
- address (str) – A string like ‘0:0’ or ‘2:10’
Raises: InvalidInputError
if the address/controller combo is invalid.- controller (str) –