The nova.virt.driver
Module¶
Driver base-classes:
(Beginning of) the contract that compute drivers must follow, and shared types that support that contract
-
class
ComputeDriver
(virtapi)¶ Bases:
object
Base class for compute drivers.
The interface to this class talks in terms of ‘instances’ (Amazon EC2 and internal Nova terminology), by which we mean ‘running virtual machine’ (XenAPI terminology) or domain (Xen or libvirt terminology).
An instance has an ID, which is the identifier chosen by Nova to represent the instance further up the stack. This is unfortunately also called a ‘name’ elsewhere. As far as this layer is concerned, ‘instance ID’ and ‘instance name’ are synonyms.
Note that the instance ID or name is not human-readable or customer-controlled – it’s an internal ID chosen by Nova. At the nova.virt layer, instances do not have human-readable names at all – such things are only known higher up the stack.
Most virtualization platforms will also have their own identity schemes, to uniquely identify a VM or domain. These IDs must stay internal to the platform-specific layer, and never escape the connection interface. The platform-specific layer is responsible for keeping track of which instance ID maps to which platform-specific ID, and vice versa.
Some methods here take an instance of nova.compute.service.Instance. This is the data structure used by nova.compute to store details regarding an instance, and pass them into this layer. This layer is responsible for translating that generic data structure into terms that are specific to the virtualization platform.
-
add_to_aggregate
(context, aggregate, host, **kwargs)¶ Add a compute host to an aggregate.
The counter action to this is
remove_from_aggregate()
Parameters: - context (nova.context.RequestContext) – The security context.
- aggregate (nova.objects.aggregate.Aggregate) – The aggregate which should add the given host
- host (str) – The name of the host to add to the given aggregate.
- kwargs (dict) – A free-form thingy...
Returns: None
-
attach_interface
(instance, image_meta, vif)¶ Use hotplug to add a network interface to a running instance.
The counter action to this is
detach_interface()
.Parameters: - instance (nova.objects.instance.Instance) – The instance which will get an additional network interface.
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
- vif (nova.network.model.NetworkInfo) – The object which has the information about the interface to attach.
Raises: nova.exception.NovaException – If the attach fails.
Returns: None
-
attach_volume
(context, connection_info, instance, mountpoint, disk_bus=None, device_type=None, encryption=None)¶ Attach the disk to the instance at mountpoint using info.
-
block_stats
(instance, disk_id)¶ Return performance counters associated with the given disk_id on the given instance. These are returned as [rd_req, rd_bytes, wr_req, wr_bytes, errs], where rd indicates read, wr indicates write, req is the total number of I/O requests made, bytes is the total number of bytes transferred, and errs is the number of requests held up due to a full pipeline.
All counters are long integers.
This method is optional. On some platforms (e.g. XenAPI) performance statistics can be retrieved directly in aggregate form, without Nova having to do the aggregation. On those platforms, this method is unused.
Note that this function takes an instance ID.
-
capabilities
= {'supports_recreate': False, 'has_imagecache': False, 'supports_migrate_to_same_host': False}¶
-
change_instance_metadata
(context, instance, diff)¶ Applies a diff to the instance metadata.
This is an optional driver method which is used to publish changes to the instance’s metadata to the hypervisor. If the hypervisor has no means of publishing the instance metadata to the instance, then this method should not be implemented.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
-
check_can_live_migrate_destination
(context, instance, 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: - context – security context
- instance – nova.db.sqlalchemy.models.Instance
- src_compute_info – Info about the sending machine
- dst_compute_info – Info about the receiving machine
- block_migration – if true, prepare for block migration
- disk_over_commit – if true, allow disk over commit
Returns: a LiveMigrateData object (hypervisor-dependent)
-
check_can_live_migrate_destination_cleanup
(context, dest_check_data)¶ Do required cleanup on dest host after check_can_live_migrate calls
Parameters: - context – security context
- dest_check_data – result of check_can_live_migrate_destination
-
check_can_live_migrate_source
(context, instance, dest_check_data, block_device_info=None)¶ 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
- block_device_info – result of _get_instance_block_device_info
Returns: a LiveMigrateData object
Do cleanup on host after check_instance_shared_storage calls
Parameters: - context – security context
- data – result of check_instance_shared_storage_local
Check if instance files located on shared storage.
This runs check on the destination host, and then calls back to the source host to check the results.
Parameters: - context – security context
- instance – nova.objects.instance.Instance object
Check if instance files located on shared storage.
Parameters: - context – security context
- data – result of check_instance_shared_storage_local
-
cleanup
(context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None, destroy_vifs=True)¶ Cleanup the instance resources .
Instance should have been destroyed from the Hypervisor before calling this method.
Parameters: - context – security context
- instance – Instance object as returned by DB layer.
- network_info –
get_instance_nw_info()
- block_device_info – Information about block devices that should be detached from the instance.
- destroy_disks – Indicates if disks should be destroyed
- migrate_data – implementation specific params
-
cleanup_host
(host)¶ Clean up anything that is necessary for the driver gracefully stop, including ending remote sessions. This is optional.
-
confirm_migration
(migration, instance, network_info)¶ Confirms a resize/migration, destroying the source VM.
Parameters: instance – nova.objects.instance.Instance
-
deallocate_networks_on_reschedule
(instance)¶ Does the driver want networks deallocated on reschedule?
-
default_device_names_for_instance
(instance, root_device_name, *block_device_lists)¶ Default the missing device names in the block device mapping.
-
default_root_device_name
(instance, image_meta, root_bdm)¶ Provide a default root device name for the driver.
Parameters: - instance (nova.objects.instance.Instance) – The instance to get the root device for.
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
- root_bdm (nova.objects.BlockDeviceMapping) – The description of the root device.
-
delete_instance_files
(instance)¶ Delete any lingering instance files for an instance.
Parameters: instance – nova.objects.instance.Instance Returns: True if the instance was deleted from disk, False otherwise.
-
destroy
(context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None)¶ Destroy the specified instance from the Hypervisor.
If the instance is not found (for example if networking failed), this function should still succeed. It’s probably a good idea to log a warning in that case.
Parameters: - context – security context
- instance – Instance object as returned by DB layer.
- network_info –
get_instance_nw_info()
- block_device_info – Information about block devices that should be detached from the instance.
- destroy_disks – Indicates if disks should be destroyed
- migrate_data – implementation specific params
-
detach_interface
(instance, vif)¶ Use hotunplug to remove a network interface from a running instance.
The counter action to this is
attach_interface()
.Parameters: - instance (nova.objects.instance.Instance) – The instance which gets a network interface removed.
- vif (nova.network.model.NetworkInfo) – The object which has the information about the interface to detach.
Raises: nova.exception.NovaException – If the detach fails.
Returns: None
-
detach_volume
(connection_info, instance, mountpoint, encryption=None)¶ Detach the disk attached to the instance.
-
dhcp_options_for_instance
(instance)¶ Get DHCP options for this instance.
Some hypervisors (such as bare metal) require that instances boot from the network, and manage their own TFTP service. This requires passing the appropriate options out to the DHCP service. Most hypervisors can use the default implementation which returns None.
This is called during spawn_instance by the compute manager.
Note that the format of the return value is specific to the Neutron client API.
Returns: None, or a set of DHCP options, eg: [{‘opt_name’: ‘bootfile-name’,‘opt_value’: ‘/tftpboot/path/to/config’},{‘opt_name’: ‘server-ip-address’,‘opt_value’: ‘1.2.3.4’},{‘opt_name’: ‘tftp-server’,‘opt_value’: ‘1.2.3.4’}]
-
emit_event
(event)¶ Dispatches an event to the compute manager.
Invokes the event callback registered by the compute manager to dispatch the event. This must only be invoked from a green thread.
-
ensure_filtering_rules_for_instance
(instance, network_info)¶ 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 filtering 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.
Parameters: instance – nova.objects.instance.Instance object
-
estimate_instance_overhead
(instance_info)¶ Estimate the virtualization overhead required to build an instance of the given flavor.
Defaults to zero, drivers should override if per-instance overhead calculations are desired.
Parameters: instance_info – Instance/flavor to calculate overhead for. Returns: Dict of estimated overhead values.
-
filter_defer_apply_off
()¶ Turn off deferral of IPTables rules and apply the rules now.
-
filter_defer_apply_on
()¶ Defer application of IPTables rules.
-
finish_migration
(context, migration, instance, disk_info, network_info, image_meta, resize_instance, block_device_info=None, power_on=True)¶ Completes a resize/migration.
Parameters: - context – the context for the migration/resize
- migration – the migrate/resize information
- instance – nova.objects.instance.Instance being migrated/resized
- disk_info – the newly transferred disk information
- network_info –
get_instance_nw_info()
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
- resize_instance – True if the instance is being resized, False otherwise
- block_device_info – instance volume block device info
- power_on – True if the instance should be powered on, False otherwise
-
finish_revert_migration
(context, instance, network_info, block_device_info=None, power_on=True)¶ Finish reverting a resize/migration.
Parameters: - context – the context for the finish_revert_migration
- instance – nova.objects.instance.Instance being migrated/resized
- network_info –
get_instance_nw_info()
- block_device_info – instance volume block device info
- power_on – True if the instance should be powered on, False otherwise
-
get_all_bw_counters
(instances)¶ - Return bandwidth usage counters for each interface on each
- running VM.
Parameters: instances – nova.objects.instance.InstanceList
-
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)¶ Returns nodenames of all nodes managed by the compute service.
This method is for multi compute-nodes support. If a driver supports multi compute-nodes, this method returns a list of nodenames managed by the service. Otherwise, this method should return [hypervisor_hostname].
-
get_available_resource
(nodename)¶ Retrieve resource information.
This method is called when nova-compute launches, and as part of a periodic task that records the results in the DB.
Parameters: nodename – node which the caller want to get resources from a driver that manages only one node can safely ignore this Returns: Dictionary describing resources
-
get_console_output
(context, instance)¶ Get console output for an instance
Parameters: - context – security context
- instance – nova.objects.instance.Instance
-
get_console_pool_info
(console_type)¶
-
get_device_name_for_instance
(instance, bdms, block_device_obj)¶ Get the next device name based on the block device mapping.
Parameters: - instance – nova.objects.instance.Instance that volume is requesting a device name
- bdms – a nova.objects.BlockDeviceMappingList for the instance
- block_device_obj – A nova.objects.BlockDeviceMapping instance with all info about the requested block device. device_name does not need to be set, and should be decided by the driver implementation if not set.
Returns: The chosen device name.
-
get_diagnostics
(instance)¶ Return diagnostics data about the given instance.
Parameters: instance (nova.objects.instance.Instance) – The instance to which the diagnostic data should be returned. Returns: Has a big overlap to the return value of the newer interface get_instance_diagnostics()
Return type: dict
-
get_host_cpu_stats
()¶ Get the currently known host CPU stats.
Returns: a dict containing the CPU stat info, eg: {‘kernel’: kern,‘idle’: idle,‘user’: user,‘iowait’: wait,‘frequency’: freq},where kern and user indicate the cumulative CPU time (nanoseconds) spent by kernel and user processes respectively, idle indicates the cumulative idle CPU time (nanoseconds), wait indicates the cumulative I/O wait CPU time (nanoseconds), since the host is booting up; freq indicates the current CPU frequency (MHz). All values are long integers.
-
get_host_ip_addr
()¶ Retrieves the IP address of the dom0
-
get_host_uptime
()¶ Returns the result of calling the Linux command uptime on this host.
Returns: A text which contains the uptime of this host since the last boot. Return type: str
-
get_info
(instance)¶ Get the current status of an instance, by name (not ID!)
Parameters: instance – nova.objects.instance.Instance object Returns a InstanceInfo object
-
get_instance_diagnostics
(instance)¶ Return diagnostics data about the given instance.
Parameters: instance (nova.objects.instance.Instance) – The instance to which the diagnostic data should be returned. Returns: Has a big overlap to the return value of the older interface get_diagnostics()
Return type: nova.virt.diagnostics.Diagnostics
-
get_instance_disk_info
(instance, block_device_info=None)¶ Retrieve information about actual disk sizes of an instance.
Parameters: - instance – nova.objects.Instance
- block_device_info – Optional; Can be used to filter out devices which are actually volumes.
Returns: json strings with below format:
"[{'path':'disk', 'type':'raw', 'virt_disk_size':'10737418240', 'backing_file':'backing_file', 'disk_size':'83886080' 'over_committed_disk_size':'10737418240'}, ...]"
-
get_mks_console
(context, instance)¶ Get connection info for a MKS console.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
:returns an instance of console.type.ConsoleMKS
-
get_num_instances
()¶ Return the total number of virtual machines.
Return the number of virtual machines that the hypervisor knows about.
Note
This implementation works for all drivers, but it is not particularly efficient. Maintainers of the virt drivers are encouraged to override this method with something more efficient.
-
get_per_instance_usage
()¶ Get information about instance resource usage.
Returns: dict of nova uuid => dict of usage info
-
get_rdp_console
(context, instance)¶ Get connection info for a rdp console.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
:returns an instance of console.type.ConsoleRDP
-
get_serial_console
(context, instance)¶ Get connection info for a serial console.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
:returns an instance of console.type.ConsoleSerial
-
get_spice_console
(context, instance)¶ Get connection info for a spice console.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
:returns an instance of console.type.ConsoleSpice
-
get_vnc_console
(context, instance)¶ Get connection info for a vnc console.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
:returns an instance of console.type.ConsoleVNC
-
get_volume_connector
(instance)¶ Get connector information for the instance for attaching to volumes.
Connector information is a dictionary representing the ip of the machine that will be making the connection, the name of the iscsi initiator and the hostname of the machine as follows:
{ 'ip': ip, 'initiator': initiator, 'host': hostname }
-
host_maintenance_mode
(host, mode)¶ Start/Stop host maintenance window.
On start, it triggers the migration of all instances to other hosts. Consider the combination with
set_host_enabled()
.Parameters: - host (str) – The name of the host whose maintenance mode should be changed.
- mode (bool) – If True, go into maintenance mode. If False, leave the maintenance mode.
Returns: “on_maintenance” if switched to maintenance mode or “off_maintenance” if maintenance mode got left.
Return type: str
-
host_power_action
(action)¶ Reboots, shuts down or powers up the host.
Parameters: action (str) – The action the host should perform. The valid actions are: “”startup”, “shutdown” and “reboot”. Returns: The result of the power action Return type: : str
-
init_host
(host)¶ Initialize anything that is necessary for the driver to function, including catching up with currently running VM’s on the given host.
-
inject_file
(instance, b64_path, b64_contents)¶ Writes a file on the specified instance.
The first parameter is an instance of nova.compute.service.Instance, and so the instance is being specified as instance.name. The second parameter is the base64-encoded path to which the file is to be written on the instance; the third is the contents of the file, also base64-encoded.
NOTE(russellb) This method is deprecated and will be removed once it can be removed from nova.compute.manager.
-
inject_network_info
(instance, nw_info)¶ inject network info for specified instance.
-
instance_exists
(instance)¶ Checks existence of an instance on the host.
Parameters: instance – The instance to lookup Returns True if an instance with the supplied ID exists on the host, False otherwise.
Note
This implementation works for all drivers, but it is not particularly efficient. Maintainers of the virt drivers are encouraged to override this method with something more efficient.
-
instance_on_disk
(instance)¶ Checks access of instance files on the host.
Parameters: instance – nova.objects.instance.Instance to lookup Returns True if files of an instance with the supplied ID accessible on the host, False otherwise.
Note
Used in rebuild for HA implementation and required for validation of access to instance shared disk files
-
is_supported_fs_format
(fs_type)¶ Check whether the file format is supported by this driver
Parameters: fs_type – the file system type to be checked, the validate values are defined at disk API module.
-
list_instance_uuids
()¶ Return the UUIDS of all the instances known to the virtualization layer, as a list.
-
list_instances
()¶ Return the names of all the instances known to the virtualization layer, as a list.
-
live_migration
(context, instance, dest, post_method, recover_method, block_migration=False, migrate_data=None)¶ Live migration of an instance to another host.
Parameters: - context – security context
- instance – nova.db.sqlalchemy.models.Instance object instance object that is migrated.
- dest – destination host
- post_method – post operation method. expected nova.compute.manager._post_live_migration.
- recover_method – recovery method when any exception occurs. expected nova.compute.manager._rollback_live_migration.
- block_migration – if true, migrate VM disk.
- migrate_data – a LiveMigrateData object
-
live_migration_abort
(instance)¶ Abort an in-progress live migration.
Parameters: instance – instance that is live migrating
-
live_migration_force_complete
(instance)¶ Force live migration to complete
Parameters: instance – Instance being live migrated
-
macs_for_instance
(instance)¶ What MAC addresses must this instance have?
Some hypervisors (such as bare metal) cannot do freeform virtualisation of MAC addresses. This method allows drivers to return a set of MAC addresses that the instance is to have. allocate_for_instance will take this into consideration when provisioning networking for the instance.
Mapping of MAC addresses to actual networks (or permitting them to be freeform) is up to the network implementation layer. For instance, with openflow switches, fixed MAC addresses can still be virtualised onto any L2 domain, with arbitrary VLANs etc, but regular switches require pre-configured MAC->network mappings that will match the actual configuration.
Most hypervisors can use the default implementation which returns None. Hypervisors with MAC limits should return a set of MAC addresses, which will be supplied to the allocate_for_instance call by the compute manager, and it is up to that call to ensure that all assigned network details are compatible with the set of MAC addresses.
This is called during spawn_instance by the compute manager.
Returns: None, or a set of MAC ids (e.g. set([‘12:34:56:78:90:ab’])). None means ‘no constraints’, a set means ‘these and only these MAC addresses’.
-
manage_image_cache
(context, all_instances)¶ Manage the driver’s local image cache.
Some drivers chose to cache images for instances on disk. This method is an opportunity to do management of that cache which isn’t directly related to other calls into the driver. The prime example is to clean the cache and remove images which are no longer of interest.
Parameters: all_instances – nova.objects.instance.InstanceList
-
migrate_disk_and_power_off
(context, instance, dest, flavor, network_info, block_device_info=None, timeout=0, retry_interval=0)¶ Transfers the disk of a running instance in multiple phases, turning off the instance before the end.
Parameters: - instance (nova.objects.instance.Instance) – The instance whose disk should be migrated.
- dest (str) – The IP address of the destination host.
- flavor (nova.objects.flavor.Flavor) – The flavor of the instance whose disk get migrated.
- network_info (nova.network.model.NetworkInfo) – The network information of the given instance.
- block_device_info (dict) – Information about the block devices.
- timeout (int) – The time in seconds to wait for the guest OS to shutdown.
- retry_interval (int) – How often to signal guest while waiting for it to shutdown.
Returns: A list of disk information dicts in JSON format.
Return type: str
-
need_legacy_block_device_info
¶ Tell the caller if the driver requires legacy block device info.
Tell the caller whether we expect the legacy format of block device info to be passed in to methods that expect it.
-
network_binding_host_id
(context, instance)¶ Get host ID to associate with network ports.
Parameters: - context – request context
- instance – nova.objects.instance.Instance that the network ports will be associated with
Returns: a string representing the host ID
-
node_is_available
(nodename)¶ Return whether this compute service manages a particular node.
-
pause
(instance)¶ Pause the given instance.
A paused instance doesn’t use CPU cycles of the host anymore. The state of the VM could be stored in the memory or storage space of the host, depending on the underlying hypervisor technology. A “stronger” version of pause is :func:’suspend’. The counter action for pause is
unpause()
.Parameters: instance (nova.objects.instance.Instance) – The instance which should be paused. Returns: None
-
plug_vifs
(instance, network_info)¶ Plug virtual interfaces (VIFs) into the given instance at instance boot time.
The counter action is
unplug_vifs()
.Parameters: - instance (nova.objects.instance.Instance) – The instance which gets VIFs plugged.
- network_info (nova.network.model.NetworkInfo) – The object which contains information about the VIFs to plug.
Returns: None
-
poll_rebooting_instances
(timeout, instances)¶ Perform a reboot on all given ‘instances’.
Reboots the given instances which are longer in the rebooting state than timeout seconds.
Parameters: - timeout (int) – The timeout (in seconds) for considering rebooting instances to be stuck.
- instances (list) – A list of nova.objects.instance.Instance objects that have been in rebooting state longer than the configured timeout.
Returns: None
-
post_interrupted_snapshot_cleanup
(context, instance)¶ Cleans up any resources left after an interrupted snapshot.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
-
post_live_migration
(context, instance, block_device_info, migrate_data=None)¶ Post operation of live migration at source host.
Parameters: - context – security context
- migrate_data – a LiveMigrateData object
Instance: instance object that was migrated
Block_device_info: instance block device information
-
post_live_migration_at_destination
(context, instance, network_info, block_migration=False, block_device_info=None)¶ Post operation of live migration at destination host.
Parameters: - context – security context
- instance – instance object that is migrated
- network_info – instance network information
- block_migration – if true, post operation of block_migration.
-
post_live_migration_at_source
(context, instance, network_info)¶ Unplug VIFs from networks at source.
Parameters: - context – security context
- instance – instance object reference
- network_info – instance network information
-
power_off
(instance, timeout=0, retry_interval=0)¶ Power off the specified instance.
Parameters: - instance – nova.objects.instance.Instance
- timeout – time to wait for GuestOS to shutdown
- retry_interval – How often to signal guest while waiting for it to shutdown
-
power_on
(context, instance, network_info, block_device_info=None)¶ Power on the specified instance.
Parameters: instance – nova.objects.instance.Instance
-
pre_live_migration
(context, instance, block_device_info, network_info, disk_info, migrate_data=None)¶ Prepare an instance for live migration
Parameters: - context – security context
- instance – nova.objects.instance.Instance object
- block_device_info – instance block device information
- network_info – instance network information
- disk_info – instance disk information
- migrate_data – a LiveMigrateData object
-
quiesce
(context, instance, image_meta)¶ Quiesce the specified instance to prepare for snapshots.
If the specified instance doesn’t support quiescing, InstanceQuiesceNotSupported is raised. When it fails to quiesce by other errors (e.g. agent timeout), NovaException is raised.
Parameters: - context – request context
- instance – nova.objects.instance.Instance to be quiesced
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
-
reboot
(context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None)¶ Reboot the specified instance.
After this is called successfully, the instance’s state goes back to power_state.RUNNING. The virtualization platform should ensure that the reboot action has completed successfully even in cases in which the underlying domain/vm is paused or halted/stopped.
Parameters: - instance – nova.objects.instance.Instance
- network_info –
get_instance_nw_info()
- reboot_type – Either a HARD or SOFT reboot
- block_device_info – Info pertaining to attached volumes
- bad_volumes_callback – Function to handle any bad volumes encountered
-
rebuild
(context, instance, image_meta, injected_files, admin_password, bdms, detach_block_devices, attach_block_devices, network_info=None, recreate=False, block_device_info=None, preserve_ephemeral=False)¶ 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’.
This base class method shuts down the VM, detaches all block devices, then spins up the new VM afterwards. It may be overridden by hypervisors that need to - e.g. for optimisations, or when the ‘VM’ is actually proxied and needs to be held across the shutdown + spin up steps.
Parameters: - context – security context
- instance – nova.objects.instance.Instance This function should use the data there to guide the creation of the new instance.
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
- injected_files – User files to inject into instance.
- admin_password – Administrator password to set in instance.
- bdms – block-device-mappings to use for rebuild
- detach_block_devices – function to detach block devices. See nova.compute.manager.ComputeManager:_rebuild_default_impl for usage.
- attach_block_devices – function to attach block devices. See nova.compute.manager.ComputeManager:_rebuild_default_impl for usage.
- network_info –
get_instance_nw_info()
- recreate – True if the instance is being recreated on a new hypervisor - all the cleanup of old state is skipped.
- block_device_info – Information about block devices to be attached to the instance.
- preserve_ephemeral – True if the default ephemeral storage partition must be preserved on rebuild
-
refresh_instance_security_rules
(instance)¶ Refresh security group rules
Gets called when an instance gets added to or removed from the security group the instance is a member of or if the group gains or loses a rule.
-
refresh_security_group_rules
(security_group_id)¶ This method is called after a change to security groups.
All security groups and their associated rules live in the datastore, and calling this method should apply the updated rules to instances running the specified security group.
An error should be raised if the operation cannot complete.
-
register_event_listener
(callback)¶ Register a callback to receive events.
Register a callback to receive asynchronous event notifications from hypervisors. The callback will be invoked with a single parameter, which will be an instance of the nova.virt.event.Event class.
-
remove_from_aggregate
(context, aggregate, host, **kwargs)¶ Remove a compute host from an aggregate.
The counter action to this is
add_to_aggregate()
Parameters: - context (nova.context.RequestContext) – The security context.
- aggregate (nova.objects.aggregate.Aggregate) – The aggregate which should remove the given host
- host (str) – The name of the host to remove from the given aggregate.
- kwargs (dict) – A free-form thingy...
Returns: None
-
rescue
(context, instance, network_info, image_meta, rescue_password)¶ Rescue the specified instance.
Parameters: - context (nova.context.RequestContext) – The context for the rescue.
- instance (nova.objects.instance.Instance) – The instance being rescued.
- network_info (nova.network.model.NetworkInfo) – Necessary network information for the resume.
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
- rescue_password – new root password to set for rescue.
-
reset_network
(instance)¶ reset networking for specified instance.
-
restore
(instance)¶ Restore the specified soft-deleted instance.
The restored instance will be automatically booted. The counter action for restore is
soft_delete()
.Parameters: instance (nova.objects.instance.Instance) – The soft-deleted instance which should be restored from the soft-deleted data. Returns: None
-
resume
(context, instance, network_info, block_device_info=None)¶ resume the specified suspended instance.
The suspended instance gets resumed and will use CPU cycles and memory of the host again. The counter action for ‘resume’ is
suspend()
. Depending on the underlying hypervisor technology, the guest has the same state as before the ‘suspend’.Parameters: - context (nova.context.RequestContext) – The context for the resume.
- instance (nova.objects.instance.Instance) – The suspended instance to resume.
- network_info (nova.network.model.NetworkInfo) – Necessary network information for the resume.
- block_device_info (dict) – Instance volume block device info.
Returns: None
-
resume_state_on_host_boot
(context, instance, network_info, block_device_info=None)¶ resume guest state when a host is booted.
Parameters: instance – nova.objects.instance.Instance
-
rollback_live_migration_at_destination
(context, instance, network_info, block_device_info, destroy_disks=True, migrate_data=None)¶ Clean up destination node after a failed live migration.
Parameters: - context – security context
- instance – instance object that was being migrated
- network_info – instance network information
- block_device_info – instance block device information
- destroy_disks – if true, destroy disks at destination during cleanup
- migrate_data – a LiveMigrateData object
-
set_admin_password
(instance, new_pass)¶ Set the root password on the specified instance.
Parameters: - instance – nova.objects.instance.Instance
- new_pass – the new password
-
set_bootable
(instance, is_bootable)¶ Set the ability to power on/off an instance.
Parameters: instance – nova.objects.instance.Instance
-
set_host_enabled
(enabled)¶ Sets the ability of this host to accept new instances.
Parameters: enabled (bool) – If this is True, the host will accept new instances. If it is False, the host won’t accept new instances. Returns: If the host can accept further instances, return “enabled”, if further instances shouldn’t be scheduled to this host, return “disabled”. Return type: str
-
snapshot
(context, instance, image_id, update_task_state)¶ Snapshots the specified instance.
Parameters: - context – security context
- instance – nova.objects.instance.Instance
- image_id – Reference to a pre-created image that will hold the snapshot.
-
soft_delete
(instance)¶ Soft delete the specified instance.
A soft-deleted instance doesn’t allocate any resources anymore, but is still available as a database entry. The counter action
restore()
uses the database entry to create a new instance based on that.Parameters: instance (nova.objects.instance.Instance) – The instance to soft-delete. Returns: None
-
spawn
(context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None)¶ Create a new instance/VM/domain on the virtualization platform.
Once this successfully completes, the instance should be running (power_state.RUNNING).
If this fails, any partial instance should be completely cleaned up, and the virtualization platform should be in the state that it was before this call began.
Parameters: - context – security context
- instance – nova.objects.instance.Instance This function should use the data there to guide the creation of the new instance.
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
- injected_files – User files to inject into instance.
- admin_password – Administrator password to set in instance.
- network_info –
get_instance_nw_info()
- block_device_info – Information about block devices to be attached to the instance.
-
suspend
(context, instance)¶ Suspend the specified instance.
A suspended instance doesn’t use CPU cycles or memory of the host anymore. The state of the instance could be persisted on the host and allocate storage space this way. A “softer” way of suspend is
pause()
. The counter action for suspend isresume()
.Parameters: - context (nova.context.RequestContext) – The context for the suspend.
- instance (nova.objects.instance.Instance) – The instance to suspend.
Returns: None
-
swap_volume
(old_connection_info, new_connection_info, instance, mountpoint, resize_to)¶ Replace the volume attached to the given instance.
Parameters: - old_connection_info (dict) – The volume for this connection gets detached from the given instance.
- new_connection_info (dict) – The volume for this connection gets attached to the given ‘instance’.
- instance (nova.objects.instance.Instance) – The instance whose volume gets replaced by another one.
- mountpoint (str) – The mountpoint in the instance where the volume for old_connection_info is attached to.
- resize_to (int) – If the new volume is larger than the old volume, it gets resized to the given size (in Gigabyte) of resize_to.
Returns: None
-
trigger_crash_dump
(instance)¶ Trigger crash dump mechanism on the given instance.
Stalling instances can be triggered to dump the crash data. How the guest OS reacts in details, depends on the configuration of it.
Parameters: instance (nova.objects.instance.Instance) – The instance where the crash dump should be triggered. Returns: None
-
undo_aggregate_operation
(context, op, aggregate, host, set_error=True)¶ Undo for Resource Pools.
-
unfilter_instance
(instance, network_info)¶ Stop filtering instance.
-
unpause
(instance)¶ Unpause the given paused instance.
The paused instance gets unpaused and will use CPU cycles of the host again. The counter action for ‘unpause’ is
pause()
. Depending on the underlying hypervisor technology, the guest has the same state as before the ‘pause’.Parameters: instance (nova.objects.instance.Instance) – The instance which should be unpaused. Returns: None
-
unplug_vifs
(instance, network_info)¶ Unplug virtual interfaces (VIFs) from networks.
The counter action is
plug_vifs()
.Parameters: - instance (nova.objects.instance.Instance) – The instance which gets VIFs unplugged.
- network_info (nova.network.model.NetworkInfo) – The object which contains information about the VIFs to unplug.
Returns: None
-
unquiesce
(context, instance, image_meta)¶ Unquiesce the specified instance after snapshots.
If the specified instance doesn’t support quiescing, InstanceQuiesceNotSupported is raised. When it fails to quiesce by other errors (e.g. agent timeout), NovaException is raised.
Parameters: - context – request context
- instance – nova.objects.instance.Instance to be unquiesced
- image_meta (nova.objects.ImageMeta) – The metadata of the image of the instance.
-
unrescue
(instance, network_info)¶ Unrescue the specified instance.
Parameters: instance – nova.objects.instance.Instance
-
volume_snapshot_create
(context, instance, volume_id, create_info)¶ Snapshots volumes attached to a specified instance.
The counter action to this is
volume_snapshot_delete()
Parameters: - context (nova.context.RequestContext) – The security context.
- instance (nova.objects.instance.Instance) – The instance that has the volume attached
- volume_id (uuid) – Volume to be snapshotted
- create_info – The data needed for nova to be able to attach to the volume. This is the same data format returned by Cinder’s initialize_connection() API call. In the case of doing a snapshot, it is the image file Cinder expects to be used as the active disk after the snapshot operation has completed. There may be other data included as well that is needed for creating the snapshot.
-
volume_snapshot_delete
(context, instance, volume_id, snapshot_id, delete_info)¶ Deletes a snapshot of a volume attached to a specified instance.
The counter action to this is
volume_snapshot_create()
Parameters: - context (nova.context.RequestContext) – The security context.
- instance (nova.objects.instance.Instance) – The instance that has the volume attached.
- volume_id (uuid) – Attached volume associated with the snapshot
- snapshot_id (uuid) – The snapshot to delete.
- delete_info (dict) – Volume backend technology specific data needed to be able to complete the snapshot. For example, in the case of qcow2 backed snapshots, this would include the file being merged, and the file being merged into (if appropriate).
Returns: None
-
-
block_device_info_get_ephemerals
(block_device_info)¶
-
block_device_info_get_mapping
(block_device_info)¶
-
block_device_info_get_root
(block_device_info)¶
-
block_device_info_get_swap
(block_device_info)¶
-
driver_dict_from_config
(named_driver_config, *args, **kwargs)¶
-
get_block_device_info
(instance, block_device_mapping)¶ Converts block device mappings for an instance to driver format.
Virt drivers expect block device mapping to be presented in the format of a dict containing the following keys:
root_device_name: device name of the root disk
- ephemerals: a (potentially empty) list of DriverEphemeralBlockDevice
instances
swap: An instance of DriverSwapBlockDevice or None
- block_device_mapping: a (potentially empty) list of
DriverVolumeBlockDevice or any of it’s more specialized subclasses.
-
is_xenapi
()¶
-
load_compute_driver
(virtapi, compute_driver=None)¶ Load a compute driver module.
Load the compute driver module specified by the compute_driver configuration option or, if supplied, the driver name supplied as an argument.
Compute drivers constructors take a VirtAPI object as their first object and this must be supplied.
Parameters: - virtapi – a VirtAPI instance
- compute_driver – a compute driver name to override the config opt
Returns: a ComputeDriver instance
-
swap_is_usable
(swap)¶