lago.providers.libvirt package

Submodules

lago.providers.libvirt.cpu module

class lago.providers.libvirt.cpu.CPU(spec, host_cpu)[source]

Bases: object

cpu_xml
generate_cpu_xml()[source]

Get CPU XML

Returns:cpu node
Return type:lxml.etree.Element
generate_custom(cpu, vcpu_num, fill_topology)[source]

Generate custom CPU model. This method attempts to convert the dict to XML, as defined by xmltodict.unparse method.

Parameters:
  • cpu (dict) – CPU spec
  • vcpu_num (int) – number of virtual cpus
  • fill_topology (bool) – if topology is not defined in cpu and vcpu was not set, will add CPU topology to the generated CPU.
Returns:

CPU XML node

Return type:

lxml.etree.Element

Raises:

LagoInitException – when failed to convert dict to XML

generate_exact(model, vcpu_num, host_cpu)[source]

Generate exact CPU model with nested virtualization CPU feature.

Parameters:
  • model (str) – libvirt supported CPU model
  • vcpu_num (int) – number of virtual cpus
  • host_cpu (lxml.etree.Element) – the host CPU model
Returns:

CPU XML node

Return type:

lxml.etree.Element

generate_feature(name, policy='require')[source]

Generate CPU feature element

Parameters:
  • name (str) – feature name
  • policy (str) – libvirt feature policy
Returns:

feature XML element

Return type:

lxml.etree.Element

generate_host_passthrough(vcpu_num)[source]

Generate host-passthrough XML cpu node

Parameters:vcpu_num (int) – number of virtual CPUs
Returns:CPU XML node
Return type:lxml.etree.Element
generate_topology(vcpu_num, cores=1, threads=1)[source]

Generate CPU <topology> XML child

Parameters:
  • vcpu_num (int) – number of virtual CPUs
  • cores (int) – number of cores
  • threads (int) – number of threads
Returns:

topology XML element

Return type:

lxml.etree.Element

generate_vcpu(vcpu_num)[source]

Generate <vcpu> domain XML child

Parameters:vcpu_num (int) – number of virtual cpus
Returns:vcpu XML element
Return type:lxml.etree.Element
generate_vcpu_xml(vcpu_num)[source]
Parameters:vcpu_num (int) – number of virtual cpus
Returns:vcpu XML node
Return type:lxml.etree.Element
model
validate()[source]

Validate CPU-related VM spec are compatible

Raises:LagoInitException – if both ‘cpu_model’ and ‘cpu’ are defined.
vcpu_xml
vendor
class lago.providers.libvirt.cpu.LibvirtCPU[source]

Bases: object

Query data from /usr/share/libvirt/cpu_map.xml

classmethod get_cpu_props(family, arch='x86')[source]

Get CPU info XML

Parameters:
  • family (str) – CPU family
  • arch (str) – CPU arch
Returns:

CPU xml

Return type:

lxml.etree.Element

Raises:

LagoException – If no such CPU family exists

classmethod get_cpu_vendor(family, arch='x86')[source]

Get CPU vendor, if vendor is not available will return ‘generic’

Parameters:
  • family (str) – CPU family
  • arch (str) – CPU arch
Returns:

CPU vendor if found otherwise ‘generic’

Return type:

str

classmethod get_cpus_by_arch(arch)[source]

Get all CPUs info by arch

Parameters:arch (str) – CPU architecture
Returns:CPUs by arch XML
Return type:lxml.etree.element
Raises:LagoException – If no such ARCH is found

lago.providers.libvirt.network module

class lago.providers.libvirt.network.BridgeNetwork(env, spec, compat)[source]

Bases: lago.providers.libvirt.network.Network

_libvirt_xml()[source]
start()[source]
stop()[source]
class lago.providers.libvirt.network.NATNetwork(env, spec, compat)[source]

Bases: lago.providers.libvirt.network.Network

_generate_dns_disable()[source]
_generate_dns_forward(forward_ip)[source]
_generate_main_dns(records, subnet, forward_plain='no')[source]
_ipv6_prefix(subnet, const='fd8f:1391:3a82:')[source]
_libvirt_xml()[source]
class lago.providers.libvirt.network.Network(env, spec, compat)[source]

Bases: object

_libvirt_name()[source]
_libvirt_xml()[source]
add_mapping(name, ip, save=True)[source]
add_mappings(mappings)[source]
alive()[source]
gw()[source]
is_management()[source]
mapping()[source]
name()[source]
resolve(name)[source]
save()[source]
spec
start(attempts=5, timeout=2)[source]

Start the network, will check if the network is active attempts times, waiting timeout between each attempt.

Parameters:
  • attempts (int) – number of attempts to check the network is active
  • timeout (int) – timeout for each attempt
Returns:

None

