Virtualization

Compute

Documentation for the compute manager and related files. For reading about a specific virtualization backend, read Drivers.

The nova.compute.manager Module

Handles all processes relating to instances (guest vms).

The ComputeManager class is a nova.manager.Manager that handles RPC calls relating to creating instances. It is responsible for building a disk image, launching it via the underlying virtualization driver, responding to calls to check its state, attaching persistent storage, and terminating it.

class ComputeManager(compute_driver=None, *args, **kwargs)

Bases: nova.manager.SchedulerDependentManager

Manages the running instances from creation to destruction.

RPC_API_VERSION = '2.47'
add_aggregate_host(context, *args, **kw)

Notify hypervisor of change (for hypervisor pools).

add_fixed_ip_to_instance(context, *args, **kw)

Calls network_api to add new fixed_ip to instance then injects the new network info and resets instance networking.

attach_interface(context, instance, network_id, port_id, requested_ip=None)

Use hotplug to add an network adapter to an instance.

attach_volume(context, *args, **kw)

Attach a volume to an instance.

backup_instance(context, *args, **kw)

Backup an instance on this host.

Parameters:
  • backup_type – daily | weekly
  • rotation – int representing how many backups to keep around
build_and_run_instance(context, *args, **kw)
change_instance_metadata(context, *args, **kw)

Update the metadata published to the instance.

check_can_live_migrate_destination(context, *args, **kwargs)

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:
  • context – security context
  • instance – dict of instance data
  • block_migration – if true, prepare for block migration
  • disk_over_commit – if true, allow disk over commit
Returns:

a dict containing migration info

check_can_live_migrate_source(context, *args, **kwargs)

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 – dict of instance data
  • dest_check_data – result of check_can_live_migrate_destination
Returns:

a dict containing migration info

check_instance_shared_storage(context, *args, **kw)

Check if the instance files are shared

Parameters:
  • context – security context
  • data – result of driver.check_instance_shared_storage_local

Returns True if instance disks located on shared storage and False otherwise.

confirm_resize(context, *args, **kwargs)
create_rpc_dispatcher(backdoor_port=None, additional_apis=None)
detach_interface(context, instance, port_id)

Detach an network adapter from an instance.

detach_volume(context, *args, **kw)

Detach a volume from an instance.

finish_resize(context, *args, **kwargs)

Completes the migration process.

Sets up the newly transferred disk and turns on the instance at its new host machine.

finish_revert_resize(context, *args, **kwargs)

Finishes the second half of reverting a resize.

Bring the original source instance state back (active/shutoff) and revert the resized attributes in the database.

get_backdoor_port(context)

Return backdoor port for eventlet_backdoor.

get_console_output(context, *args, **kw)

Send the console output for the given instance.

get_console_pool_info(context, console_type)
get_console_topic(context)

Retrieves the console host for a project on this host.

Currently this is just set in the flags for each compute host.

get_diagnostics(context, *args, **kw)

Retrieve diagnostics for an instance on this host.

get_host_uptime(context, *args, **kw)

Returns the result of calling “uptime” on the target host.

get_spice_console(*args, **kwargs)
get_vnc_console(*args, **kwargs)
handle_events(event)
handle_lifecycle_event(event)
host_maintenance_mode(context, *args, **kw)

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

host_power_action(context, *args, **kw)

Reboots, shuts down or powers up the host.

init_host()

Initialization for a standalone compute service.

init_virt_events()
inject_file(context, *args, **kw)

Write a file to the specified path in an instance on this host.

inject_network_info(context, *args, **kwargs)

Inject network info, but don’t return the info.

live_migration(context, *args, **kw)

Executing live migration.

Parameters:
  • context – security context
  • instance – instance dict
  • dest – destination host
  • block_migration – if true, prepare for block migration
  • migrate_data – implementation specific params
live_snapshot_instance(context, *args, **kw)

Live snapshot an instance on this host.

Parameters:
  • context – security context
  • image_id – glance.db.sqlalchemy.models.Image.Id
  • instance – an Instance dict
pause_instance(context, *args, **kwargs)

Pause an instance on this host.

post_live_migration_at_destination(context, *args, **kw)

Post operations for live migration .

Parameters:
  • context – security context
  • instance – Instance dict
  • block_migration – if true, prepare for block migration
