Merge "db: Copy docs from 'nova.db.*' to 'nova.db.sqlalchemy.*'"

This commit is contained in:
Zuul
2021-07-01 20:15:55 +00:00
committed by Gerrit Code Review
3 changed files with 620 additions and 181 deletions
+185 -80
View File
@@ -75,7 +75,10 @@ def not_equal(*values):
def create_context_manager(connection):
"""Return a context manager for a cell database connection."""
"""Create a database context manager object for a cell database connection.
:param connection: The database connection string
"""
return IMPL.create_context_manager(connection=connection)
@@ -87,6 +90,9 @@ def select_db_reader_mode(f):
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.
"""
return IMPL.select_db_reader_mode(f)
@@ -176,8 +182,7 @@ def service_create(context, values):
def service_update(context, service_id, values):
"""Set the given properties on a service and update it.
Raises NotFound if service does not exist.
:raises: NotFound if service does not exist.
"""
return IMPL.service_update(context, service_id, values)
@@ -192,8 +197,8 @@ def compute_node_get(context, compute_id):
:param compute_id: ID of the compute node
:returns: Dictionary-like object containing properties of the compute node
Raises ComputeHostNotFound if compute node with the given ID doesn't exist.
:raises: ComputeHostNotFound if compute node with the given ID doesn't
exist.
"""
return IMPL.compute_node_get(context, compute_id)
@@ -207,8 +212,8 @@ def compute_node_get_model(context, compute_id):
:param compute_id: ID of the compute node
:returns: Sqlalchemy model object containing properties of the compute node
Raises ComputeHostNotFound if compute node with the given ID doesn't exist.
:raises: ComputeHostNotFound if compute node with the given ID doesn't
exist.
"""
return IMPL.compute_node_get_model(context, compute_id)
@@ -220,10 +225,8 @@ def compute_nodes_get_by_service_id(context, service_id):
:param service_id: ID of the associated service
:returns: List of dictionary-like objects, each containing properties of
the compute node, including its corresponding service and
statistics
Raises ServiceNotFound if service with the given ID doesn't exist.
the compute node, including its corresponding service and statistics
:raises: ServiceNotFound if service with the given ID doesn't exist.
"""
return IMPL.compute_nodes_get_by_service_id(context, service_id)
@@ -236,9 +239,8 @@ def compute_node_get_by_host_and_nodename(context, host, nodename):
:param nodename: Name of the node
:returns: Dictionary-like object containing properties of the compute node,
including its statistics
Raises ComputeHostNotFound if host with the given name doesn't exist.
including its statistics
:raises: ComputeHostNotFound if host with the given name doesn't exist.
"""
return IMPL.compute_node_get_by_host_and_nodename(context, host, nodename)
@@ -250,16 +252,15 @@ def compute_node_get_by_nodename(context, hypervisor_hostname):
:param hypervisor_hostname: Name of the node
:returns: Dictionary-like object containing properties of the compute node,
including its statistics
Raises ComputeHostNotFound if hypervisor_hostname with the given name
doesn't exist.
including its statistics
:raises: ComputeHostNotFound if hypervisor_hostname with the given name
doesn't exist.
"""
return IMPL.compute_node_get_by_nodename(context, hypervisor_hostname)
def compute_node_get_all(context):
"""Get all computeNodes.
"""Get all compute nodes.
:param context: The security context
@@ -269,11 +270,10 @@ def compute_node_get_all(context):
def compute_node_get_all_mapped_less_than(context, mapped_less_than):
"""Get all ComputeNode objects with specific mapped values.
"""Get all compute nodes with specific mapped values.
:param context: The security context
:param mapped_less_than: Get compute nodes with mapped less than this
value
:param mapped_less_than: Get compute nodes with mapped less than this value
:returns: List of dictionaries each containing compute node properties
"""
@@ -282,11 +282,12 @@ def compute_node_get_all_mapped_less_than(context, mapped_less_than):
def compute_node_get_all_by_pagination(context, limit=None, marker=None):
"""Get compute nodes by pagination.
"""Get all compute nodes by pagination.
:param context: The security context
:param limit: Maximum number of items to return
:param marker: The last item of the previous page, the next results after
this value will be returned
this value will be returned
:returns: List of dictionaries each containing compute node properties
"""
@@ -295,7 +296,7 @@ def compute_node_get_all_by_pagination(context, limit=None, marker=None):
def compute_node_get_all_by_host(context, host):
"""Get compute nodes by host name
"""Get all compute nodes by host name.
:param context: The security context (admin)
:param host: Name of the host
@@ -306,13 +307,13 @@ def compute_node_get_all_by_host(context, host):
def compute_node_search_by_hypervisor(context, hypervisor_match):
"""Get compute nodes by hypervisor hostname.
"""Get all compute nodes by hypervisor hostname.
:param context: The security context
:param hypervisor_match: The hypervisor hostname
:returns: List of dictionary-like objects each containing compute node
properties
properties
"""
return IMPL.compute_node_search_by_hypervisor(context, hypervisor_match)
@@ -324,7 +325,7 @@ def compute_node_create(context, values):
:param values: Dictionary containing compute node properties
:returns: Dictionary-like object containing the properties of the created
node, including its corresponding service and statistics
node, including its corresponding service and statistics
"""
return IMPL.compute_node_create(context, values)
@@ -337,9 +338,9 @@ def compute_node_update(context, compute_id, values):
:param values: Dictionary containing compute node properties to be updated
:returns: Dictionary-like object containing the properties of the updated
compute node, including its corresponding service and statistics
Raises ComputeHostNotFound if compute node with the given ID doesn't exist.
compute node, including its corresponding service and statistics
:raises: ComputeHostNotFound if compute node with the given ID doesn't
exist.
"""
return IMPL.compute_node_update(context, compute_id, values)
@@ -349,8 +350,8 @@ def compute_node_delete(context, compute_id):
:param context: The security context
:param compute_id: ID of the compute node
Raises ComputeHostNotFound if compute node with the given ID doesn't exist.
:raises: ComputeHostNotFound if compute node with the given ID doesn't
exist.
"""
return IMPL.compute_node_delete(context, compute_id)
@@ -361,7 +362,7 @@ def compute_node_statistics(context):
:param context: The security context
:returns: Dictionary containing compute node characteristics summed up
over all the compute nodes, e.g. 'vcpus', 'free_ram_mb' etc.
over all the compute nodes, e.g. 'vcpus', 'free_ram_mb' etc.
"""
return IMPL.compute_node_statistics(context)
@@ -405,24 +406,24 @@ def migration_create(context, values):
def migration_get(context, migration_id):
"""Finds a migration by the id."""
"""Finds a migration by the ID."""
return IMPL.migration_get(context, migration_id)
def migration_get_by_uuid(context, migration_uuid):
"""Finds a migration by the migration uuid."""
"""Finds a migration by the migration UUID."""
return IMPL.migration_get_by_uuid(context, migration_uuid)
def migration_get_by_id_and_instance(context, migration_id, instance_uuid):
"""Finds a migration by the migration id and the instance uuid."""
"""Finds a migration by the migration ID and the instance UUID."""
return IMPL.migration_get_by_id_and_instance(context,
migration_id,
instance_uuid)
def migration_get_by_instance_and_status(context, instance_uuid, status):
"""Finds a migration by the instance uuid its migrating."""
"""Finds a migration by the instance UUID it's migrating."""
return IMPL.migration_get_by_instance_and_status(context, instance_uuid,
status)
@@ -464,7 +465,10 @@ def migration_get_by_sort_filters(context, sort_keys, sort_dirs, values):
Return the first migration (uuid) of the set where each column value
is greater than or equal to the matching one in @values, for each key
in @sort_keys.
in @sort_keys. This is used to try to find a marker migration when we don't
have a marker uuid.
:returns: A UUID of the migration that matched.
"""
return IMPL.migration_get_by_sort_filters(context, sort_keys, sort_dirs,
values)
@@ -472,7 +476,7 @@ def migration_get_by_sort_filters(context, sort_keys, sort_dirs, values):
def migration_get_in_progress_and_error_by_host_and_node(context, host, node):
"""Finds all in progress migrations and error migrations for the given
host + node.
host and node.
"""
return IMPL.migration_get_in_progress_and_error_by_host_and_node(
context, host, node)
@@ -482,7 +486,10 @@ def migration_get_in_progress_and_error_by_host_and_node(context, host, node):
def virtual_interface_create(context, values):
"""Create a virtual interface record in the database."""
"""Create a new virtual interface record.
:param values: Dict containing column values.
"""
return IMPL.virtual_interface_create(context, values)
@@ -492,45 +499,66 @@ def virtual_interface_update(context, address, values):
def virtual_interface_get(context, vif_id):
"""Gets a virtual interface from the table."""
"""Get a virtual interface by ID.
:param vif_id: ID of the virtual interface.
"""
return IMPL.virtual_interface_get(context, vif_id)
def virtual_interface_get_by_address(context, address):
"""Gets a virtual interface from the table filtering on address."""
"""Get a virtual interface by address.
:param address: The address of the interface you're looking to get.
"""
return IMPL.virtual_interface_get_by_address(context, address)
def virtual_interface_get_by_uuid(context, vif_uuid):
"""Gets a virtual interface from the table filtering on vif uuid."""
"""Get a virtual interface by UUID.
:param vif_uuid: The uuid of the interface you're looking to get
"""
return IMPL.virtual_interface_get_by_uuid(context, vif_uuid)
def virtual_interface_get_by_instance(context, instance_id):
"""Gets all virtual_interfaces for instance."""
"""Gets all virtual interfaces for instance.
:param instance_uuid: UUID of the instance to filter on.
"""
return IMPL.virtual_interface_get_by_instance(context, instance_id)
def virtual_interface_get_by_instance_and_network(context, instance_id,
network_id):
"""Gets all virtual interfaces for instance."""
def virtual_interface_get_by_instance_and_network(
context, instance_id, network_id,
):
"""Get all virtual interface for instance that's associated with
network.
"""
return IMPL.virtual_interface_get_by_instance_and_network(context,
instance_id,
network_id)
def virtual_interface_delete_by_instance(context, instance_id):
"""Delete virtual interface records associated with instance."""
"""Delete virtual interface records associated with instance.
:param instance_uuid: UUID of the instance to filter on.
"""
return IMPL.virtual_interface_delete_by_instance(context, instance_id)
def virtual_interface_delete(context, id):
"""Delete virtual interface by id."""
"""Delete a virtual interface records.
:param id: ID of the interface.
"""
return IMPL.virtual_interface_delete(context, id)
def virtual_interface_get_all(context):
"""Gets all virtual interfaces from the table."""
"""Get all virtual interface records."""
return IMPL.virtual_interface_get_all(context)
@@ -538,7 +566,11 @@ def virtual_interface_get_all(context):
def instance_create(context, values):
"""Create an instance from the values dictionary."""
"""Create an instance from the values dictionary.
:param context: Request context object
:param values: Dict containing column values.
"""
return IMPL.instance_create(context, values)
@@ -550,7 +582,7 @@ def instance_destroy(context, instance_uuid, constraint=None,
:param instance_uuid: uuid of the instance to delete
:param constraint: a constraint object
:param hard_delete: when set to True, removes all records related to the
instance
instance
"""
return IMPL.instance_destroy(context, instance_uuid,
constraint=constraint,
@@ -574,8 +606,11 @@ def instance_get_all(context, columns_to_join=None):
def instance_get_all_uuids_by_hosts(context, hosts):
"""Get a dict, keyed by hostname, of a list of instance uuids on one or
more hosts.
"""Get a dict, keyed by hostname, of a list of the instance UUIDs on the
host for each supplied hostname, not Instance model objects.
The dict is a defaultdict of list, thus inspecting the dict for a host not
in the dict will return an empty list not a KeyError.
"""
return IMPL.instance_get_all_uuids_by_hosts(context, hosts)
@@ -583,7 +618,10 @@ def instance_get_all_uuids_by_hosts(context, hosts):
def instance_get_all_by_filters(context, filters, sort_key='created_at',
sort_dir='desc', limit=None, marker=None,
columns_to_join=None):
"""Get all instances that match all filters."""
"""Get all instances matching all filters sorted by the primary key.
See instance_get_all_by_filters_sort for more information.
"""
# Note: This function exists for backwards compatibility since calls to
# the instance layer coming in over RPC may specify the single sort
# key/direction values; in this case, this function is invoked instead
@@ -597,9 +635,67 @@ def instance_get_all_by_filters(context, filters, sort_key='created_at',
def instance_get_all_by_filters_sort(context, filters, limit=None,
marker=None, columns_to_join=None,
sort_keys=None, sort_dirs=None):
"""Get all instances that match all filters sorted by multiple keys.
"""Get all instances that match all filters sorted by the given keys.
sort_keys and sort_dirs must be a list of strings.
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', 'locked', 'hidden']
Hidden instances will *not* be returned by default, unless there's a
filter that says otherwise.
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
| 'changes-before' - only return instances updated before
| '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: T1 AND T2
`tags-any` -- One or more strings that will be used to filter results in
an OR expression: T1 OR T2
`not-tags` -- One or more strings that will be used to filter results in
an NOT AND expression: NOT (T1 AND T2)
`not-tags-any` -- One or more strings that will be used to filter results
in an NOT OR expression: NOT (T1 OR T2)
Tags should be represented as list::
| filters = {
| 'tags': [some-tag, some-another-tag],
| 'tags-any: [some-any-tag, some-another-any-tag],
| 'not-tags: [some-not-tag, some-another-not-tag],
| 'not-tags-any: [some-not-any-tag, some-another-not-any-tag]
| }
"""
return IMPL.instance_get_all_by_filters_sort(
context, filters, limit=limit, marker=marker,
@@ -608,11 +704,13 @@ def instance_get_all_by_filters_sort(context, filters, limit=None,
def instance_get_by_sort_filters(context, sort_keys, sort_dirs, values):
"""Get the uuid of the first instance in a sort order.
"""Get the UUID of the first instance in a sort order.
Return the first instance (uuid) of the set where each column value
is greater than or equal to the matching one in @values, for each key
in @sort_keys.
Attempt to get a single instance based on a combination of sort
keys, directions and filter values. This is used to try to find a
marker instance when we don't have a marker uuid.
:returns: The UUID of the instance that matched, if any.
"""
return IMPL.instance_get_by_sort_filters(context, sort_keys, sort_dirs,
values)
@@ -659,8 +757,7 @@ def instance_get_all_hung_in_rebooting(context, reboot_window):
def instance_update(context, instance_uuid, values, expected=None):
"""Set the given properties on an instance and update it.
Raises NotFound if instance does not exist.
:raises: NotFound if instance does not exist.
"""
return IMPL.instance_update(context, instance_uuid, values,
expected=expected)
@@ -668,17 +765,20 @@ def instance_update(context, instance_uuid, values, expected=None):
def instance_update_and_get_original(context, instance_uuid, values,
columns_to_join=None, expected=None):
"""Set the given properties on an instance and update it. Return
a shallow copy of the original instance reference, as well as the
"""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.
:param context: = request context object
:param instance_uuid: = instance id or uuid
:param 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.
:param context: request context object
:param instance_uuid: instance uuid
:param values: dict containing column values
:returns: a tuple of the form (old_instance_ref, new_instance_ref)
Raises NotFound if instance does not exist.
:raises: NotFound if instance does not exist.
"""
rv = IMPL.instance_update_and_get_original(context, instance_uuid, values,
columns_to_join=columns_to_join,
@@ -732,7 +832,7 @@ def instance_info_cache_delete(context, instance_uuid):
def instance_extra_get_by_instance_uuid(context, instance_uuid, columns=None):
"""Get the instance extra record
:param instance_uuid: = uuid of the instance tied to the topology record
:param instance_uuid: UUID of the instance tied to the topology record
:param columns: A list of the columns to load, or None for 'all of them'
"""
return IMPL.instance_extra_get_by_instance_uuid(
@@ -742,7 +842,7 @@ def instance_extra_get_by_instance_uuid(context, instance_uuid, columns=None):
def instance_extra_update_by_uuid(context, instance_uuid, updates):
"""Update the instance extra record by instance uuid
:param instance_uuid: = uuid of the instance tied to the record
:param instance_uuid: UUID of the instance tied to the record
:param updates: A dict of updates to apply
"""
return IMPL.instance_extra_update_by_uuid(context, instance_uuid,
@@ -804,7 +904,7 @@ def quota_get_all_by_project(context, project_id):
def quota_get_per_project_resources():
"""Retrieve the names of resources whose quotas are calculated on a
per-project rather than a per-user basis.
per-project rather than a per-user basis.
"""
return IMPL.quota_get_per_project_resources()
@@ -938,7 +1038,7 @@ def security_group_get_all(context):
def security_group_get(context, security_group_id, columns_to_join=None):
"""Get security group by its id."""
"""Get security group by its ID."""
return IMPL.security_group_get(context, security_group_id,
columns_to_join)
@@ -1100,7 +1200,7 @@ def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes,
update_totals=False):
"""Update cached volume usage for a volume
Creates new record if needed.
Creates new record if needed.
"""
return IMPL.vol_usage_update(context, id, rd_req, rd_bytes, wr_req,
wr_bytes, instance_id, project_id, user_id,
@@ -1130,13 +1230,18 @@ def s3_image_create(context, image_uuid):
def instance_fault_create(context, values):
"""Create a new Instance Fault."""
"""Create a new instance fault."""
return IMPL.instance_fault_create(context, values)
def instance_fault_get_by_instance_uuids(context, instance_uuids,
latest=False):
"""Get all instance faults for the provided instance_uuids."""
"""Get all instance faults for the provided instance_uuids.
:param instance_uuids: List of UUIDs of instances to grab faults for
:param latest: Optional boolean indicating we should only return the latest
fault for the instance
"""
return IMPL.instance_fault_get_by_instance_uuids(context, instance_uuids,
latest=latest)
@@ -1188,12 +1293,12 @@ def action_event_get_by_id(context, action_id, event_id):
def get_instance_uuid_by_ec2_id(context, ec2_id):
"""Get uuid through ec2 id from instance_id_mappings table."""
"""Get UUID through EC2 ID from instance_id_mappings table."""
return IMPL.get_instance_uuid_by_ec2_id(context, ec2_id)
def ec2_instance_create(context, instance_uuid, id=None):
"""Create the ec2 id to instance uuid mapping on demand."""
"""Create the EC2 ID to instance UUID mapping on demand."""
return IMPL.ec2_instance_create(context, instance_uuid, id)
+432 -101
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -42,6 +42,7 @@ def get_engine(database='main', context=None):
def db_sync(version=None, database='main', context=None):
"""Migrate the database to `version` or the most recent version."""
if version is not None:
try:
version = int(version)
@@ -59,6 +60,7 @@ def db_sync(version=None, database='main', context=None):
def db_version(database='main', context=None):
"""Display the current database version."""
repository = _find_migrate_repo(database)
# NOTE(mdbooth): This is a crude workaround for races in _db_version. The 2
@@ -117,6 +119,7 @@ def _db_version(repository, database, context):
def db_initial_version(database='main'):
"""The starting version for the database."""
return INIT_VERSION[database]