The nova.db.sqlalchemy.api Module

Implementation of SQLAlchemy backend.

class Constraint(conditions)

Bases: object

apply(model, query)
class EqualityCondition(values)

Bases: object

clauses(field)
class InequalityCondition(values)

Bases: object

clauses(field)
action_event_finish(context, *args, **kwargs)

Finish an event on an instance action.

action_event_get_by_id(context, *args, **kwargs)
action_event_start(context, *args, **kwargs)

Start an event on an instance action.

action_events_get(context, *args, **kwargs)
action_finish(context, *args, **kwargs)
action_get_by_request_id(context, *args, **kwargs)

Get the action by request_id and given instance.

action_start(context, *args, **kwargs)
actions_get(context, *args, **kwargs)

Get all instance actions for the provided uuid.

agent_build_create(*args, **kwargs)
agent_build_destroy(*args, **kwargs)
agent_build_get_all(*args, **kwargs)
agent_build_get_by_triple(*args, **kwargs)
agent_build_update(*args, **kwargs)
aggregate_create(*args, **kwargs)
aggregate_delete(*args, **kwargs)
aggregate_get(*args, **kwargs)
aggregate_get_all(*args, **kwargs)
aggregate_get_by_host(*args, **kwargs)

Return rows that match host (mandatory) and metadata key (optional).

:param host matches host, and is required. :param key Matches metadata key, if not None.

aggregate_get_by_metadata_key(*args, **kwargs)

Return rows that match metadata key.

:param key Matches metadata key.

aggregate_host_add(context, aggregate_id, *args, **kwargs)
aggregate_host_delete(context, aggregate_id, *args, **kwargs)
aggregate_host_get_all(context, aggregate_id, *args, **kwargs)
aggregate_metadata_add(context, aggregate_id, *args, **kwargs)
aggregate_metadata_delete(context, aggregate_id, *args, **kwargs)
aggregate_metadata_get(context, aggregate_id, *args, **kwargs)
aggregate_metadata_get_by_host(*args, **kwargs)
aggregate_update(*args, **kwargs)
aggregate_uuids_online_data_migration(*args, **kwargs)
archive_deleted_rows(max_rows=None)

Move up to max_rows rows from production tables to the corresponding shadow tables.

Returns:dict that maps table name to number of rows archived from that table, for example:
{
    'instances': 5,
    'block_device_mapping': 5,
    'pci_devices': 2,
}
block_device_mapping_create(*args, **kwargs)
block_device_mapping_destroy(*args, **kwargs)
block_device_mapping_destroy_by_instance_and_device(*args, **kwargs)
block_device_mapping_destroy_by_instance_and_volume(*args, **kwargs)
block_device_mapping_get_all_by_instance(*args, **kwargs)
block_device_mapping_get_all_by_instance_uuids(*args, **kwargs)
block_device_mapping_get_all_by_volume_id(*args, **kwargs)
block_device_mapping_get_by_instance_and_volume_id(*args, **kwargs)
block_device_mapping_update(*args, **kwargs)
block_device_mapping_update_or_create(context, *args, **kwargs)
bw_usage_get(*args, **kwargs)
bw_usage_get_by_uuids(*args, **kwargs)
bw_usage_update(*args, **kwargs)
cell_create(*args, **kwargs)
cell_delete(*args, **kwargs)
cell_get(*args, **kwargs)
cell_get_all(*args, **kwargs)
cell_update(*args, **kwargs)
certificate_create(*args, **kwargs)
certificate_get_all_by_project(*args, **kwargs)
certificate_get_all_by_user(*args, **kwargs)
certificate_get_all_by_user_and_project(*args, **kwargs)
compute_node_create(context, *args, **kwargs)

Creates a new ComputeNode and populates the capacity fields with the most recent data.

compute_node_delete(context, *args, **kwargs)

Delete a ComputeNode record.

compute_node_get(context, *args, **kwargs)
compute_node_get_all(context, *args, **kwargs)
compute_node_get_all_by_host(context, *args, **kwargs)
compute_node_get_by_host_and_nodename(context, *args, **kwargs)
compute_node_get_model(context, *args, **kwargs)
compute_node_search_by_hypervisor(context, *args, **kwargs)
compute_node_statistics(context, *args, **kwargs)

