Driver base-classes:
(Beginning of) the contract that compute drivers must follow, and shared types that support that contract
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 a compute host to an aggregate.
The counter action to this is remove_from_aggregate()
Parameters: |
|
---|---|
Returns: | None |
Use hotplug to add a network interface to a running instance.
The counter action to this is detach_interface().
Parameters: |
|
---|---|
Raises nova.exception.NovaException: | |
If the attach fails. |
|
Returns: | None |
Attach the disk to the instance at mountpoint using info.
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.
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: |
|
---|
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: |
|
---|---|
Returns: | a LiveMigrateData object (hypervisor-dependent) |
Do required cleanup on dest host after check_can_live_migrate calls
Parameters: |
|
---|
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: |
|
---|---|
Returns: | a LiveMigrateData object |
Do cleanup on host after check_instance_shared_storage calls
Parameters: |
|
---|
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: |
|
---|
Check if instance files located on shared storage.
Parameters: |
|
---|
Cleanup the instance resources .
Instance should have been destroyed from the Hypervisor before calling this method.
Parameters: |
|
---|
Clean up anything that is necessary for the driver gracefully stop, including ending remote sessions. This is optional.
Confirms a resize/migration, destroying the source VM.
Parameters: | instance – nova.objects.instance.Instance |
---|
Does the driver want networks deallocated on reschedule?
Default the missing device names in the block device mapping.
Provide a default root device name for the driver.
Parameters: |
|
---|
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 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: |
|
---|
Use hotunplug to remove a network interface from a running instance.
The counter action to this is attach_interface().
Parameters: |
|
---|---|
Raises nova.exception.NovaException: | |
If the detach fails. |
|
Returns: | None |
Detach the disk attached to the 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’}
]
|
---|
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.
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 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. |
Turn off deferral of IPTables rules and apply the rules now.
Defer application of IPTables rules.
Completes a resize/migration.
Parameters: |
|
---|
Finish reverting a resize/migration.
Parameters: |
|
---|
Parameters: | instances – nova.objects.instance.InstanceList |
---|
Return usage info for volumes attached to vms on a given host.-
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].
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 for an instance
Parameters: |
|
---|
Get the next device name based on the block device mapping.
Parameters: |
|
---|---|
Returns: | The chosen device name. |
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 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},
|
---|
Retrieves the IP address of the dom0
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 the current status of an instance, by name (not ID!)
Parameters: | instance – nova.objects.instance.Instance object |
---|
Returns a InstanceInfo object
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 |
Retrieve information about actual disk sizes of an instance.
Parameters: |
|
---|---|
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 connection info for a MKS console.
Parameters: |
|
---|
:returns an instance of console.type.ConsoleMKS
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 information about instance resource usage.
Returns: | dict of nova uuid => dict of usage info |
---|
Get connection info for a rdp console.
Parameters: |
|
---|
:returns an instance of console.type.ConsoleRDP
Get connection info for a serial console.
Parameters: |
|
---|
:returns an instance of console.type.ConsoleSerial
Get connection info for a spice console.
Parameters: |
|
---|
:returns an instance of console.type.ConsoleSpice
Get connection info for a vnc console.
Parameters: |
|
---|
:returns an instance of console.type.ConsoleVNC
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
}
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: |
|
---|---|
Returns: | “on_maintenance” if switched to maintenance mode or “off_maintenance” if maintenance mode got left. |
Return type: | str |
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 |
Initialize anything that is necessary for the driver to function, including catching up with currently running VM’s on the given host.
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 for specified 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.
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
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. |
---|
Return the UUIDS of all the instances known to the virtualization layer, as a list.
Return the names of all the instances known to the virtualization layer, as a list.
Live migration of an instance to another host.
Parameters: |
|
---|
Abort an in-progress live migration.
Parameters: | instance – instance that is live migrating |
---|
Force live migration to complete
Parameters: | instance – Instance being live migrated |
---|
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 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 |
---|
Transfers the disk of a running instance in multiple phases, turning off the instance before the end.
Parameters: |
|
---|---|
Returns: | A list of disk information dicts in JSON format. |
Return type: | str |
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.
Get host ID to associate with network ports.
Parameters: |
|
---|---|
Returns: | a string representing the host ID |
Return whether this compute service manages a particular node.
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 virtual interfaces (VIFs) into the given instance at instance boot time.
The counter action is unplug_vifs().
Parameters: |
|
---|---|
Returns: | None |
Perform a reboot on all given ‘instances’.
Reboots the given instances which are longer in the rebooting state than timeout seconds.
Parameters: |
|
---|---|
Returns: | None |
Cleans up any resources left after an interrupted snapshot.
Parameters: |
|
---|
Post operation of live migration at source host.
Parameters: |
|
---|---|
Instance: | instance object that was migrated |
Block_device_info: | |
instance block device information |
Post operation of live migration at destination host.
Parameters: |
|
---|
Unplug VIFs from networks at source.
Parameters: |
|
---|
Power off the specified instance.
Parameters: |
|
---|
Power on the specified instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
Prepare an instance for live migration
Parameters: |
|
---|
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: |
|
---|
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: |
|
---|
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: |
|
---|
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.
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 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 a compute host from an aggregate.
The counter action to this is add_to_aggregate()
Parameters: |
|
---|---|
Returns: | None |
Rescue the specified instance.
Parameters: |
|
---|
reset networking for specified 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 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: |
|
---|---|
Returns: | None |
resume guest state when a host is booted.
Parameters: | instance – nova.objects.instance.Instance |
---|
Clean up destination node after a failed live migration.
Parameters: |
|
---|
Set the root password on the specified instance.
Parameters: |
|
---|
Set the ability to power on/off an instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
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 |
Snapshots the specified instance.
Parameters: |
|
---|
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 |
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: |
|
---|
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 is resume().
Parameters: |
|
---|---|
Returns: | None |
Replace the volume attached to the given instance.
Parameters: |
|
---|---|
Returns: | None |
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 for Resource Pools.
Stop filtering 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 virtual interfaces (VIFs) from networks.
The counter action is plug_vifs().
Parameters: |
|
---|---|
Returns: | None |
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: |
|
---|
Unrescue the specified instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
Snapshots volumes attached to a specified instance.
The counter action to this is volume_snapshot_delete()
Parameters: |
|
---|
Deletes a snapshot of a volume attached to a specified instance.
The counter action to this is volume_snapshot_create()
Parameters: |
|
---|---|
Returns: | None |
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
instances
swap: An instance of DriverSwapBlockDevice or None
DriverVolumeBlockDevice or any of it’s more specialized subclasses.
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: |
|
---|---|
Returns: | a ComputeDriver instance |