Handling Virtual Machines (VMs)

The pyti.vms modules handles all the VM features, such as start, stop, rollback etc. It is the central and prefered way to control the different virtual machines on the Python Testing Infrastructure.

Its original goal is to be used on the slaves of the master/slave architecture. It is able to: mount different disks to a VM, start it, wait until it stops and return information about the changes that have been made on the filesystem.

Terminology

The terminology used here is mainly coming from libvirt. Here are some definitions, you can refer yourself to the libvirt documentation for more information.

VirtualMachine class

To deal with virtual machines, you will use the VirtualMachine class.

To initialize a VirtualMachine object include VM name, Connection object(which represents the hypervisor VirtualBox), configuration by either an XML file or by a python dictionary:

>>> VirtualMachine('arch linux #1', "vbox:///session", config=config)

You can specify it using the xmlfile argument:

>>> VirtualMachine('arch linux #1', "vbox:///session",
        xmlfile="yourfile.xml")

For config as a dictionary, you should specify:

  • a name
  • the memory
  • the disk location (of the iso file) (optional parameter for live boot)
  • the hard disk location(of the virtual hard disk file)

For instance:

config = {
    'name': 'virtual machine A',
    'memory': '128',
    'disk_location': 'dsl.iso',
    'hd_location':'disk.vdi'
}

Example

The following example starts a Virtual Machine, creates a snapshot and rollbacks:

>>> from vms import *
>>> config = {'name': 'test123', 'memory':'123', \
          'disk_location': 'dsl-4.4.10.iso', \
          'hd_location': 'disk.vdi'}
>>> a = VirtualMachine('hey', "vbox:///session", config=config)
>>> a.start()
>>> a.createSnapshot('hello', 'blah')
>>> a.rollback('hello')