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.
Attach an interface to the instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
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 dict containing migration info (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 dict containing migration info (hypervisor-dependent) |
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, 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.
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: |
|
---|
Detach an interface from the instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
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 Quantum 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.
Parameters: |
|
---|
Finish reverting a resize.
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 data about VM diagnostics.
Parameters: | instance – nova.objects.instance.Instance |
---|
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 “uptime” on the target host.
Get the current status of an instance, by name (not ID!)
Parameters: | instance – nova.objects.instance.Instance object |
---|
Returns a InstanceInfo object
Return data about VM diagnostics.
Parameters: | instance – nova.objects.instance.Instance |
---|
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 guest VMs evacuation.
Reboots, shuts down or powers up the host.
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.
Inject an NMI to the specified instance.
Parameters: | instance – nova objects.instance.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: |
|
---|
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: |
|
---|
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.
Return whether this compute service manages a particular node.
Pause the specified instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
Plug VIFs into networks.
Parameters: | instance – nova.objects.instance.Instance |
---|
Poll for rebooting instances
Parameters: |
|
---|
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 triggers a firewall update based on database changes.
When this is called, rules have either been added or removed from the datastore. You can retrieve rules with nova.db.provider_fw_rule_get_all().
Provider rules take precedence over security group rules. If an IP would be allowed by a security group ingress rule, but blocked by a provider rule, then packets from the IP are dropped. This includes intra-project traffic in the case of the allow_project_net_traffic flag for the libvirt-derived classes.
This method is called when a security group is added to an instance.
This message is sent to the virtualization drivers on hosts that are running an instance that belongs to a security group that has a rule that references the security group identified by security_group_id. It is the responsibility of this method to make sure any rules that authorize traffic flow with members of the security group are updated and any new members can communicate, and any removed members cannot.
When ‘i-1’ launches or terminates we will receive the message to update members of group ‘b’, at which time we will make any changes needed to the rules for instance ‘i-0’ to allow or deny traffic coming from ‘i-1’, depending on if it is being added or removed from the group.
In this scenario, ‘i-1’ could just as easily have been running on our host ‘H0’ and this method would still have been called. The point was that this method isn’t called on the host where instances of that group are running (as is the case with refresh_security_group_rules()) but is called where references are made to authorizing those instances.
An error should be raised if the operation cannot complete.
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.
Rescue the specified instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
reset networking for specified instance.
Restore the specified instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
resume the specified instance.
Parameters: |
|
---|
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 specified host’s ability to accept new instances.
Snapshots the specified instance.
Parameters: |
|
---|
Soft delete the specified instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
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.
Parameters: |
|
---|
Replace the disk attached to the instance.
Parameters: |
|
---|
Undo for Resource Pools.
Stop filtering instance.
Unpause paused VM instance.
Parameters: | instance – nova.objects.instance.Instance |
---|
Unplug VIFs from networks.
Parameters: | instance – nova.objects.instance.Instance |
---|
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.
Parameters: |
|
---|
Snapshots volumes attached to a specified instance.
Parameters: |
|
---|
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 |