The nova.virt.libvirt.driver Module

A connection to a hypervisor through libvirt.

Supports KVM, LXC, QEMU, UML, and XEN.

Related Flags

libvirt_type:Libvirt domain type. Can be kvm, qemu, uml, xen (default: kvm).
libvirt_uri:Override for the default libvirt URI (depends on libvirt_type).
libvirt_disk_prefix:
 Override the default disk prefix for the devices attached to a server.
rescue_image_id:
 Rescue ami image (None = original image).
rescue_kernel_id:
 Rescue aki image (None = original image).
rescue_ramdisk_id:
 Rescue ari image (None = original image).
injected_network_template:
 Template file for injected network
allow_same_net_traffic:
 Whether to allow in project network traffic
class HostState(read_only)

Bases: object

Manages information about the compute node through libvirt

get_host_stats(refresh=False)

Return the current state of the host.

If ‘refresh’ is True, run update the stats first.

update_status()

Retrieve status info from libvirt.

class LibvirtDriver(read_only=False)

Bases: nova.virt.driver.ComputeDriver

add_to_aggregate(context, aggregate, host, **kwargs)

Add a compute host to an aggregate.

attach_volume(*args, **kw)
block_stats(instance_name, disk)

Note that this function takes an instance name.

check_can_live_migrate_destination(ctxt, instance_ref, block_migration=False, disk_over_commit=False)

Check if it is possible to execute live migration.

This runs checks on the destination host, and then calls back to the source host to check the results.

Parameters:
  • ctxt – security context
  • instance_ref – nova.db.sqlalchemy.models.Instance
  • dest – destination host
  • block_migration – if true, prepare for block migration
  • disk_over_commit – if true, allow disk over commit
check_can_live_migrate_destination_cleanup(ctxt, dest_check_data)

Do required cleanup on dest host after check_can_live_migrate calls

Parameters:
  • ctxt – security context
  • disk_over_commit – if true, allow disk over commit
check_can_live_migrate_source(ctxt, instance_ref, dest_check_data)

Check if it is possible to execute live migration.

This checks if the live migration can succeed, based on the results from check_can_live_migrate_destination.

Parameters:
  • context – security context
  • instance_ref – nova.db.sqlalchemy.models.Instance
  • dest_check_data – result of check_can_live_migrate_destination
confirm_migration(migration, instance, network_info)

Confirms a resize, destroying the source VM

destroy(instance, network_info, block_device_info=None)
detach_volume(*args, **kw)
disk_cachemode
ensure_filtering_rules_for_instance(instance_ref, network_info, time_module=None)

Ensure that an instance’s filtering rules are enabled.

When migrating an instance, we need the filtering rules to be configured on the destination host before starting the migration.

Also, when restarting the compute service, we need to ensure that filtering rules exist for all running services.

filter_defer_apply_off()
filter_defer_apply_on()
finish_migration(*args, **kw)
finish_revert_migration(*args, **kw)
get_all_block_devices()

Return all block devices in use on this node.

get_available_resource()

Retrieve resource info.

This method is called as a periodic task and is used only in live migration currently.

Returns:dictionary containing resource info
get_console_output(*args, **kw)
get_console_pool_info(console_type)
get_cpu_info()

Get cpuinfo information.

Obtains cpu feature from virConnect.getCapabilities, and returns as a json string.

Returns:see above description
get_diagnostics(instance)
get_disk_available_least()

Return disk available least size.

The size of available disk, when block_migration command given disk_over_commit param is FALSE.

The size that deducted real nstance disk size from the total size of the virtual disk of all instances.

get_disks(instance_name)

Note that this function takes an instance name.

Returns a list of all block devices for this domain.

get_guest_config(instance, network_info, image_meta, rescue=None, block_device_info=None)

Get config data for parameters.

Parameters:rescue – optional dictionary that should contain the key ‘ramdisk_id’ if a ramdisk is needed for the rescue image and ‘kernel_id’ if a kernel is needed for the rescue image.
get_guest_cpu_config()
get_guest_storage_config(instance, image_meta, rescue, block_device_info, inst_type, root_device_name, root_device)
get_host_capabilities()

Returns an instance of config.LibvirtConfigCaps representing the capabilities of the host

get_host_cpu_for_guest()

Returns an instance of config.LibvirtConfigGuestCPU representing the host’s CPU model & topology with policy for configuring a guest to match

static get_host_ip_addr()
get_host_stats(refresh=False)

Return the current state of the host.

If ‘refresh’ is True, run update the stats first.

get_host_uptime(host)

Returns the result of calling “uptime”.

get_hypervisor_hostname()

Returns the hostname of the hypervisor.

get_hypervisor_type()

Get hypervisor type.

Returns:hypervisor type (ex. qemu)
get_hypervisor_version()

Get hypervisor version.

Returns:hypervisor version (ex. 12003)
get_info(instance)

Retrieve information from libvirt for a specific instance name.

If a libvirt error is encountered during lookup, we might raise a NotFound exception or Error exception depending on how severe the libvirt error is.

get_instance_capabilities()

Get hypervisor instance capabilities

Returns a list of tuples that describe instances the hypervisor is capable of hosting. Each tuple consists of the triplet (arch, hypervisor_type, vm_mode).

Returns:List of tuples describing instance capabilities
get_instance_disk_info(instance_name)

Preparation block migration.

Params ctxt:security context
Params instance_ref:
 nova.db.sqlalchemy.models.Instance object instance object that is migrated.