power_off_instance(context, *args, **kw)

Power off an instance on this host.

power_on_instance(context, *args, **kw)

Power on an instance on this host.

pre_live_migration(context, *args, **kw)

Preparations for live migration at dest host.

Parameters:
  • context – security context
  • instance – dict of instance data
  • block_migration – if true, prepare for block migration

:param migrate_data : if not None, it is a dict which holds data required for live migration without shared storage.

pre_start_hook()

After the service is initialized, but before we fully bring the service up by listening on RPC queues, make sure to update our available resources (and indirectly our available nodes).

prep_resize(context, *args, **kwargs)

Initiates the process of moving a running instance to another host.

Possibly changes the RAM and disk size in the process.

reboot_instance(context, *args, **kwargs)

Reboot an instance on this host.

rebuild_instance(context, *args, **kw)

Destroy and re-make this instance.

A ‘rebuild’ effectively purges all existing data from the system and remakes the VM with given ‘metadata’ and ‘personalities’.

Parameters:
  • contextnova.RequestContext object
  • instance – Instance dict
  • orig_image_ref – Original image_ref before rebuild
  • image_ref – New image_ref for rebuild
  • injected_files – Files to inject
  • new_pass – password to set on rebuilt instance
  • orig_sys_metadata – instance system metadata from pre-rebuild
  • bdms – block-device-mappings to use for rebuild
  • recreate – True if instance should be recreated with same disk
  • on_shared_storage – True if instance files on shared storage
refresh_instance_security_rules(context, *args, **kw)

Tell the virtualization driver to refresh security rules for an instance.

Passes straight through to the virtualization driver.

Synchronise the call beacuse we may still be in the middle of creating the instance.

refresh_provider_fw_rules(context, *args, **kw)

This call passes straight through to the virtualization driver.

refresh_security_group_members(context, *args, **kw)

Tell the virtualization driver to refresh security group members.

Passes straight through to the virtualization driver.

refresh_security_group_rules(context, *args, **kw)

Tell the virtualization driver to refresh security group rules.

Passes straight through to the virtualization driver.

remove_aggregate_host(context, *args, **kw)

Removes a host from a physical hypervisor pool.

remove_fixed_ip_from_instance(context, *args, **kw)

Calls network_api to remove existing fixed_ip from instance by injecting the altered network info and resetting instance networking.

remove_volume_connection(context, *args, **kw)

Remove a volume connection using the volume api.

rescue_instance(context, *args, **kw)

Rescue an instance on this host. :param rescue_password: password to set on rescue instance

reserve_block_device_name(context, *args, **kw)
reset_network(context, *args, **kwargs)

Reset networking on the given instance.

resize_instance(context, *args, **kwargs)

Starts the migration of a running instance to another host.

restore_instance(context, *args, **kw)

Restore a soft-deleted instance on this host.

resume_instance(context, *args, **kwargs)

Resume the given suspended instance.

revert_resize(context, *args, **kwargs)

Destroys the new instance on the destination machine.

Reverts the model changes, and powers on the old instance on the source machine.

rollback_live_migration_at_destination(context, *args, **kw)

Cleaning up image directory that is created pre_live_migration.

Parameters:
  • context – security context
  • instance – an Instance dict sent over rpc
run_instance(context, *args, **kw)
set_admin_password(context, *args, **kw)

Set the root/admin password for an instance on this host.

This is generally only called by API password resets after an image has been built.

set_host_enabled(context, *args, **kw)

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

shelve_instance(context, *args, **kw)

Shelve an instance.

This should be used when you want to take a snapshot of the instance. It also adds system_metadata that can be used by a periodic task to offload the shelved instance after a period of time.

Parameters:
  • context – request context
  • instance – an Instance object
  • image_id – an image id to snapshot to.
shelve_offload_instance(context, *args, **kw)

Remove a shelved instance from the hypervisor.

This frees up those resources for use by other instances, but may lead to slower unshelve times for this instance. This method is used by volume backed instances since restoring them doesn’t involve the potentially large download of an image.

Parameters:
  • context – request context
  • instance – an Instance dict
snapshot_instance(context, *args, **kwargs)

Snapshot an instance on this host.

Parameters:
  • context – security context
  • instance – an Instance dict
  • image_id – glance.db.sqlalchemy.models.Image.Id

