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.

Related Flags

instances_path:Where instances are kept on disk
base_dir_name:Where cached images are stored under instances_path
compute_driver:Name of class that is used to handle virtualization, loaded by nova.openstack.common.importutils.import_object()
class ComputeManager(compute_driver=None, *args, **kwargs)

Bases: nova.manager.SchedulerDependentManager

Manages the running instances from creation to destruction.

ComputeManager.RPC_API_VERSION = '2.1'
ComputeManager.add_aggregate_host(*args, **kw)

Notify hypervisor of change (for hypervisor pools).

ComputeManager.add_fixed_ip_to_instance(*args, **kw)

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

ComputeManager.attach_volume(*args, **kw)

Attach a volume to an instance.

ComputeManager.change_instance_metadata(*args, **kw)

Update the metadata published to the instance.

ComputeManager.check_can_live_migrate_destination(*args, **kw)

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 mapping of values required in case of block migration and None otherwise.

ComputeManager.check_can_live_migrate_source(*args, **kw)

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

Destroys the source instance.

ComputeManager.detach_volume(*args, **kw)

Detach a volume from an instance.

ComputeManager.finish_resize(*args, **kw)

Completes the migration process.

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

ComputeManager.finish_revert_resize(*args, **kw)

Finishes the second half of reverting a resize.

Power back on the source instance and revert the resized attributes in the database.

ComputeManager.get_console_output(*args, **kw)

Send the console output for the given instance.

ComputeManager.get_console_pool_info(context, console_type)
ComputeManager.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.

ComputeManager.get_diagnostics(*args, **kw)

Retrieve diagnostics for an instance on this host.

ComputeManager.get_host_uptime(*args, **kw)

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

ComputeManager.get_vnc_console(*args, **kw)

Return connection information for a vnc console.

ComputeManager.host_maintenance_mode(*args, **kw)

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

ComputeManager.host_power_action(*args, **kw)

Reboots, shuts down or powers up the host.

ComputeManager.init_host()

Initialization for a standalone compute service.

ComputeManager.inject_file(*args, **kw)

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

ComputeManager.inject_network_info(context, *args, **kwargs)

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

ComputeManager.live_migration(context, dest, instance, block_migration=False, migrate_data=None)

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

Pause an instance on this host.

ComputeManager.post_live_migration_at_destination(context, instance, block_migration=False)

Post operations for live migration .

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

Power off an instance on this host.

ComputeManager.power_on_instance(*args, **kw)

Power on an instance on this host.

ComputeManager.pre_live_migration(context, instance, block_migration=False, disk=None)

Preparations for live migration at dest host.

Parameters:
  • context – security context
  • instance – dict of instance data
  • block_migration – if true, prepare for block migration
ComputeManager.prep_resize(*args, **kw)

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

Possibly changes the RAM and disk size in the process.

ComputeManager.reboot_instance(*args, **kw)

Reboot an instance on this host.

