rehome model_query function
This patch rehomes the model_query function into neutron_lib.db.utils. Also see: https://bugs.launchpad.net/neutron/+bug/1815827 Change-Id: I5ad2937af88a2f7a4e526c4d75ee18b06f50562d
This commit is contained in:
parent
3b1793eb5f
commit
011228b9ca
@ -167,3 +167,21 @@ def model_query_scope_is_project(context, model):
|
||||
# query will be scoped to a single project_id
|
||||
return ((not context.is_admin and hasattr(model, 'project_id')) and
|
||||
(not context.is_advsvc and hasattr(model, 'project_id')))
|
||||
|
||||
|
||||
def model_query(context, model):
|
||||
"""Query the context for the said model.
|
||||
|
||||
:param context: The context to use for the query.
|
||||
:param model: The model to query for.
|
||||
:returns: A query from the said context for the said model.
|
||||
"""
|
||||
query = context.session.query(model)
|
||||
# define basic filter condition for model query
|
||||
query_filter = None
|
||||
if model_query_scope_is_project(context, model):
|
||||
query_filter = (model.tenant_id == context.tenant_id)
|
||||
|
||||
if query_filter is not None:
|
||||
query = query.filter(query_filter)
|
||||
return query
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- The ``model_query`` function is now available in ``neutron_lib.db.utils``.
|
Loading…
x
Reference in New Issue
Block a user