Compute statistics over all compute nodes.

compute_node_update(*args, **kwargs)

Updates the ComputeNode record with the most recent data.

compute_nodes_get_by_service_id(context, *args, **kwargs)
computenode_uuids_online_data_migration(*args, **kwargs)
configure(conf)
console_create(context, *args, **kwargs)
console_delete(context, *args, **kwargs)
console_get(context, *args, **kwargs)
console_get_all_by_instance(context, *args, **kwargs)
console_get_by_pool_instance(context, *args, **kwargs)
console_pool_create(context, *args, **kwargs)
console_pool_get_all_by_host_type(context, *args, **kwargs)
console_pool_get_by_host_type(context, *args, **kwargs)
constraint(**conditions)
create_context_manager(connection=None)

Create a database context manager object.

: param connection: The database connection string

dnsdomain_get(*args, **kwargs)
dnsdomain_get_all(*args, **kwargs)
dnsdomain_register_for_project(*args, **kwargs)
dnsdomain_register_for_zone(*args, **kwargs)
dnsdomain_unregister(*args, **kwargs)
ec2_instance_create(*args, **kwargs)

Create ec2 compatible instance by provided uuid.

ec2_instance_get_by_id(*args, **kwargs)
ec2_instance_get_by_uuid(*args, **kwargs)
ec2_snapshot_create(*args, **kwargs)

Create ec2 compatible snapshot by provided uuid.

ec2_snapshot_get_by_ec2_id(*args, **kwargs)
ec2_snapshot_get_by_uuid(*args, **kwargs)
ec2_volume_create(*args, **kwargs)

Create ec2 compatible volume by provided uuid.

ec2_volume_get_by_id(*args, **kwargs)
ec2_volume_get_by_uuid(*args, **kwargs)
equal_any(*values)
fixed_ip_associate(*args, **kwargs)

Keyword arguments: reserved – should be a boolean value(True or False), exact value will be used to filter on the fixed IP address

fixed_ip_associate_pool(*args, **kwargs)

allocate a fixed ip out of a fixed ip network pool.

This allocates an unallocated fixed ip out of a specified network. We sort by updated_at to hand out the oldest address in the list.

fixed_ip_bulk_create(*args, **kwargs)
fixed_ip_create(*args, **kwargs)
fixed_ip_disassociate(*args, **kwargs)
fixed_ip_disassociate_all_by_timeout(*args, **kwargs)
fixed_ip_get(*args, **kwargs)
fixed_ip_get_all(*args, **kwargs)
fixed_ip_get_by_address(*args, **kwargs)
fixed_ip_get_by_floating_address(*args, **kwargs)
fixed_ip_get_by_host(*args, **kwargs)
fixed_ip_get_by_instance(*args, **kwargs)
fixed_ip_get_by_network_host(*args, **kwargs)
fixed_ip_update(*args, **kwargs)
fixed_ips_by_virtual_interface(*args, **kwargs)
flavor_access_add(*args, **kwargs)

Add given tenant to the flavor access list.

flavor_access_get_by_flavor_id(*args, **kwargs)

Get flavor access list by flavor id.

flavor_access_remove(*args, **kwargs)

Remove given tenant from the flavor access list.

flavor_create(*args, **kwargs)

Create a new instance type. In order to pass in extra specs, the values dict should contain a ‘extra_specs’ key/value pair:

{‘extra_specs’ : {‘k1’: ‘v1’, ‘k2’: ‘v2’, ...}}

flavor_destroy(*args, **kwargs)

Marks specific flavor as deleted.

flavor_extra_specs_delete(*args, **kwargs)
flavor_extra_specs_get(*args, **kwargs)
flavor_extra_specs_update_or_create(*args, **kwargs)
flavor_get(*args, **kwargs)

Returns a dict describing specific flavor.

flavor_get_all(*args, **kwargs)

Returns all flavors.

flavor_get_by_flavor_id(*args, **kwargs)

Returns a dict describing specific flavor_id.

flavor_get_by_name(*args, **kwargs)

Returns a dict describing specific flavor.

