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, values)

Finish an event on an instance action.

action_event_get_by_id(context, action_id, event_id)
action_event_start(context, values)

Start an event on an instance action.

action_events_get(context, action_id)
action_finish(context, values)
action_get_by_request_id(context, instance_uuid, request_id)

Get the action by request_id and given instance.

action_start(context, values)
actions_get(context, instance_uuid)

Get all instance actions for the provided uuid.

agent_build_create(context, values)
agent_build_destroy(context, agent_build_id)
agent_build_get_all(context, hypervisor=None)
agent_build_get_by_triple(context, hypervisor, os, architecture)
agent_build_update(context, agent_build_id, values)
aggregate_create(context, values, metadata=None)
aggregate_delete(context, aggregate_id)
aggregate_get(context, aggregate_id)
aggregate_get_all(context)
aggregate_get_by_host(context, host, key=None)

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(context, key)

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(context, host, key=None)
aggregate_update(context, aggregate_id, values)
archive_deleted_rows(context, max_rows=None)

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

Returns:Number of rows archived.
archive_deleted_rows_for_table(context, tablename, max_rows)

Move up to max_rows rows from one tables to the corresponding shadow table. The context argument is only used for the decorator.

Returns:number of rows archived
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_by_volume_id(*args, **kwargs)
block_device_mapping_update(*args, **kwargs)
block_device_mapping_update_or_create(context, values, legacy=True)
bw_usage_get(*args, **kwargs)
bw_usage_get_by_uuids(*args, **kwargs)
bw_usage_update(*args, **kwargs)
cell_create(context, values)
cell_delete(context, cell_name)
cell_get(context, cell_name)
cell_get_all(context)
cell_update(context, cell_name, values)
certificate_create(context, values)
certificate_get_all_by_project(context, project_id)
certificate_get_all_by_user(context, user_id)
certificate_get_all_by_user_and_project(context, user_id, project_id)
compute_node_create(context, values)

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

compute_node_delete(context, compute_id)

Delete a ComputeNode record.

compute_node_get(context, compute_id)
compute_node_get_all(context)
compute_node_get_all_by_host(context, host, use_slave=False)
compute_node_get_by_host_and_nodename(context, host, nodename)
compute_node_search_by_hypervisor(context, hypervisor_match)
compute_node_statistics(context)

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, service_id)
console_create(context, values)
console_delete(context, console_id)
console_get(context, console_id, instance_uuid=None)
console_get_all_by_instance(context, instance_uuid, columns_to_join=None)
console_get_by_pool_instance(context, pool_id, instance_uuid)
console_pool_create(context, values)
console_pool_get_all_by_host_type(context, host, console_type)
console_pool_get_by_host_type(context, compute_host, host, console_type)
constraint(**conditions)
dnsdomain_get(*args, **kwargs)
dnsdomain_get_all(context)
dnsdomain_register_for_project(context, fqdomain, project)
dnsdomain_register_for_zone(context, fqdomain, zone)
dnsdomain_unregister(context, fqdomain)
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(context, host, time)
fixed_ip_get(*args, **kwargs)
fixed_ip_get_all(context)
fixed_ip_get_by_address(*args, **kwargs)
fixed_ip_get_by_floating_address(*args, **kwargs)
fixed_ip_get_by_host(context, host)
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(context, flavor_id, project_id)

Add given tenant to the flavor access list.

flavor_access_get_by_flavor_id(context, flavor_id)

Get flavor access list by flavor id.

flavor_access_remove(context, flavor_id, project_id)

Remove given tenant from the flavor access list.

flavor_create(context, values, projects=None)

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(context, name)

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(context)
floating_ip_get_all_by_host(context, host)
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_api_session(**kwargs)
get_backend()

The backend is this module itself.

get_engine(use_slave=False)
get_instance_uuid_by_ec2_id(*args, **kwargs)
get_session(use_slave=False, **kwargs)
instance_add_security_group(context, instance_uuid, security_group_id)

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, instance_uuid, columns=None)
instance_extra_update_by_uuid(context, instance_uuid, values)
instance_fault_create(context, values)

Create a new InstanceFault.

instance_fault_get_by_instance_uuids(context, instance_uuids)

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 the 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:

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

Tags should be represented as list:

|    filters = {
|        'tag': [some-tag, some-another-tag],
|        'tag-any: [some-any-tag, some-another-any-tag]
|    }
instance_get_all_by_grantee_security_groups(context, group_ids)
instance_get_all_by_host(context, host, columns_to_join=None, use_slave=False)
instance_get_all_by_host_and_node(context, host, node, columns_to_join=None)
instance_get_all_by_host_and_not_type(context, host, type_id=None)
instance_get_all_hung_in_rebooting(context, reboot_window)
instance_get_by_uuid(*args, **kwargs)
instance_group_create(context, values, policies=None, members=None)

