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_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: 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: Returns: CPU XML node
Return type: lxml.etree.Element
-
generate_feature
(name, policy='require')[source]¶ Generate CPU feature element
Parameters: Returns: feature XML element
Return type: lxml.etree.Element
-
generate_host_passthrough
(vcpu_num)[source]¶ Generate host-passthrough XML cpu node
Parameters: vcpu_num (str) – number of virtual CPUs Returns: CPU XML node Return type: lxml.etree.Element
-
generate_numa
(vcpu_num)[source]¶ Generate guest CPU <numa> XML child Configures 1, 2 or 4 vCPUs per cell.
Parameters: vcpu_num (str) – number of virtual CPUs Returns: numa XML element Return type: lxml.etree.Element
-
generate_topology
(vcpu_num, cores=1, threads=1)[source]¶ Generate CPU <topology> XML child
Parameters: Returns: topology XML element
Return type: lxml.etree.Element
-
generate_vcpu
(vcpu_num)[source]¶ Generate <vcpu> domain XML child
Parameters: vcpu_num (str) – 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_custom’ 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: Returns: CPU xml
Return type: lxml.etree.Element
Raises: LagoException
– If no such CPU family exists
-
classmethod
lago.providers.libvirt.network module¶
-
class
lago.providers.libvirt.network.
BridgeNetwork
(env, spec, compat)[source]¶ Bases:
lago.providers.libvirt.network.Network
-
start
()[source]¶ Start the network, will check if the network is active
attempts
times, waitingtimeout
between each attempt.Parameters: Returns: None
Raises: RuntimeError
– if network creation failed, or failed to verify it isactive.
-
-
class
lago.providers.libvirt.network.
Network
(env, spec, compat)[source]¶ Bases:
object
-
spec
¶
-
start
(attempts=5, timeout=2)[source]¶ Start the network, will check if the network is active
attempts
times, waitingtimeout
between each attempt.Parameters: Returns: None
Raises: RuntimeError
– if network creation failed, or failed to verify it isactive.
-
lago.providers.libvirt.utils module¶
-
lago.providers.libvirt.utils.
DOMAIN_STATES
= {<sphinx.ext.autodoc.importer._MockObject object>: 'no state', <sphinx.ext.autodoc.importer._MockObject object>: 'running', <sphinx.ext.autodoc.importer._MockObject object>: 'blocked', <sphinx.ext.autodoc.importer._MockObject object>: 'paused', <sphinx.ext.autodoc.importer._MockObject object>: 'begin shut down', <sphinx.ext.autodoc.importer._MockObject object>: 'shut off', <sphinx.ext.autodoc.importer._MockObject object>: 'crashed', <sphinx.ext.autodoc.importer._MockObject object>: 'suspended'}¶ 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
-
static
-
lago.providers.libvirt.utils.
LIBVIRT_CONNECTIONS
= {}¶ Singleton with the cached opened libvirt connections
-
lago.providers.libvirt.utils.
dict_to_xml
(spec, full_document=False)[source]¶ Convert dict to XML
Parameters: Returns: XML tree
Return type: lxml.etree.Element
-
lago.providers.libvirt.utils.
get_domain_template
(distro, libvirt_ver, **kwargs)[source]¶ Get a rendered Jinja2 domain template
Parameters: Returns: rendered template
Return type:
lago.providers.libvirt.vm module¶
-
exception
lago.providers.libvirt.vm.
LagoLocalLibvirtVMProviderException
[source]¶ Bases:
lago.utils.LagoException
-
class
lago.providers.libvirt.vm.
LocalLibvirtVMProvider
(vm)[source]¶ Bases:
lago.plugins.vm.VMProviderPlugin
-
_get_domain
()[source]¶ Return the object representation of this provider VM.
Returns: Libvirt domain object Return type: libvirt.virDomain Raises: exc:`~lago.plugins.vm.LagoFailedToGetVMStateError: If the VM exist, but the query returned an error.
-
_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]¶ Does any actions needed to get the domain ready to be used, ran on prefix init. :returns: None
-
caps
¶
-
cpu
¶
-
create_snapshot
(name)[source]¶ Take any actions needed to create a snapshot :param name: Name for the snapshot, will be used as key to retrieve
it laterReturns: None
-
export_disks
(standalone, dst_dir, compress, collect_only=False, with_threads=True, *args, **kwargs)[source]¶ Export all the disks of self.
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.
- collect_only (bool) – If true, return only a dict which maps between the name of the vm to the paths of the disks that will be exported (don’t export anything).
- with_threads (bool) – If True, export disks in parallel
Returns: which maps between the name of the vm to the paths of the disks that will be exported
Return type: (dict)
-
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 inextract_paths()
, if it fails, and guestfs is available it will try extracting the files with guestfs.Parameters: - paths (list of tuples) – files to extract in [(src1, dst1), (src2, dst2)…] format.
- ignore_nopath (boolean) – if True will ignore none existing paths.
Returns: None
Raises: ExtractPathNoPathError
– if a none existing path was found on the VM, and ignore_nopath is False.ExtractPathError
– on all other failures.
-
extract_paths_dead
(paths, ignore_nopath)[source]¶ Extract the given paths from the domain using guestfs. Using guestfs can have side-effects and should be used as a second option, mainly when SSH is not available.
Parameters: - paths (list of str) – paths to extract
- ignore_nopath (boolean) – if True will ignore none existing paths.
Returns: None
Raises: LagoException
– ifguestfs
is not importable.ExtractPathNoPathError
– if a none existing path was found on the VM, and ignore_nopath is True.ExtractPathError
– on failure extracting the files.
-
interactive_console
()[source]¶ Opens an interactive console
Returns: result of the virsh command execution Return type: lago.utils.CommandStatus
-
libvirt_ver
¶
-
raw_state
()[source]¶ Return the state of the domain in Libvirt’s terms
- Retruns:
- tuple of ints: The state and its reason
Raises: LagoVMDoesNotExistError
– If the VM of this provider doesn’t exist.- exc:`~lago.plugins.vm.LagoFailedToGetVMStateError: If the VM exist, but the query returned an error.
-
revert_snapshot
(name)[source]¶ Take any actions needed to revert/restore a snapshot :param name: Name for the snapshot, same that was set on creation :type name: str
Returns: None
-
-
lago.providers.libvirt.vm.
log_task
(task, level='info', propagate_fail=True, uuid=None)¶ Parameterized decorator to wrap a function in a log task
Example
>>> @log_task('mytask') ... def do_something(): ... pass