floating_ip_allocate_address(*args, **kwargs)
floating_ip_bulk_create(*args, **kwargs)
floating_ip_bulk_destroy(*args, **kwargs)
floating_ip_create(*args, **kwargs)
floating_ip_deallocate(*args, **kwargs)
floating_ip_destroy(*args, **kwargs)
floating_ip_disassociate(*args, **kwargs)
floating_ip_fixed_ip_associate(*args, **kwargs)
floating_ip_get(*args, **kwargs)
floating_ip_get_all(*args, **kwargs)
floating_ip_get_all_by_host(*args, **kwargs)
floating_ip_get_all_by_project(*args, **kwargs)
floating_ip_get_by_address(*args, **kwargs)
floating_ip_get_by_fixed_address(*args, **kwargs)
floating_ip_get_by_fixed_ip_id(*args, **kwargs)
floating_ip_get_pools(*args, **kwargs)
floating_ip_update(*args, **kwargs)
get_api_engine()
get_backend()

The backend is this module itself.

get_context_manager(context)

Get a database context manager object.

Parameters:context – The request context that can contain a context manager
get_engine(use_slave=False, context=None)

Get a database engine object.

Parameters:
  • use_slave – Whether to use the slave connection
  • context – The request context that can contain a context manager
get_instance_uuid_by_ec2_id(*args, **kwargs)
instance_add_security_group(context, *args, **kwargs)

Associate the given security group with the given instance.

instance_create(*args, **kwargs)

Create a new Instance record in the database.

context - request context object values - dict containing column values.

instance_destroy(*args, **kwargs)
instance_extra_get_by_instance_uuid(context, *args, **kwargs)
instance_extra_update_by_uuid(context, *args, **kwargs)
instance_fault_create(context, *args, **kwargs)

Create a new InstanceFault.

instance_fault_get_by_instance_uuids(context, *args, **kwargs)

Get all instance faults for the provided instance_uuids.

instance_floating_address_get_all(*args, **kwargs)
instance_get(*args, **kwargs)
instance_get_active_by_window_joined(*args, **kwargs)

Return instances and joins that were active during window.

instance_get_all(*args, **kwargs)
instance_get_all_by_filters(*args, **kwargs)

Return instances matching all filters sorted by the primary key.

See instance_get_all_by_filters_sort for more information.

instance_get_all_by_filters_sort(*args, **kwargs)

Return instances that match all filters sorted by the given keys. Deleted instances will be returned by default, unless there’s a filter that says otherwise.

Depending on the name of a filter, matching for that filter is performed using either exact matching or as regular expression matching. Exact matching is applied for the following filters:

|   ['project_id', 'user_id', 'image_ref',
|    'vm_state', 'instance_type_id', 'uuid',
|    'metadata', 'host', 'system_metadata']

A third type of filter (also using exact matching), filters based on instance metadata tags when supplied under a special key named ‘filter’:

|   filters = {
|       'filter': [
|           {'name': 'tag-key', 'value': '<metakey>'},
|           {'name': 'tag-value', 'value': '<metaval>'},
|           {'name': 'tag:<metakey>', 'value': '<metaval>'}
|       ]
|   }

Special keys are used to tweek the query further:

|   'changes-since' - only return instances updated after
|   'deleted' - only return (or exclude) deleted instances
|   'soft_deleted' - modify behavior of 'deleted' to either
|                    include or exclude instances whose
|                    vm_state is SOFT_DELETED.

A fourth type of filter (also using exact matching), filters based on instance tags (not metadata tags). There are two types of these tags:

tags – One or more strings that will be used to filter results
in an AND expression.
tags-any – One or more strings that will be used to filter results in
an OR expression.

Tags should be represented as list:

|    filters = {
|        'tags': [some-tag, some-another-tag],
|        'tags-any: [some-any-tag, some-another-any-tag]
|    }
instance_get_all_by_grantee_security_groups(context, *args, **kwargs)
instance_get_all_by_host(context, *args, **kwargs)
instance_get_all_by_host_and_node(context, *args, **kwargs)
instance_get_all_by_host_and_not_type(context, *args, **kwargs)
instance_get_all_hung_in_rebooting(context, *args, **kwargs)
instance_get_by_uuid(*args, **kwargs)
instance_group_create(*args, **kwargs)

