The nova.compute.api Module

Handles all requests relating to compute resources (e.g. guest VMs, networking and storage of VMs, and compute hosts on which they run).

class API(image_service=None, network_api=None, volume_api=None, security_group_api=None, **kwargs)

Bases: nova.db.base.Base

API for interacting with the compute manager.

add_fixed_ip(context, target, *args, **kwargs)

Add fixed_ip from specified network to given instance.

attach_interface(context, target, *args, **kwargs)

Use hotplug to add an network adapter to an instance.

attach_volume(context, target, *args, **kwargs)

Attach an existing volume to an existing instance.

backup(context, target, *args, **kwargs)

Backup the given instance

Parameters:
  • instance – nova.db.sqlalchemy.models.Instance
  • name – name of the backup or snapshot name = backup_type # daily backups are called ‘daily’
  • rotation – int representing how many backups to keep around; None if rotation shouldn’t be used (as in the case of snapshots)
  • extra_properties – dict of extra image properties to include
confirm_resize(context, target, *args, **kwargs)

Confirms a migration/resize and deletes the ‘old’ instance.

create(*args, **kwargs)

Provision instances, sending instance information to the scheduler. The scheduler will determine where the instance(s) go and will handle creating the DB entries.

Returns a tuple of (instances, reservation_id)

create_db_entry_for_new_instance(context, instance_type, image, base_options, security_group, block_device_mapping, num_instances, index)

Create an entry in the DB for this new instance, including any related table updates (such as security group, etc).

This is called by the scheduler after a location for the instance has been determined.

delete(context, target, *args, **kwargs)

Terminate an instance.

delete_instance_metadata(context, target, *args, **kwargs)

Delete the given metadata item from an instance.

detach_interface(context, target, *args, **kwargs)

Detach an network adapter from an instance.

detach_volume(context, volume_id)

Detach a volume from an instance.

evacuate(context, instance, *args, **kw)

Running evacuate to target host.

Checking vm compute host state, if the host not in expected_state, raising an exception.

force_delete(context, target, *args, **kwargs)

Force delete a previously deleted (but not reclaimed) instance.

get(context, instance_id)

Get a single instance with the given instance_id.

get_active_by_window(context, begin, end=None, project_id=None)

Get instances that were continuously active over a window.

get_all(context, search_opts=None, sort_key='created_at', sort_dir='desc', limit=None, marker=None)

Get all instances filtered by one of the given parameters.

If there is no filter and the context is an admin, it will retrieve all instances in the system.

Deleted instances will be returned by default, unless there is a search option that says otherwise.

The results will be returned sorted in the order specified by the ‘sort_dir’ parameter using the key specified in the ‘sort_key’ parameter.

get_backdoor_port(context, host_name)

Retrieve backdoor port.

get_console_output(context, target, *args, **kwargs)

Get console output for an instance.

get_diagnostics(context, target, *args, **kwargs)

Retrieve diagnostics for the given instance.

get_instance_bdms(context, instance)

Get all bdm tables for specified instance.

get_instance_faults(context, instances)

Get all faults for a list of instance uuids.

get_instance_metadata(context, target, *args, **kwargs)

Get all metadata associated with an instance.

get_instance_type(context, instance_type_id)

Get an instance type by instance type id.

get_lock(context, target, *args, **kwargs)

Return the boolean state of given instance’s lock.

get_spice_connect_info(context, instance, *args, **kwargs)

Used in a child cell to get console info.

get_spice_console(context, target, *args, **kwargs)

Get a url to an instance Console.

get_vnc_connect_info(context, instance, *args, **kwargs)

Used in a child cell to get console info.

get_vnc_console(context, target, *args, **kwargs)

Get a url to an instance Console.

inject_file(context, target, *args, **kwargs)

Write a file to the given instance.

inject_network_info(context, target, *args, **kwargs)

Inject network info for the instance.

is_volume_backed_instance(context, instance, bdms)
live_migrate(context, instance, *args, **kw)

Migrate a server lively to a new host.

lock(context, target, *args, **kwargs)

Lock the given instance.

pause(context, target, *args, **kwargs)