Returns:json strings with below format:
"[{'path':'disk', 'type':'raw',
  'virt_disk_size':'10737418240',
  'backing_file':'backing_file',
  'disk_size':'83886080'},...]"
get_interfaces(xml)

Note that this function takes an domain xml.

Returns a list of all network interfaces for this instance.

static get_local_gb_total()

Get the total hdd size(GB) of physical computer.

Returns:The total amount of HDD(GB). Note that this value shows a partition where NOVA-INST-DIR/instances mounts.
get_local_gb_used()

Get the free hdd size(GB) of physical computer.

Returns:The total usage of HDD(GB). Note that this value shows a partition where NOVA-INST-DIR/instances mounts.
static get_lxc_container_root(virt_dom)
static get_lxc_container_target(xml)
static get_lxc_host_device(xml)
get_memory_mb_total()

Get the total memory size(MB) of physical computer.

Returns:the total amount of memory(MB).
get_memory_mb_used()

Get the free memory size(MB) of physical computer.

Returns:the total usage of memory(MB).
get_num_instances()

Efficient override of base instance_exists method.

static get_vcpu_total()

Get vcpu number of physical computer.

Returns:the number of cpu core.
get_vcpu_used()

Get vcpu usage number of physical computer.

Returns:The total number of vcpu that currently used.
get_vnc_console(*args, **kw)
get_volume_connector(instance)
has_min_version(ver)
host_maintenance_mode(host, mode)

Start/Stop host maintenance window. On start, it triggers guest VMs evacuation.

host_power_action(host, action)

Reboots, shuts down or powers up the host.

host_state
init_host(host)
instance_exists(instance_id)

Efficient override of base instance_exists method.

interface_stats(instance_name, interface)

Note that this function takes an instance name.

list_instance_ids()
list_instances()
live_migration(ctxt, instance_ref, dest, post_method, recover_method, block_migration=False, migrate_data=None)

Spawning live_migration operation for distributing high-load.

Params ctxt:security context
Params instance_ref:
 nova.db.sqlalchemy.models.Instance object instance object that is migrated.
Params dest:destination host
Params block_migration:
 destination host
Params post_method:
 post operation method. expected nova.compute.manager.post_live_migration.
Params recover_method:
 recovery method when any exception occurs. expected nova.compute.manager.recover_live_migration.
Params block_migration:
 if true, do block migration.
Params migrate_data:
 implementation specific params
manage_image_cache(context)

Manage the local cache of images.

migrate_disk_and_power_off(*args, **kw)
pause(*args, **kw)

Pause VM instance

plug_vifs(instance, network_info)

Plug VIFs into networks.

poll_rebooting_instances(*args, **kw)
poll_rescued_instances(*args, **kw)
post_live_migration_at_destination(ctxt, instance_ref, network_info, block_migration)

Post operation of live migration at destination host.

Parameters:
  • ctxt – security context
  • instance_ref – nova.db.sqlalchemy.models.Instance object instance object that is migrated.
  • network_info – instance network infomation
  • block_migration – if true, post operation of block_migraiton.
power_off(*args, **kw)

Power off the specified instance

power_on(*args, **kw)

Power on the specified instance

pre_block_migration(ctxt, instance, disk_info_json)

Preparation block migration.

Params ctxt:security context
Params instance:
 nova.db.sqlalchemy.models.Instance object instance object that is migrated.
Params disk_info_json:
 json strings specified in get_instance_disk_info
pre_live_migration(context, instance_ref, block_device_info, network_info)

Preparation live migration.

reboot(*args, **kw)

Reboot a virtual machine, given an instance reference.

refresh_instance_security_rules(instance)
refresh_provider_fw_rules()
refresh_security_group_members(security_group_id)
refresh_security_group_rules(security_group_id)
remove_from_aggregate(context, aggregate, host, **kwargs)

Remove a compute host from an aggregate.

rescue(*args, **kw)

Loads a VM using rescue images.

A rescue is normally performed when something goes wrong with the primary images and data needs to be corrected/recovered. Rescuing should not edit or over-ride the original image, only allow for data recovery.

resume(*args, **kw)

resume the specified instance

resume_state_on_host_boot(*args, **kw)

resume guest state when a host is booted

set_host_enabled(host, enabled)

Sets the specified host’s ability to accept new instances.

snapshot(*args, **kw)

Create snapshot from a running VM instance.

This command only works with qemu 0.14+

spawn(*args, **kw)
suspend(*args, **kw)

Suspend the specified instance

to_xml(instance, network_info, image_meta=None, rescue=None, block_device_info=None)
undo_aggregate_operation(context, op, aggregate_id, host, set_error=True)

only used for Resource Pools

unfilter_instance(instance_ref, network_info)

See comments of same method in firewall_driver.

unpause(*args, **kw)

Unpause paused VM instance

unplug_vifs(instance, network_info)

Unplug VIFs from networks.

unrescue(*args, **kw)

Reboot the VM which is being rescued back into primary images.

update_host_status()

Retrieve status info from libvirt.

Query libvirt to get the state of the compute node, such as memory and disk usage.

uri
volume_driver_method(method_name, connection_info, *args, **kwargs)
patch_tpool_proxy()

eventlet.tpool.Proxy doesn’t work with old-style class in __str__() or __repr__() calls. See bug #962840 for details. We perform a monkey patch to replace those two instance methods.

Previous topic

The nova.virt.libvirt.config Module

Next topic

The nova.virt.libvirt.firewall Module

This Page