Libvirt Compute Driver Documentation

Note

Libvirt driver in current version of Libcloud is still experimental and doesn’t support advanced functionality like creating a node and so on.

libvirt is an open source toolkit for managing different hypervisors. It ca be used to manage Xen, KVM, Vmware ESX, QEMU and many other hypervisors.

../../_images/libvirt.png

For full list of the supported hypervisors, please see the Hypervisor drivers page.

Requirements

To be able to use this driver you need to install libvirt client and libvirt-python Python package.

Libvirt client is available in standard package repositories of most popular Linux distributions which means you can install it using your distribution’s package manager.

Example #1 - Ubuntu, Debian, etc. (apt-get):

sudo apt-get install libvirt-client

Example #2 - Fedora, RHEL, etc. (yum):

sudo yum install libvirt-client

Python package can be installed using pip:

pip install libvirt-python

Connecting to a hypervisor

To instantiate the driver and connect to a hypervisor, you need to pass uri argument to the driver constructor.

This argument tells the driver which libvirt driver (qemu, xen, virtualbox, etc.) this connection refers to. For a full list of supported URIs, please refer to the Connection URIs <http://libvirt.org/uri.html> page.

Example 1 - Connecting to QEMU and KVM hypervisor

This example shows how to connect to a local QEMU or KVM instance.

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.LIBVIRT)
driver = cls(uri='qemu:///system')

For more details and information on how to connect to a remote instance, please see Connections to QEMU driver page.

Example 2 - Connecting to Virtualbox hypervisor

This example shows how to connect to a local Virtualbox instance.

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.LIBVIRT)
driver = cls(uri='vbox:///session')

For more details and information on how to connect to a remote instance, please see VirtualBox hypervisor driver page.

Enabling libvirt debug mode

To enable libvirt debug mode, simply set LIBVIRT_DEBUG environment variable.

For example:

LIBVIRT_DEBUG=1 python my_script.py

When debug mode is enabled, libvirt client will print all kind of debugging information to the standard error.

API Docs