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(driver)

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(virtapi, read_only=False)

Bases: nova.virt.driver.ComputeDriver

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

Add a compute host to an aggregate.

attach_interface(context, *args, **kw)
attach_volume(connection_info, instance, mountpoint)
block_stats(instance_name, disk)

Note that this function takes an instance name.

capabilities = {'supports_recreate': True, 'has_imagecache': True}
check_can_live_migrate_destination(ctxt, instance_ref, src_compute_info, dst_compute_info, 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
  • 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
check_can_live_migrate_source(ctxt, instance, 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 – 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, destroy_disks=True)
detach_interface(context, *args, **kw)
detach_volume(connection_info, instance, mountpoint)
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(context, migration, instance, disk_info, network_info, image_meta, resize_instance, block_device_info=None)
finish_revert_migration(instance, network_info, block_device_info=None)
get_all_block_devices()

Return all block devices in use on this node.

get_all_volume_usage(context, compute_host_bdms)

Return usage info for volumes attached to vms on a given host

get_available_resource(nodename)

Retrieve resource info.

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

Parameters:nodename – ignored in this driver
Returns:dictionary containing resource info
get_console_output(instance)
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_over_committed_size_total()

Return total over committed disk size for 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, disk_info, 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_config_sysinfo(instance)
get_guest_cpu_config()
get_guest_disk_config(instance, name, disk_mapping, inst_type, image_type=None)
get_guest_storage_config(instance, image_meta, disk_info, rescue, block_device_info, inst_type)
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_host_uuid()

Returns a UUID representing the host.

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, xml=None, block_device_info=None)

Preparation block migration.

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 a domain xml.

Returns a list of all network interfaces for this instance.

static get_local_gb_info()

Get local storage info of the compute node in GB.

Returns:A dict containing: :total: How big the overall usable filesystem is (in gigabytes) :free: How much space is free (in gigabytes) :used: How much space is used (in gigabytes)
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.

get_spice_console(context, *args, **kw)
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(instance)
get_volume_connector(instance)
has_min_version(lv_ver=None, hv_ver=None, hv_type=None)
host_state
init_host(host)
inject_network_info(instance, nw_info)
instance_exists(instance_name)

Efficient override of base instance_exists method.

instance_on_disk(instance)
interface_stats(instance_name, interface)

Note that this function takes an instance name.

legacy_nwinfo()
list_instance_ids()
list_instance_uuids()
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, all_instances)

Manage the local cache of images.

migrate_disk_and_power_off(context, instance, dest, instance_type, network_info, block_device_info=None)
pause(instance)

Pause VM instance.

plug_vifs(instance, network_info)

Plug VIFs into networks.

poll_rebooting_instances(timeout, instances)
post_live_migration_at_destination(ctxt, instance_ref, network_info, block_migration, block_device_info=None)

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 information
  • block_migration – if true, post operation of block_migraiton.
power_off(instance)

Power off the specified instance.

power_on(context, instance, network_info, block_device_info=None)

Power on the specified instance.

pre_block_migration(ctxt, instance, disk_info_json)

Preparation for block migration.

pre_live_migration(context, instance, block_device_info, network_info, migrate_data=None)

Preparation live migration.

reboot(context, instance, network_info, reboot_type='SOFT', block_device_info=None, bad_volumes_callback=None)

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(context, instance, network_info, image_meta, rescue_password)

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(instance, network_info, block_device_info=None)

resume the specified instance.

resume_state_on_host_boot(context, instance, network_info, block_device_info=None)

resume guest state when a host is booted.

set_cache_mode(conf)

Set cache mode on LibvirtConfigGuestDisk object.

snapshot(context, instance, image_href, update_task_state)

Create snapshot from a running VM instance.

This command only works with qemu 0.14+

spawn(context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None)
suspend(instance)

Suspend the specified instance.

to_xml(instance, network_info, disk_info, image_meta=None, rescue=None, block_device_info=None, write_to_disk=False)
undo_aggregate_operation(context, op, aggregate, host, set_error=True)

only used for Resource Pools.

unfilter_instance(instance_ref, network_info)

See comments of same method in firewall_driver.

unpause(instance)

Unpause paused VM instance.

unplug_vifs(instance, network_info)

Unplug VIFs from networks.

unrescue(instance, network_info)

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

static 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.designer Module

Next topic

The nova.virt.libvirt.firewall Module

This Page