Create a new group.

instance_group_delete(context, group_uuid)

Delete an group.

instance_group_get(context, group_uuid)

Get a specific group by uuid.

instance_group_get_all(context)

Get all groups.

instance_group_get_all_by_project_id(context, project_id)

Get all groups.

instance_group_get_by_instance(context, instance_uuid)
instance_group_member_delete(context, group_uuid, instance_id)
instance_group_members_add(context, group_uuid, members, set_delete=False)
instance_group_members_get(context, group_uuid)
instance_group_update(context, group_uuid, values)

Update the attributes of an 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, instance_uuid, tag)
instance_tag_delete(context, instance_uuid, tag)
instance_tag_delete_all(context, instance_uuid)
instance_tag_exists(context, instance_uuid, tag)
instance_tag_get_by_instance_uuid(context, instance_uuid)
instance_tag_set(context, instance_uuid, tags)
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, values)
migration_get(context, id)
migration_get_all_by_filters(context, filters)
migration_get_by_instance_and_status(context, instance_uuid, status)
migration_get_in_progress_by_host_and_node(context, host, node)
migration_get_unconfirmed_by_dest_compute(context, confirm_window, dest_compute, use_slave=False)
migration_update(context, id, values)
model_query(context, model, args=None, session=None, use_slave=False, 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.
  • session – If present, the session to use.
  • use_slave – If true, use a slave connection to the DB if creating a session.
  • 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(context, project_id, network_id=None, force=False)

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(context, network_id)
network_create_safe(context, values)
network_delete_safe(context, network_id)
network_disassociate(context, network_id, disassociate_host, disassociate_project)
network_get(*args, **kwargs)
network_get_all(*args, **kwargs)
network_get_all_by_host(context, host)
network_get_all_by_uuids(*args, **kwargs)
network_get_associated_fixed_ips(context, network_id, host=None)
network_get_by_cidr(context, cidr)
network_get_by_uuid(context, uuid)
network_in_use_on_host(context, network_id, host)
network_set_host(*args, **kwargs)
network_update(*args, **kwargs)
not_equal(*values)
pci_device_destroy(context, node_id, address)
pci_device_get_all_by_instance_uuid(*args, **kwargs)
pci_device_get_all_by_node(context, node_id)
pci_device_get_by_addr(context, node_id, dev_addr)
pci_device_get_by_id(context, id)
pci_device_update(context, node_id, address, values)
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(context, rule)
provider_fw_rule_destroy(context, rule_id)
provider_fw_rule_get_all(context)
quota_class_create(context, class_name, resource, limit)
quota_class_get(*args, **kwargs)
quota_class_get_all_by_name(*args, **kwargs)
quota_class_get_default(context)
quota_class_update(context, class_name, resource, limit)
quota_create(context, project_id, resource, limit, user_id=None)
quota_destroy_all_by_project(context, project_id)
quota_destroy_all_by_project_and_user(context, project_id, user_id)
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(context, project_id, resource, limit, user_id=None)
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(context, project_id, user_id, resource, **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(context, image_uuid)

Create local s3 image represented by provided uuid.

s3_image_get(context, image_id)

Find local s3 image represented by the provided id.

s3_image_get_by_uuid(context, image_uuid)

Find local s3 image represented by the provided uuid.

security_group_create(*args, **kwargs)
security_group_default_rule_create(context, values)
security_group_default_rule_destroy(context, security_group_rule_default_id)
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_security_group(*args, **kwargs)
security_group_update(*args, **kwargs)
service_create(context, values)
service_destroy(context, service_id)
service_get(context, service_id, use_slave=False)
service_get_all(context, disabled=None)
service_get_all_by_binary(context, binary)
service_get_all_by_host(context, host)
service_get_all_by_topic(context, topic)
service_get_by_compute_host(context, host, use_slave=False)
service_get_by_host_and_binary(context, host, binary)
service_get_by_host_and_topic(context, host, topic)
service_update(*args, **kwargs)
task_log_begin_task(context, task_name, period_beginning, period_ending, host, task_items=None, message=None)
task_log_end_task(context, task_name, period_beginning, period_ending, host, errors, message=None)
task_log_get(context, task_name, period_beginning, period_ending, host, state=None)
task_log_get_all(context, task_name, period_beginning, period_ending, host=None, state=None)
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