ComputeManager.rebuild_instance(*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
ComputeManager.refresh_instance_security_rules(*args, **kw)

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

Passes straight through to the virtualization driver.

ComputeManager.refresh_provider_fw_rules(*args, **kw)

This call passes straight through to the virtualization driver.

ComputeManager.refresh_security_group_members(*args, **kw)

Tell the virtualization driver to refresh security group members.

Passes straight through to the virtualization driver.

ComputeManager.refresh_security_group_rules(*args, **kw)

Tell the virtualization driver to refresh security group rules.

Passes straight through to the virtualization driver.

ComputeManager.remove_aggregate_host(*args, **kw)

Removes a host from a physical hypervisor pool.

ComputeManager.remove_fixed_ip_from_instance(*args, **kw)

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

ComputeManager.remove_volume_connection(*args, **kw)

Remove a volume connection using the volume api

ComputeManager.rescue_instance(*args, **kw)

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

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

Reset networking on the given instance.

ComputeManager.resize_instance(*args, **kw)

Starts the migration of a running instance to another host.

ComputeManager.resume_instance(*args, **kw)

Resume the given suspended instance.

ComputeManager.revert_resize(*args, **kw)

Destroys the new instance on the destination machine.

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

ComputeManager.rollback_live_migration_at_destination(context, instance)

Cleaning up image directory that is created pre_live_migration.

Parameters:
  • context – security context
  • instance – an Instance dict sent over rpc
ComputeManager.run_instance(*args, **kw)
ComputeManager.set_admin_password(*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.

ComputeManager.set_host_enabled(*args, **kw)

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

ComputeManager.snapshot_instance(*args, **kw)

Snapshot an instance on this host.

Parameters:
  • context – security context
  • instance – an Instance dict
  • image_id – glance.db.sqlalchemy.models.Image.Id
  • image_type – snapshot | backup
  • backup_type – daily | weekly
  • rotation – int representing how many backups to keep around; None if rotation shouldn’t be used (as in the case of snapshots)
ComputeManager.start_instance(*args, **kw)

Starting an instance on this host.

Alias for power_on_instance for compatibility

ComputeManager.stop_instance(*args, **kw)

Stopping an instance on this host.

Alias for power_off_instance for compatibility

ComputeManager.suspend_instance(*args, **kw)

Suspend the given instance.

ComputeManager.terminate_instance(*args, **kw)

Terminate an instance on this host.

ComputeManager.unpause_instance(*args, **kw)

Unpause a paused instance on this host.

ComputeManager.unrescue_instance(*args, **kw)

Rescue an instance on this host.

ComputeManager.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
publisher_id(host=None)
reverts_task_state(function)

Decorator to revert task_state on failure

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

Abstraction of the underlying virtualization API.

get_connection(read_only=False)

Returns an object representing the connection to a virtualization platform, or to an on-demand bare-metal provisioning platform.

This could be nova.virt.fake.FakeConnection in test mode, a connection to KVM, QEMU, or UML via libvirt_conn, or a connection to XenServer or Xen Cloud Platform via xenapi. Other platforms are also supported.

Any object returned here must conform to the interface documented by FakeConnection.

Related flags

Connection_type :
 

A string literal that falls through an if/elif structure to determine what virtualization mechanism to use. Values may be

  • fake
  • libvirt
  • xenapi
  • vmwareapi
  • baremetal

The nova.compute.disk Module

The nova.virt.images Module

Handling of VM disk images.

fetch(context, image_href, path, _user_id, _project_id)
fetch_to_raw(context, image_href, path, user_id, project_id)
qemu_img_info(path)

Return a dict containing the parsed output from qemu-img info.

The nova.compute.instance_types Module

Built-in instance properties.

add_instance_type_access(flavorid, projectid, ctxt=None)

Add instance type access for project

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

Creates instance types.

destroy(name)

Marks instance types as deleted.

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

Get all non-deleted instance_types.

Pass true as argument if you want deleted instance types returned also.

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

Get all non-deleted instance_types.

Pass true as argument if you want deleted instance types returned also.

get_default_instance_type()

Get the default instance type.

get_instance_type(instance_type_id, ctxt=None)

Retrieves single instance type by id.

get_instance_type_access_by_flavor_id(flavorid, ctxt=None)

Retrieve instance type access list by flavor id

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

Retrieve instance type by flavorid.

Raises :FlavorNotFound
get_instance_type_by_name(name, ctxt=None)

Retrieves single instance type by name.

remove_instance_type_access(flavorid, projectid, ctxt=None)

Remove instance type access for project

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

Bases: nova.virt.driver.ComputeDriver

Fake hypervisor driver

FakeDriver.attach_volume(connection_info, instance_name, mountpoint)

Attach the disk to the instance at mountpoint using info

FakeDriver.block_stats(instance_name, disk_id)
FakeDriver.confirm_migration(migration, instance, network_info)
FakeDriver.destroy(instance, network_info, block_device_info=None)
FakeDriver.detach_volume(connection_info, instance_name, mountpoint)

Detach the disk attached to the instance

FakeDriver.ensure_filtering_rules_for_instance(instance_ref, network_info)

This method is supported only by libvirt.

FakeDriver.finish_migration(context, migration, instance, disk_info, network_info, image_meta, resize_instance)
FakeDriver.finish_revert_migration(instance, network_info)
FakeDriver.get_all_bw_usage(instances, start_time, stop_time=None)

Return bandwidth usage info for each interface on each running VM

FakeDriver.get_available_resource()

Updates compute manager resource info on ComputeNode table.

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

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

Return fake Host Status of ram, disk, network.

FakeDriver.get_info(instance)
FakeDriver.get_instance_disk_info(instance_name)
FakeDriver.get_vnc_console(instance)
FakeDriver.get_volume_connector(instance)
FakeDriver.host_maintenance_mode(host, mode)

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

FakeDriver.host_power_action(host, action)

Reboots, shuts down or powers up the host.

FakeDriver.init_host(host)
FakeDriver.inject_file(instance, b64_path, b64_contents)
FakeDriver.interface_stats(instance_name, iface_id)
FakeDriver.list_instances()
FakeDriver.live_migration(context, instance_ref, dest, post_method, recover_method, block_migration=False, migrate_data=None)
FakeDriver.migrate_disk_and_power_off(context, instance, dest, instance_type, network_info)
FakeDriver.pause(instance)
FakeDriver.plug_vifs(instance, network_info)

Plug VIFs into networks.

FakeDriver.poll_rebooting_instances(timeout)
FakeDriver.poll_rescued_instances(timeout)
FakeDriver.power_off(instance)
FakeDriver.power_on(instance)
FakeDriver.pre_live_migration(context, instance_ref, block_device_info, network_info)
FakeDriver.reboot(instance, network_info, reboot_type, block_device_info=None)
FakeDriver.refresh_instance_security_rules(instance)
FakeDriver.refresh_provider_fw_rules()
FakeDriver.refresh_security_group_members(security_group_id)
FakeDriver.refresh_security_group_rules(security_group_id)
FakeDriver.rescue(context, instance, network_info, image_meta, rescue_password)
FakeDriver.resume(instance)
FakeDriver.resume_state_on_host_boot(context, instance, network_info, block_device_info=None)
FakeDriver.set_admin_password(instance, new_pass)
FakeDriver.set_host_enabled(host, enabled)

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

FakeDriver.snapshot(context, instance, name)
FakeDriver.spawn(context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None)
FakeDriver.suspend(instance)
FakeDriver.test_remove_vm(instance_name)

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

FakeDriver.unfilter_instance(instance_ref, network_info)

This method is supported only by libvirt.

FakeDriver.unpause(instance)
FakeDriver.unplug_vifs(instance, network_info)

Unplug VIFs from networks.

FakeDriver.unrescue(instance, network_info)
FakeDriver.update_host_status()

Return fake Host Status of ram, disk, network.

class FakeInstance(name, state)

Bases: object

Tests

The compute_unittest Module

The virt_unittest Module