108a598252
This patch rehomes neutron.db._model_query into neutron-lib. While our longer term goal is to use OVO rather than queries and tables, this module is provided as a stepping stone (as mentioned in release note herein). The patch also includes a few other APIs that are required for the rehome including some utils and an exception class. For more details see the spec on [1]. Also a sample consumption patch can be found on [2]. While it won't work as-is with the depends on approach (it needs to be rebased on multiple other DNMs in neutron) I tested it locally. In addition this change was tested locally with a sample vmware-nsx consumption patch [3]. [1] https://review.openstack.org/#/c/473531/ [2] https://review.openstack.org/#/c/557786/ [3] https://review.openstack.org/#/c/557788/ Change-Id: I3e4b38aa3b6460ce916091c020adedd4ed2c4d26
67 lines
2.3 KiB
ReStructuredText
67 lines
2.3 KiB
ReStructuredText
..
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
not use this file except in compliance with the License. You may obtain
|
|
a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
License for the specific language governing permissions and limitations
|
|
under the License.
|
|
|
|
|
|
Convention for heading levels in Neutron devref:
|
|
======= Heading 0 (reserved for the title in a document)
|
|
------- Heading 1
|
|
~~~~~~~ Heading 2
|
|
+++++++ Heading 3
|
|
''''''' Heading 4
|
|
(Avoid deeper levels because they do not render well.)
|
|
|
|
|
|
DB Model Query
|
|
==============
|
|
|
|
The implementation in ``neutron_lib.db.model_query`` is intended to be used as a
|
|
stepping stone for existing consumers using standard database models/tables.
|
|
Moving forward new database implementations should all use neutron's Versioned
|
|
Object approach, while existing model based implementations should begin
|
|
migrating to Versioned Objects.
|
|
|
|
|
|
Registering Hooks
|
|
-----------------
|
|
|
|
The ``neutron_lib.db.model_query.register_hook`` function allows hooks to be
|
|
registered for invocation during a respective database query.
|
|
|
|
Each hook has three components:
|
|
|
|
- "query": used to build the query expression
|
|
- "filter": used to build the filter expression
|
|
- "result_filters": used for final filtering on the query result
|
|
|
|
Query hooks take as input the query being built and return a transformed
|
|
query expression. For example::
|
|
|
|
def mymodel_query_hook(context, original_model, query):
|
|
augmented_query = ...
|
|
return augmented_query
|
|
|
|
Filter hooks take as input the filter expression being built and return
|
|
a transformed filter expression. For example::
|
|
|
|
def mymodel_filter_hook(context, original_model, filters):
|
|
refined_filters = ...
|
|
return refined_filters
|
|
|
|
Result filter hooks take as input the query expression and the filter
|
|
expression, and return a final transformed query expression. For example::
|
|
|
|
def mymodel_result_filter_hook(query, filters):
|
|
final_filters = ...
|
|
return query.filter(final_filters)
|
|
|