Previous topic

The nova.virt.images Module

Next topic

The nova.virt.libvirt.firewall Module

This Page

Psst... hey. You're reading the latest content, but it might be out of sync with code. You can read Nova 2011.2 docs or all OpenStack docs too.

The nova.virt.libvirt.connection 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_xml_template:
 Libvirt XML Template.
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 LibvirtConnection(read_only)

Bases: nova.virt.driver.ComputeDriver

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

Note that this function takes an instance name.

compare_cpu(cpu_info)

Checks the host cpu is compatible to a cpu given by xml.

“xml” must be a part of libvirt.openReadonly().getCapabilities(). return values follows by virCPUCompareResult. if 0 > return value, do live migration. ‘http://libvirt.org/html/libvirt-libvirt.html#virCPUCompareResult

Parameters:cpu_info – json string that shows cpu feature(see get_cpu_info())
Returns:None. if given cpu info is not compatible to this server, raise exception.
confirm_migration(migration, instance, network_info)

Confirms a resize, destroying the source VM

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

Setting up filtering rules and waiting for its completion.

To migrate an instance, filtering rules to hypervisors and firewalls are inevitable on destination host. ( Waiting only for filterling rules to hypervisor, since filtering rules to firewall rules can be set faster).

Concretely, the below method must be called. - setup_basic_filtering (for nova-basic, etc.) - prepare_instance_filter(for nova-instance-instance-xxx, etc.)

to_xml may have to be called since it defines PROJNET, PROJMASK. but libvirt migrates those value through migrateToURI(), so , no need to be called.

Don’t use thread for this method since migration should not be started when setting-up filtering rules operations are not completed.

Params instance_ref:
 nova.db.sqlalchemy.models.Instance object
finish_migration(*args, **kw)
finish_revert_migration(*args, **kw)
get_all_block_devices()

Return all block devices in use on this node.

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_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.

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_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_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 instance 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)
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.

libvirt_xml
list_instances()
list_instances_detail()
live_migration(ctxt, instance_ref, dest, post_method, recover_method, block_migration=False)

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.
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)
poll_unconfirmed_resizes(*args, **kw)

Poll for unconfirmed resizes.

Look for any unconfirmed resizes that are older than resize_confirm_window and automatically confirm them.

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.
pre_block_migration(ctxt, instance_ref, disk_info_json)

Preparation block migration.

Params ctxt:security context
Params instance_ref:
 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(block_device_info)

Preparation live migration.

Params block_device_info:
 It must be the result of _get_instance_volume_bdms() at compute manager.
reboot(*args, **kw)

Reboot a virtual machine, given an instance reference.

refresh_provider_fw_rules()
refresh_security_group_members(security_group_id)
refresh_security_group_rules(security_group_id)
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=False, block_device_info=None)
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.

Because reboot destroys and re-creates instances, unresue should simply call reboot.

update_available_resource(ctxt, host)

Updates compute manager resource info on ComputeNode table.

This method is called as an periodic tasks and is used only in live migration currently.

Parameters:
  • ctxt – security context
  • host – hostname that compute manager is currently running
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)
get_connection(read_only)
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.