Raises:
  • RuntimeError – if network creation failed, or failed to verify it is
  • active.
stop()[source]

lago.providers.libvirt.utils module

Utilities to help deal with the libvirt python bindings

lago.providers.libvirt.utils.DOMAIN_STATES = {<class 'sphinx.ext.autodoc.VIR_DOMAIN_SHUTOFF'>: 'shut off', <class 'sphinx.ext.autodoc.VIR_DOMAIN_BLOCKED'>: 'blocked', <class 'sphinx.ext.autodoc.VIR_DOMAIN_PMSUSPENDED'>: 'suspended', <class 'sphinx.ext.autodoc.VIR_DOMAIN_NOSTATE'>: 'no state', <class 'sphinx.ext.autodoc.VIR_DOMAIN_SHUTDOWN'>: 'beign shut down', <class 'sphinx.ext.autodoc.VIR_DOMAIN_RUNNING'>: 'running', <class 'sphinx.ext.autodoc.VIR_DOMAIN_CRASHED'>: 'crashed', <class 'sphinx.ext.autodoc.VIR_DOMAIN_PAUSED'>: 'paused'}

Mapping of domain statuses values to human readable strings

class lago.providers.libvirt.utils.Domain[source]

Bases: object

Class to namespace libvirt domain related helpers

static resolve_state(state_number)[source]

Get a nice description from a domain state number

Parameters:state_number (list of int) – State number as returned by libvirt.virDomain.state()
Returns:
small human readable description of the domain state, unknown
if the state is not in the known list
Return type:str
lago.providers.libvirt.utils.LIBVIRT_CONNECTIONS = {}

Singleton with the cached opened libvirt connections

lago.providers.libvirt.utils.auth_callback(credentials, user_data)[source]
lago.providers.libvirt.utils.dict_to_xml(spec, full_document=False)[source]

Convert dict to XML

Parameters:
  • spec (dict) – dict to convert
  • full_document (bool) – whether to add XML headers
Returns:

XML tree

Return type:

lxml.etree.Element

lago.providers.libvirt.utils.get_libvirt_connection(name, libvirt_url='qemu://system')[source]
lago.providers.libvirt.utils.get_template(basename)[source]

Load a file as a string from the templates directory

Parameters:basename (str) – filename
Returns:string representation of the file
Return type:str

lago.providers.libvirt.vm module

class lago.providers.libvirt.vm.LocalLibvirtVMProvider(vm)[source]

Bases: lago.plugins.vm.VMProviderPlugin

_create_dead_snapshot(name)[source]
_create_live_snapshot(name)[source]
_extract_paths_gfs(paths, ignore_nopath)[source]
_libvirt_name()[source]
_libvirt_xml()[source]
_load_domain_xml()[source]
_reclaim_disk(path)[source]
_reclaim_disks()[source]
_shutdown(libvirt_cmd, ssh_cmd, msg)[source]

Choose the invoking method (using libvirt or ssh) to shutdown / poweroff the domain.

If acpi is defined in the domain use libvirt, otherwise use ssh.

Parameters:
  • libvirt_cmd (function) – Libvirt function the invoke
  • ssh_cmd (list of str) – Shell command to invoke on the domain
  • msg (str) – Name of the command that should be inserted to the log message.
Returns
None
Raises:RuntimeError – If acpi is not configured an ssh isn’t available
bootstrap()[source]
cpu_model

VM CPU model

Returns:CPU model
Return type:str
cpu_vendor

VM CPU Vendor

Returns:CPU vendor
Return type:str
create_snapshot(name)[source]
defined()[source]
export_disks(standalone, dst_dir, compress, *args, **kwargs)[source]

Exports all the disks of self. For each disk type, handler function should be added.

Parameters:
  • standalone (bool) – if true, merge the base images and the layered image into a new file (Supported only in qcow2 format)
  • dst_dir (str) – dir to place the exported disks
  • compress (bool) – if true, compress each disk.
extract_paths(paths, ignore_nopath)[source]

Extract the given paths from the domain

Attempt to extract all files defined in paths with the method defined in extract_paths(), if it fails, will try extracting the files with libguestfs.

Parameters:
  • paths (list of str) – paths to extract
  • ignore_nopath (boolean) – if True will ignore none existing paths.
Returns:

None

Raises:
interactive_console(*args, **kwargs)[source]

Opens an interactive console

Returns:result of the virsh command execution
Return type:lago.utils.CommandStatus
reboot(*args, **kwargs)[source]
revert_snapshot(name)[source]
shutdown(*args, **kwargs)[source]
start()[source]
state()[source]

Return a small description of the current status of the domain

Returns:small description of the domain status, ‘down’ if it’s not defined at all.
Return type:str
stop()[source]
lago.providers.libvirt.vm._guestfs_copy_path(guestfs_conn, guest_path, host_path)[source]