The following params are for RPC versions prior to 2.39 where this method also handled backups: :param image_type: snapshot | backup :param backup_type: daily | weekly :param rotation: int representing how many backups to keep around;

None if rotation shouldn’t be used (as in the case of snapshots)
soft_delete_instance(context, *args, **kwargs)

Soft delete an instance on this host.

start_instance(context, *args, **kwargs)

Starting an instance on this host.

stop_instance(context, *args, **kwargs)

Stopping an instance on this host.

suspend_instance(context, *args, **kwargs)

Suspend the given instance.

swap_volume(context, *args, **kw)

Swap volume for an instance.

terminate_instance(context, *args, **kwargs)

Terminate an instance on this host.

unpause_instance(context, *args, **kwargs)

Unpause a paused instance on this host.

unrescue_instance(context, *args, **kw)

Rescue an instance on this host.

unshelve_instance(context, *args, **kw)

Unshelve the instance.

Parameters:
  • context – request context
  • instance – an Instance dict
  • image – an image to build from. If None we assume a volume backed instance.
update_available_resource(context)

See driver.get_available_resource()

Periodic process that keeps that the compute host’s understanding of resource availability and usage in sync with the underlying hypervisor.

Parameters:context – security context
validate_console_port(*args, **kwargs)
volume_snapshot_create(*args, **kwargs)
volume_snapshot_delete(*args, **kwargs)
class ComputeV3Proxy(manager)

Bases: object

RPC_API_VERSION = '3.0'
supported_methods = ('add_aggregate_host', 'add_fixed_ip_to_instance', 'attach_interface', 'attach_volume', 'change_instance_metadata', 'check_can_live_migrate_destination', 'check_can_live_migrate_source', 'check_instance_shared_storage', 'confirm_resize', 'detach_interface', 'detach_volume', 'finish_resize', 'finish_revert_resize', 'get_console_output', 'get_console_pool_info', 'get_console_topic', 'get_diagnostics', 'get_vnc_console', 'get_spice_console', 'validate_console_port', 'host_maintenance_mode', 'host_power_action', 'inject_file', 'inject_network_info', 'live_migration', 'pause_instance', 'post_live_migration_at_destination', 'power_off_instance', 'power_on_instance', 'pre_live_migration', 'prep_resize', 'reboot_instance', 'rebuild_instance', 'refresh_provider_fw_rules', 'remove_aggregate_host', 'remove_fixed_ip_from_instance', 'remove_volume_connection', 'rescue_instance', 'reset_network', 'resize_instance', 'resume_instance', 'revert_resize', 'rollback_live_migration_at_destination', 'run_instance', 'set_admin_password', 'set_host_enabled', 'swap_volume', 'get_host_uptime', 'reserve_block_device_name', 'live_snapshot_instance', 'backup_instance', 'snapshot_instance', 'start_instance', 'stop_instance', 'suspend_instance', 'terminate_instance', 'unpause_instance', 'unrescue_instance', 'soft_delete_instance', 'restore_instance', 'shelve_instance', 'shelve_offload_instance', 'unshelve_instance', 'volume_snapshot_create', 'volume_snapshot_delete', 'refresh_security_group_rules', 'refresh_security_group_members', 'refresh_instance_security_rules')
class ComputeVirtAPI(compute)

Bases: nova.virt.virtapi.VirtAPI

agent_build_get_by_triple(context, hypervisor, os, architecture)
aggregate_get_by_host(context, host, key=None)
aggregate_metadata_add(context, aggregate, metadata, set_delete=False)
aggregate_metadata_delete(context, aggregate, key)
block_device_mapping_get_all_by_instance(context, instance, legacy=True)
block_device_mapping_update(context, bdm_id, values)
instance_type_get(context, instance_type_id)
instance_update(context, instance_uuid, updates)
provider_fw_rule_get_all(context)
security_group_get_by_instance(context, instance)
security_group_rule_get_by_security_group(context, security_group)
delete_image_on_error(function)

Used for snapshot related method to ensure the image created in compute.api is deleted when an error occurs.

object_compat(function)

Wraps a method that expects a new-world instance

This provides compatibility for callers passing old-style dict instances.

reverts_task_state(function)

Decorator to revert task_state on failure.

wrap_instance_event(function)