Create a new group.

instance_group_delete(*args, **kwargs)

Delete a group.

instance_group_get(*args, **kwargs)

Get a specific group by uuid.

instance_group_get_all(*args, **kwargs)

Get all groups.

instance_group_get_all_by_project_id(*args, **kwargs)

Get all groups.

instance_group_get_by_instance(*args, **kwargs)
instance_group_member_delete(*args, **kwargs)
instance_group_members_add(*args, **kwargs)
instance_group_members_get(*args, **kwargs)
instance_group_update(*args, **kwargs)

Update the attributes of a group.

If values contains a metadata key, it updates the aggregate metadata too. Similarly for the policies and members.

instance_info_cache_delete(*args, **kwargs)

Deletes an existing instance_info_cache record

Parameters:instance_uuid – = uuid of the instance tied to the cache record
instance_info_cache_get(*args, **kwargs)

Gets an instance info cache from the table.

Parameters:instance_uuid – = uuid of the info cache’s instance
instance_info_cache_update(*args, **kwargs)

Update an instance info cache record in the table.

Parameters:
  • instance_uuid – = uuid of info cache’s instance
  • values – = dict containing column values to update
instance_metadata_delete(*args, **kwargs)
instance_metadata_get(*args, **kwargs)
instance_metadata_update(*args, **kwargs)
instance_remove_security_group(*args, **kwargs)

Disassociate the given security group from the given instance.

instance_system_metadata_get(*args, **kwargs)
instance_system_metadata_update(*args, **kwargs)
instance_tag_add(context, *args, **kwargs)
instance_tag_delete(context, *args, **kwargs)
instance_tag_delete_all(context, *args, **kwargs)
instance_tag_exists(*args, **kwargs)
instance_tag_get_by_instance_uuid(context, *args, **kwargs)
instance_tag_set(context, *args, **kwargs)
instance_update(*args, **kwargs)
instance_update_and_get_original(*args, **kwargs)

Set the given properties on an instance and update it. Return a shallow copy of the original instance reference, as well as the updated one.

Parameters:
  • context – = request context object
  • instance_uuid – = instance uuid
  • values – = dict containing column values

If “expected_task_state” exists in values, the update can only happen when the task state before update matches expected_task_state. Otherwise a UnexpectedTaskStateError is thrown.

Returns:a tuple of the form (old_instance_ref, new_instance_ref)

Raises NotFound if instance does not exist.

key_pair_count_by_user(*args, **kwargs)
key_pair_create(*args, **kwargs)
key_pair_destroy(*args, **kwargs)
key_pair_get(*args, **kwargs)
key_pair_get_all_by_user(*args, **kwargs)
migration_create(context, *args, **kwargs)
migration_get(context, *args, **kwargs)
migration_get_all_by_filters(context, *args, **kwargs)
migration_get_by_id_and_instance(context, *args, **kwargs)
migration_get_by_instance_and_status(context, *args, **kwargs)
migration_get_in_progress_by_host_and_node(context, *args, **kwargs)
migration_get_in_progress_by_instance(context, *args, **kwargs)
migration_get_unconfirmed_by_dest_compute(context, *args, **kwargs)
migration_update(context, *args, **kwargs)
model_query(context, model, args=None, read_deleted=None, project_only=False)

Query helper that accounts for context’s read_deleted field.

Parameters:
  • context – NovaContext of the query.
  • model – Model to query. Must be a subclass of ModelBase.
  • args – Arguments to query. If None - model is used.
  • read_deleted – If not None, overrides context’s read_deleted field. Permitted values are ‘no’, which does not return deleted values; ‘only’, which only returns deleted values; and ‘yes’, which does not filter deleted values.
  • project_only – If set and context is user-type, then restrict query to match the context’s project_id. If set to ‘allow_none’, restriction includes project_id = None.
network_associate(*args, **kwargs)

Associate a project with a network.

called by project_get_networks under certain conditions and network manager add_network_to_project()

only associate if the project doesn’t already have a network or if force is True

force solves race condition where a fresh project has multiple instance builds simultaneously picked up by multiple network hosts which attempt to associate the project with multiple networks force should only be used as a direct consequence of user request all automated requests should not use force

