master.lib.vm package¶
Submodules¶
master.lib.vm.manage module¶
The manage module contains classes to manage VM creation, conversion, snapshots, and exporting
-
class
master.lib.vm.manage.
LibvirtWorker
(image_path, idx, log)[source]¶ Bases:
master.lib.vm.manage.VMWorker
A worker for managing a running libvirt vms directly (not via vagrant)
-
class
master.lib.vm.manage.
VMManager
(vagrant_base='~/.vagrant.d', image_store='/var/lib/libvirt/images', parent_log=None, **opts)[source]¶ Bases:
object
VMManager class is responsible for creating and managing VM images.
It is intended to be able to handle:
- converting VM images from various file formats to qcow2
- running Vagrant files on base images to configure VMs
- saving off a snapshot of the configured VM (in qcow2 format with backing files (a snapshot chain)
- exporting VM images into various file formats
- fetching a list of all backing file names/md5s
This class will block until all operations are complete.
-
configure_image
(box_name, vagrantfile, user_interaction=False, on_success=None)[source]¶ Configure the existing vagrant box with the supplied vagrantfile. If
user_interaction
is True, a dict will be returned with vm worker info in the format:{ "worker": WORKER_NUMBER, "vnc": { "uri": "vnc:///HOSTNAME:PORT" } }
The worker number may be passed to
shutdown_worker()
to shutdown a running VM ifuser_interaction
was set to True.Box_name: The name of the box to configure Vagrantfile: The name of the vagrantfile to configure User_interaction: If user-interaction is expected (e.g. if only doing auto-updates w/ a Vagrantfile, set to False) Returns: None
-
create_image
(vagrantfile, base_name, dest_name, user_interaction=False, on_success=None)[source]¶ Use the vagrantfile to create a new image using the vagrant box specified by base_name. If
user_interaction
is True, a dict will be returned with vm worker info in the format:{ "worker": WORKER_NUMBER, "vnc": { "uri": "vnc:///HOSTNAME:PORT" } }
The worker number may be passed to
shutdown_worker()
to shutdown a running VM ifuser_interaction
was set to True.Vagrantfile: Contents of the Vagrant file with a $$BASE_IMAGE$$ placeholder for the base box Base_name: The name of the base vagrant box Dest_name: The name of the new vagrant box User_interaction: If user interaction will be allowed (will not immediately cleanup, and a vnc url will be returned) Returns: A VM info (including vnc connection info) if user_interaction
is True; else returns None
-
delete_image
(image_name)[source]¶ Delete the image specified by
image_name
. Note that this WILL NOT check for images that useimage_name
as their base.Image_name: The name of the image to delete Returns: None
-
export_image
(image_name, output_type=None)[source]¶ Export the image specified by image_name to output_type VM image. Supported output types are qcow2, ova, vmdk, and vid. (TODO: vagrant box output? <name>.box?)
Image_name: Name of the image to export (probably a UUID) Output_type: Optionally specify the output format. Defaults to qcow2 Returns: Path to an exported VM image
-
import_image
(image_path, image_name, user_interaction=False, iso_path=None, username='user', password='password', on_success=None)[source]¶ Import the image into talus with the name
image_name
, optionally runningvagrantfile
on the newly created box and applying the changes. Ifuser_interaction
is True, worker and vnc info will be returned in a dict:{ "worker": WORKER_NUMBER, "vnc": { "uri": "vnc:///HOSTNAME:PORT" } }
The worker number may be passed to
shutdown_worker()
to shutdown a running VM ifuser_interaction
was set to True.Image_path: The path to the image to be imported Image_name: The name of the resulting image User_interaction: True/False if the user should be allowed to interact with the imported VM (default=False) Iso_path: Path to an iso to be mounted after booting up (default: None) On_success: Callback to be called with the image name on successful completion Returns: TODO
-
class
master.lib.vm.manage.
VMWorker
(idx, log)[source]¶ Bases:
threading.Thread
A threaded class that manages individual VMs
-
class
master.lib.vm.manage.
VagrantWorker
(box_name, vagrantfile, idx, log, vagrant_base='~/.vagrant.d', image_store='/var/lib/libvirt/images', dest_name=None, import_image_path=None, iso_path=None, on_success=None, user_interaction=False, **options)[source]¶ Bases:
master.lib.vm.manage.VMWorker
A worker for managing a running vagrant image
master.lib.vm.utils module¶
-
master.lib.vm.utils.
get_image_format
(image_path)[source]¶ Get the format of the VM image at image_path
Image_path: The path to the VM image Returns: The format of the VM image, or None if it cannot be determined
-
master.lib.vm.utils.
qemu_convert_image
(image_path, target_format, target_path=None, orig_format=None)[source]¶ qemu_convert_image will conver the image found at image_path to the specified format. It is expected that original file-type detection will be used. The resulting image will be saved to target_path
Image_path: The path to the image (e.g. qcow2, vmdk, vdi, raw) Target_format: The target format (e.g. qcow2, vmdk, vdi, raw) Target_path: [optional] The path to save the converted image to Orig_format: [optional] the format of the original image Returns: The path the converted image was saved to, potentially the same as the original path Raises: Exception if the original file format cannot be determined or if the image path does not exist
-
master.lib.vm.utils.
qemu_img_info
(image_path)[source]¶ Return a dict of info returned by qemu-img info. Assumes the image_path exists and points to a valid VM image
Image_path: path to the image Returns: dict of returned information about the image
-
master.lib.vm.utils.
run
(args, async=False, shell=True, env=None, output_to_stdout=False)[source]¶ Run the command specified by the array args and return the output. If
async
is True, the proc object will be returnedArgs: An array of command arguments to be run Async: If true, return immediately with the proc object Returns: output of the command or the proc object if async