sql Package

sql Package

core Module

SQL backends for the various services.

Before using this module, call initialize(). This has to be done before CONF() because it sets up configuration options.

class keystone.common.sql.core.DictBase[source]

Bases: oslo_db.sqlalchemy.models.ModelBase

attributes = []
classmethod from_dict(d)[source]
to_dict(include_extra_dict=False)[source]

Returns the model’s attributes as a dictionary.

If include_extra_dict is True, ‘extra’ attributes are literally included in the resulting dictionary twice, for backwards-compatibility with a broken implementation.

class keystone.common.sql.core.JsonBlob(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

impl

alias of Text

process_bind_param(value, dialect)[source]
process_result_value(value, dialect)[source]
class keystone.common.sql.core.ModelDictMixin[source]

Bases: object

classmethod from_dict(d)[source]

Returns a model instance from a dictionary.

to_dict()[source]

Returns the model’s attributes as a dictionary.

keystone.common.sql.core.cleanup()[source]
keystone.common.sql.core.filter_limit_query(model, query, hints)[source]

Applies filtering and limit to a query.

Parameters:
  • model – table model
  • query – query to apply filters to
  • hints – contains the list of filters and limit details. This may be None, indicating that there are no filters or limits to be applied. If it’s not None, then any filters satisfied here will be removed so that the caller will know if any filters remain.
Returns:

updated query

keystone.common.sql.core.get_engine()[source]
keystone.common.sql.core.get_session(expire_on_commit=False)[source]
keystone.common.sql.core.handle_conflicts(conflict_type='object')[source]

Converts select sqlalchemy exceptions into HTTP 409 Conflict.

keystone.common.sql.core.initialize()[source]

Initialize the module.

keystone.common.sql.core.initialize_decorator(init)[source]

Ensure that the length of string field do not exceed the limit.

This decorator check the initialize arguments, to make sure the length of string field do not exceed the length limit, or raise a ‘StringLengthExceeded’ exception.

Use decorator instead of inheritance, because the metaclass will check the __tablename__, primary key columns, etc. at the class definition.

keystone.common.sql.core.transaction(*args, **kwds)[source]

Return a SQLAlchemy session in a scoped transaction.

keystone.common.sql.core.truncated(f)[source]

Ensure list truncation is detected in Driver list entity methods.

This is designed to wrap and sql Driver list_{entity} methods in order to calculate if the resultant list has been truncated. Provided a limit dict is found in the hints list, we increment the limit by one so as to ask the wrapped function for one more entity than the limit, and then once the list has been generated, we check to see if the original limit has been exceeded, in which case we truncate back to that limit and set the ‘truncated’ boolean to ‘true’ in the hints limit dict.

migration_helpers Module

keystone.common.sql.migration_helpers.add_constraints(constraints)[source]
keystone.common.sql.migration_helpers.find_migrate_repo(package=None, repo_name='migrate_repo')[source]
keystone.common.sql.migration_helpers.get_constraints_names(table, column_name)[source]
keystone.common.sql.migration_helpers.get_db_version(extension=None)[source]
keystone.common.sql.migration_helpers.get_default_domain()[source]
keystone.common.sql.migration_helpers.print_db_version(extension=None)[source]
keystone.common.sql.migration_helpers.remove_constraints(constraints)[source]
keystone.common.sql.migration_helpers.rename_tables_with_constraints(renames, constraints, engine)[source]

Renames tables with foreign key constraints.

Tables are renamed after first removing constraints. The constraints are replaced after the rename is complete.

This works on databases that don’t support renaming tables that have constraints on them (DB2).

renames is a dict, mapping {‘to_table_name’: from_table, ...}

keystone.common.sql.migration_helpers.sync_database_to_version(extension=None, version=None)[source]

Table Of Contents

This Page