network_count_reserved_ips(*args, **kwargs)
network_create_safe(*args, **kwargs)
network_delete_safe(*args, **kwargs)
network_disassociate(*args, **kwargs)
network_get(*args, **kwargs)
network_get_all(*args, **kwargs)
network_get_all_by_host(*args, **kwargs)
network_get_all_by_uuids(*args, **kwargs)
network_get_associated_fixed_ips(*args, **kwargs)
network_get_by_cidr(*args, **kwargs)
network_get_by_uuid(*args, **kwargs)
network_in_use_on_host(*args, **kwargs)
network_set_host(*args, **kwargs)
network_update(*args, **kwargs)
not_equal(*values)
pci_device_destroy(context, *args, **kwargs)
pci_device_get_all_by_instance_uuid(*args, **kwargs)
pci_device_get_all_by_node(context, *args, **kwargs)
pci_device_get_all_by_parent_addr(context, *args, **kwargs)
pci_device_get_by_addr(context, *args, **kwargs)
pci_device_get_by_id(context, *args, **kwargs)
pci_device_update(context, *args, **kwargs)
pcidevice_online_data_migration(*args, **kwargs)
pick_context_manager_reader(f)

Decorator to use a reader db context manager.

The db context manager will be picked from the RequestContext.

Wrapped function must have a RequestContext in the arguments.

pick_context_manager_reader_allow_async(f)

Decorator to use a reader.allow_async db context manager.

The db context manager will be picked from the RequestContext.

Wrapped function must have a RequestContext in the arguments.

pick_context_manager_writer(f)

Decorator to use a writer db context manager.

The db context manager will be picked from the RequestContext.

Wrapped function must have a RequestContext in the arguments.

process_sort_params(sort_keys, sort_dirs, default_keys=['created_at', 'id'], default_dir='asc')

Process the sort parameters to include default keys.

Creates a list of sort keys and a list of sort directions. Adds the default keys to the end of the list if they are not already included.

When adding the default keys to the sort keys list, the associated direction is: 1) The first element in the ‘sort_dirs’ list (if specified), else 2) ‘default_dir’ value (Note that ‘asc’ is the default value since this is the default in sqlalchemy.utils.paginate_query)

Parameters:
  • sort_keys – List of sort keys to include in the processed list
  • sort_dirs – List of sort directions to include in the processed list
  • default_keys – List of sort keys that need to be included in the processed list, they are added at the end of the list if not already specified.
  • default_dir – Sort direction associated with each of the default keys that are not supplied, used when they are added to the processed list
Returns:

list of sort keys, list of sort directions

Raises exception.InvalidInput:
 

If more sort directions than sort keys are specified or if an invalid sort direction is specified

project_get_networks(*args, **kwargs)
provider_fw_rule_create(*args, **kwargs)
provider_fw_rule_destroy(*args, **kwargs)
provider_fw_rule_get_all(*args, **kwargs)
quota_class_create(*args, **kwargs)
quota_class_get(*args, **kwargs)
quota_class_get_all_by_name(*args, **kwargs)
quota_class_get_default(*args, **kwargs)
quota_class_update(*args, **kwargs)
quota_create(*args, **kwargs)
quota_destroy_all_by_project(*args, **kwargs)
quota_destroy_all_by_project_and_user(*args, **kwargs)
quota_get(*args, **kwargs)
quota_get_all(*args, **kwargs)
quota_get_all_by_project(*args, **kwargs)
quota_get_all_by_project_and_user(*args, **kwargs)
quota_reserve(*args, **kwargs)
quota_update(*args, **kwargs)
quota_usage_get(*args, **kwargs)
quota_usage_get_all_by_project(*args, **kwargs)
quota_usage_get_all_by_project_and_user(*args, **kwargs)
quota_usage_update(*args, **kwargs)
require_aggregate_exists(f)

Decorator to require the specified aggregate to exist.

Requires the wrapped function to use context and aggregate_id as their first two arguments.

require_context(f)

Decorator to require any user or admin context.

This does no authorization for user or project access matching, see nova.context.authorize_project_context() and nova.context.authorize_user_context().

The first argument to the wrapped function must be the context.