Pause the given instance.

reboot(context, target, *args, **kwargs)

Reboot the given instance.

rebuild(context, target, *args, **kwargs)

Rebuild the given instance with the provided attributes.

remove_fixed_ip(context, target, *args, **kwargs)

Remove fixed_ip from specified network to given instance.

rescue(context, target, *args, **kwargs)

Rescue the given instance.

reset_network(context, target, *args, **kwargs)

Reset networking on the instance.

resize(context, target, *args, **kwargs)

Resize (ie, migrate) a running instance.

If flavor_id is None, the process is considered a migration, keeping the original flavor_id. If flavor_id is not None, the instance should be migrated to a new host and resized to the new flavor_id.

restore(context, target, *args, **kwargs)

Restore a previously deleted (but not reclaimed) instance.

resume(context, target, *args, **kwargs)

Resume the given instance.

revert_resize(context, target, *args, **kwargs)

Reverts a resize, deleting the ‘new’ instance in the process.

set_admin_password(context, target, *args, **kwargs)

Set the root/admin password for the given instance.

snapshot(context, target, *args, **kwargs)

Snapshot the given instance.

Parameters:
  • instance – nova.db.sqlalchemy.models.Instance
  • name – name of the backup or snapshot
  • extra_properties – dict of extra image properties to include
Returns:

A dict containing image metadata

snapshot_volume_backed(context, instance, *args, **kw)

Snapshot the given volume-backed instance.

Parameters:
  • instance – nova.db.sqlalchemy.models.Instance
  • image_meta – metadata for the new image
  • name – name of the backup or snapshot
  • extra_properties – dict of extra image properties to include
Returns:

the new image metadata

soft_delete(context, target, *args, **kwargs)

Terminate an instance.

start(context, target, *args, **kwargs)

Start an instance.

stop(context, target, *args, **kwargs)

Stop an instance.

suspend(context, target, *args, **kwargs)

Suspend the given instance.

trigger_provider_fw_rules_refresh(context)

Called when a rule is added/removed from a provider firewall.

unlock(context, target, *args, **kwargs)

Unlock the given instance.

unpause(context, target, *args, **kwargs)

Unpause the given instance.

unrescue(context, target, *args, **kwargs)

Unrescue the given instance.

update(context, target, *args, **kwargs)

Updates the instance in the datastore.

Parameters:
  • context – The security context
  • instance – The instance to update
  • kwargs – All additional keyword args are treated as data fields of the instance to be updated
Returns:

None

update_instance_metadata(context, target, *args, **kwargs)

Updates or creates instance metadata.

If delete is True, metadata items that are not specified in the metadata argument will be deleted.

update_state(context, instance, new_state)

Updates the state of a compute instance. For example to ‘active’ or ‘error’. Also sets ‘task_state’ to None. Used by admin_actions api

Parameters:
  • context – The security context
  • instance – The instance to update
  • new_state – A member of vm_state, eg. ‘active’
class AggregateAPI(**kwargs)

Bases: nova.db.base.Base

Sub-set of the Compute Manager API for managing host aggregates.

add_host_to_aggregate(context, aggregate_id, host_name)

Adds the host to an aggregate.

create_aggregate(context, aggregate_name, availability_zone)

Creates the model for the aggregate.

delete_aggregate(context, aggregate_id)

Deletes the aggregate.

get_aggregate(context, aggregate_id)

Get an aggregate by id.

get_aggregate_list(context)

Get all the aggregates.

remove_host_from_aggregate(context, aggregate_id, host_name)

Removes host from the aggregate.

update_aggregate(context, aggregate_id, values)

Update the properties of an aggregate.

update_aggregate_metadata(context, aggregate_id, metadata)

Updates the aggregate metadata.

If a key is set to None, it gets removed from the aggregate metadata.

class HostAPI(rpcapi=None)

Bases: nova.db.base.Base

Sub-set of the Compute Manager API for managing host operations.

compute_node_get(context, compute_id)

Return compute node entry for particular integer ID.

compute_node_get_all(context)
compute_node_search_by_hypervisor(context, hypervisor_match)
compute_node_statistics(context)
get_host_uptime(context, host_name)

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