Wraps a method to log the event taken on the instance, and result.

This decorator wraps a method to log the start and result of an event, as part of an action taken on an instance.

wrap_instance_fault(function)

Wraps a method to catch exceptions related to instances.

This decorator wraps a method to catch any exceptions having to do with an instance that may get thrown. It then logs an instance fault in the db.

The nova.virt.connection Module

The nova.compute.disk Module

The nova.virt.images Module

Handling of VM disk images.

class QemuImgInfo(cmd_output=None)

Bases: object

BACKING_FILE_RE = <_sre.SRE_Pattern object at 0x54a3a40>
SIZE_RE = <_sre.SRE_Pattern object at 0x51ed5a0>
TOP_LEVEL_RE = <_sre.SRE_Pattern object at 0x5e09e40>
convert_image(source, dest, out_format, run_as_root=False)

Convert image to other format.

direct_fetch(context, image_href, backend_dest, _user_id, _project_id, max_size=0)

Allow an image backend to fetch directly from the glance backend.

Backend_dest:the image backend, which must have a direct_fetch method accepting a list of image locations. This method should raise exceptions.ImageUnacceptable if the image cannot be downloaded directly.
fetch(context, image_href, path, _user_id, _project_id, max_size=0)
fetch_to_raw(context, image_href, path, user_id, project_id, max_size=0)
qemu_img_info(path)

Return an object containing the parsed output from qemu-img info.

The nova.compute.flavors Module

Built-in instance properties.

add_flavor_access(flavorid, projectid, ctxt=None)

Add flavor access for project.

create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, swap=0, rxtx_factor=1.0, is_public=True)

Creates flavors.

delete_flavor_info(metadata, *prefixes)

Delete flavor instance_type information from instance’s system_metadata by prefix.

destroy(name)

Marks flavor as deleted.

extract_flavor(instance, prefix='')

Create an InstanceType-like object from instance’s system_metadata information.

get_all_flavors(ctxt=None, inactive=False, filters=None)

Get all non-deleted flavors as a dict.

Pass true as argument if you want deleted flavors returned also.

get_all_flavors_sorted_list(ctxt=None, inactive=False, filters=None, sort_key='flavorid', sort_dir='asc', limit=None, marker=None)

Get all non-deleted flavors as a sorted list.

Pass true as argument if you want deleted flavors returned also.

get_default_flavor()

Get the default flavor.

get_flavor(instance_type_id, ctxt=None, inactive=False)

Retrieves single flavor by id.

get_flavor_access_by_flavor_id(flavorid, ctxt=None)

Retrieve flavor access list by flavor id.

get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted='yes')

Retrieve flavor by flavorid.

Raises:FlavorNotFound
get_flavor_by_name(name, ctxt=None)

Retrieves single flavor by name.

remove_flavor_access(flavorid, projectid, ctxt=None)

Remove flavor access for project.

save_flavor_info(metadata, instance_type, prefix='')

Save properties from instance_type into instance’s system_metadata, in the format of:

[prefix]instance_type_[key]

This can be used to update system_metadata in place from a type, as well as stash information about another instance_type for later use (such as during resize).

The nova.compute.power_state Module

Power state is the state we get by calling virt driver on a particular domain. The hypervisor is always considered the authority on the status of a particular VM, and the power_state in the DB should be viewed as a snapshot of the VMs’s state in the (recent) past. It can be periodically updated, and should also be updated at the end of a task if the task is supposed to affect power_state.

name(code)
valid_states()

Drivers

The nova.virt.libvirt_conn Driver

The nova.virt.xenapi Driver

xenapi – Nova support for XenServer and XCP through XenAPI

The nova.virt.fake Driver

A fake (in-memory) hypervisor+api.

Allows nova testing w/o a hypervisor. This module also documents the semantics of real hypervisor connections.

class FakeDriver(virtapi, read_only=False)

Bases: nova.virt.driver.ComputeDriver

add_to_aggregate(context, aggregate, host, **kwargs)
attach_interface(instance, image_meta, vif)
attach_volume(context, connection_info, instance, mountpoint, encryption=None)

Attach the disk to the instance at mountpoint using info.

block_stats(instance_name, disk_id)
capabilities = {'supports_recreate': True, 'has_imagecache': True}

Fake hypervisor driver.