require_instance_exists_using_uuid(f)

Decorator to require the specified instance to exist.

Requires the wrapped function to use context and instance_uuid as their first two arguments.

reservation_commit(*args, **kwargs)
reservation_expire(*args, **kwargs)
reservation_rollback(*args, **kwargs)
s3_image_create(*args, **kwargs)

Create local s3 image represented by provided uuid.

s3_image_get(*args, **kwargs)

Find local s3 image represented by the provided id.

s3_image_get_by_uuid(*args, **kwargs)

Find local s3 image represented by the provided uuid.

security_group_create(*args, **kwargs)
security_group_default_rule_create(*args, **kwargs)
security_group_default_rule_destroy(*args, **kwargs)
security_group_default_rule_get(*args, **kwargs)
security_group_default_rule_list(*args, **kwargs)
security_group_destroy(*args, **kwargs)
security_group_ensure_default(context)

Ensure default security group exists for a project_id.

security_group_get(*args, **kwargs)
security_group_get_all(*args, **kwargs)
security_group_get_by_instance(*args, **kwargs)
security_group_get_by_name(*args, **kwargs)
security_group_get_by_project(*args, **kwargs)
security_group_in_use(*args, **kwargs)
security_group_rule_count_by_group(*args, **kwargs)
security_group_rule_create(*args, **kwargs)
security_group_rule_destroy(*args, **kwargs)
security_group_rule_get(*args, **kwargs)
security_group_rule_get_by_instance(*args, **kwargs)
security_group_rule_get_by_security_group(*args, **kwargs)
security_group_update(*args, **kwargs)
select_db_reader_mode(f)

Decorator to select synchronous or asynchronous reader mode.

The kwarg argument ‘use_slave’ defines reader mode. Asynchronous reader will be used if ‘use_slave’ is True and synchronous reader otherwise. If ‘use_slave’ is not specified default value ‘False’ will be used.

Wrapped function must have a context in the arguments.

service_create(context, *args, **kwargs)
service_destroy(context, *args, **kwargs)
service_get(context, *args, **kwargs)
service_get_all(context, *args, **kwargs)
service_get_all_by_binary(context, *args, **kwargs)
service_get_all_by_host(context, *args, **kwargs)
service_get_all_by_topic(context, *args, **kwargs)
service_get_by_compute_host(context, *args, **kwargs)
service_get_by_host_and_binary(context, *args, **kwargs)
service_get_by_host_and_topic(context, *args, **kwargs)
service_get_minimum_version(context, *args, **kwargs)
service_update(*args, **kwargs)
task_log_begin_task(context, *args, **kwargs)
task_log_end_task(context, *args, **kwargs)
task_log_get(context, *args, **kwargs)
task_log_get_all(context, *args, **kwargs)
virtual_interface_create(*args, **kwargs)

Create a new virtual interface record in the database.

Parameters:values – = dict containing column values
virtual_interface_delete_by_instance(*args, **kwargs)

Delete virtual interface records that are associated with the instance given by instance_id.

Parameters:instance_uuid – = uuid of instance
virtual_interface_get(*args, **kwargs)

Gets a virtual interface from the table.

Parameters:vif_id – = id of the virtual interface
virtual_interface_get_all(*args, **kwargs)

Get all vifs.

virtual_interface_get_by_address(*args, **kwargs)

Gets a virtual interface from the table.

Parameters:address – = the address of the interface you’re looking to get
virtual_interface_get_by_instance(*args, **kwargs)

Gets all virtual interfaces for instance.

Parameters:instance_uuid – = uuid of the instance to retrieve vifs for
virtual_interface_get_by_instance_and_network(*args, **kwargs)

Gets virtual interface for instance that’s associated with network.

virtual_interface_get_by_uuid(*args, **kwargs)

Gets a virtual interface from the table.

Parameters:vif_uuid – the uuid of the interface you’re looking to get
vol_get_usage_by_time(*args, **kwargs)

Return volumes usage that have been updated after a specified time.

vol_usage_update(*args, **kwargs)

Previous topic

The nova.db.migration Module

Next topic

The nova.db.sqlalchemy.api_migrations.migrate_repo.versions.001_cell_mapping Module

Project Source

This Page