host_power_action(context, host_name, action)

Reboots, shuts down or powers up the host.

instance_get_all_by_host(context, host_name)

Return all instances on the given host.

service_get_all(context, filters=None, set_zones=False)

Returns a list of services, optionally filtering the results.

If specified, ‘filters’ should be a dictionary containing services attributes and matching values. Ie, to get a list of services for the ‘compute’ topic, use filters={‘topic’: ‘compute’}.

service_get_by_compute_host(context, host_name)

Get service entry for the given compute hostname.

set_host_enabled(context, host_name, enabled)

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

set_host_maintenance(context, host_name, mode)

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

task_log_get_all(context, task_name, period_beginning, period_ending, host=None, state=None)

Return the task logs within a given range, optionally filtering by host and/or state.

class InstanceActionAPI(db_driver=None)

Bases: nova.db.base.Base

Sub-set of the Compute Manager API for managing instance actions.

action_events_get(context, instance, action_id)
action_get_by_request_id(context, instance, request_id)
actions_get(context, instance)
class KeypairAPI(**kwargs)

Bases: nova.db.base.Base

Sub-set of the Compute Manager API for managing key pairs.

create_key_pair(context, user_id, key_name)

Create a new key pair.

delete_key_pair(context, user_id, key_name)

Delete a keypair by name.

get_key_pair(context, user_id, key_name)

Get a keypair by name.

get_key_pairs(context, user_id)

List key pairs.

import_key_pair(context, user_id, key_name, public_key)

Import a key pair using an existing public key.

class SecurityGroupAPI(**kwargs)

Bases: nova.db.base.Base, nova.network.security_group.security_group_base.SecurityGroupBase

Sub-set of the Compute API related to managing security groups and security group rules

add_default_rules(context, vals)
add_rules(context, id, name, vals)

Add security group rule(s) to security group.

Note: the Nova security group API doesn’t support adding muliple security group rules at once but the EC2 one does. Therefore, this function is writen to support both.

add_to_instance(context, target, *args, **kwargs)

Add security group to the instance.

create_security_group(context, name, description)
default_rule_exists(context, values)

Indicates whether the specified rule values are already defined in the default security group rules.

destroy(context, security_group)
ensure_default(context)

Ensure that a context has a security group.

Creates a security group for the security context if it does not already exist.

Parameters:context – the security context
get(context, name=None, id=None, map_exception=False)
get_all_default_rules(context)
get_default_rule(context, id)
get_instance_security_groups(context, instance_id, instance_uuid=None, detailed=False)
get_rule(context, id)
id_is_uuid = False
is_associated_with_server(security_group, instance_uuid)

Check if the security group is already associated with the instance. If Yes, return True.

list(context, names=None, ids=None, project=None, search_opts=None)
populate_security_groups(instance, security_groups)
remove_default_rules(context, rule_ids)
remove_from_instance(context, target, *args, **kwargs)

Remove the security group associated with the instance.

remove_rules(context, security_group, rule_ids)
trigger_handler(event, *args)
trigger_members_refresh(context, group_ids)

Called when a security group gains a new or loses a member.

Sends an update request to each compute node for each instance for which this is relevant.

trigger_rules_refresh(context, id)

Called when a rule is added to or removed from a security_group.

validate_id(id)
validate_property(value, property, allowed)

Validate given security group property.

Parameters:
  • value – the value to validate, as a string or unicode
  • property – the property, either ‘name’ or ‘description’
  • allowed – the range of characters allowed
check_instance_host(function)
check_instance_lock(function)
check_instance_state(vm_state=None, task_state=(None, ))

Decorator to check VM and/or task state before entry to API functions.

If the instance is in the wrong state, the wrapper will raise an exception.

check_policy(context, action, target, scope='compute')
policy_decorator(scope)

Check corresponding policy prior of wrapped method to execution.

wrap_check_policy(func)
wrap_check_security_groups_policy(func)

Previous topic

The nova.cloudpipe.pipelib Module

Next topic

The nova.compute.cells_api Module

This Page