check_can_live_migrate_destination(ctxt, instance_ref, src_compute_info, dst_compute_info, block_migration=False, disk_over_commit=False)
check_can_live_migrate_destination_cleanup(ctxt, dest_check_data)
check_can_live_migrate_source(ctxt, instance_ref, dest_check_data)
confirm_migration(migration, instance, network_info)
destroy(instance, network_info, block_device_info=None, destroy_disks=True, context=None, migrate_data=None)
detach_interface(instance, vif)
detach_volume(connection_info, instance, mountpoint, encryption=None)

Detach the disk attached to the instance.

ensure_filtering_rules_for_instance(instance_ref, network_info)
finish_migration(context, migration, instance, disk_info, network_info, image_meta, resize_instance, block_device_info=None, power_on=True)
finish_revert_migration(instance, network_info, block_device_info=None, power_on=True)
get_all_bw_counters(instances)

Return bandwidth usage counters for each interface on each running VM.

get_all_volume_usage(context, compute_host_bdms)

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

get_available_nodes(refresh=False)
get_available_resource(nodename)

Updates compute manager resource info on ComputeNode table.

Since we don’t have a real hypervisor, pretend we have lots of disk and ram.

get_console_output(instance)
get_console_pool_info(console_type)
get_diagnostics(instance_name)
get_disk_available_least()
static get_host_ip_addr()
get_host_stats(refresh=False)

Return fake Host Status of ram, disk, network.

get_info(instance)
get_instance_disk_info(instance_name)
get_spice_console(instance)
get_vnc_console(instance)
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.

init_host(host)
inject_file(instance, b64_path, b64_contents)
instance_on_disk(instance)
interface_stats(instance_name, iface_id)
list_instance_uuids()
list_instances()
live_migration(context, instance_ref, dest, post_method, recover_method, block_migration=False, migrate_data=None)
live_snapshot(context, instance, name, update_task_state)
migrate_disk_and_power_off(context, instance, dest, instance_type, network_info, block_device_info=None)
pause(instance)
plug_vifs(instance, network_info)

Plug VIFs into networks.

poll_rebooting_instances(timeout, instances)
post_live_migration_at_destination(context, instance, network_info, block_migration=False, block_device_info=None)
power_off(instance)
power_on(context, instance, network_info, block_device_info)
pre_live_migration(context, instance_ref, block_device_info, network_info, disk, migrate_data=None)
reboot(context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None)
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)
rescue(context, instance, network_info, image_meta, rescue_password)
restore(instance)
resume(context, instance, network_info, block_device_info=None)
resume_state_on_host_boot(context, instance, network_info, block_device_info=None)
set_admin_password(instance, new_pass)
set_host_enabled(host, enabled)

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

snapshot(context, instance, name, update_task_state)
soft_delete(instance)
spawn(context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None)
suspend(instance)
swap_volume(old_connection_info, new_connection_info, instance, mountpoint)

Replace the disk attached to the instance.

test_remove_vm(instance_name)

Removes the named VM, as if it crashed. For testing.

unfilter_instance(instance_ref, network_info)
unpause(instance)
unplug_vifs(instance, network_info)

Unplug VIFs from networks.

unrescue(instance, network_info)
class FakeInstance(name, state)

Bases: object

class FakeVirtAPI

Bases: nova.virt.virtapi.VirtAPI

agent_build_get_by_triple(context, hypervisor, os, architecture)
aggregate_get_by_host(context, host, key=None)
aggregate_metadata_add(context, aggregate, metadata, set_delete=False)
aggregate_metadata_delete(context, aggregate, key)
block_device_mapping_get_all_by_instance(context, instance, legacy=True)
block_device_mapping_update(context, bdm_id, values)
instance_type_get(context, instance_type_id)
instance_update(context, instance_uuid, updates)
provider_fw_rule_get_all(context)
security_group_get_by_instance(context, instance)
security_group_rule_get_by_security_group(context, security_group)
restore_nodes()

Resets FakeDriver’s node list modified by set_nodes().

Usually called from tearDown().

set_nodes(nodes)

Sets FakeDriver’s node.list.

It has effect on the following methods:
get_available_nodes() get_available_resource get_host_stats()

To restore the change, call restore_nodes()

Tests

The compute_unittest Module

The virt_unittest Module