Merge "allow subclasses to modify the parents model hooks"
This commit is contained in:
commit
f08d412fb4
@ -100,11 +100,16 @@ class CommonDbMixin(object):
|
|||||||
for _name, hooks in self._model_query_hooks.get(model,
|
for _name, hooks in self._model_query_hooks.get(model,
|
||||||
{}).iteritems():
|
{}).iteritems():
|
||||||
query_hook = hooks.get('query')
|
query_hook = hooks.get('query')
|
||||||
filter_hook = hooks.get('filter')
|
if isinstance(query_hook, basestring):
|
||||||
|
query_hook = getattr(self, query_hook, None)
|
||||||
if query_hook:
|
if query_hook:
|
||||||
query = query_hook(self, context, model, query)
|
query = query_hook(context, model, query)
|
||||||
|
|
||||||
|
filter_hook = hooks.get('filter')
|
||||||
|
if isinstance(filter_hook, basestring):
|
||||||
|
filter_hook = getattr(self, filter_hook, None)
|
||||||
if filter_hook:
|
if filter_hook:
|
||||||
query_filter = filter_hook(self, context, model, query_filter)
|
query_filter = filter_hook(context, model, query_filter)
|
||||||
|
|
||||||
# NOTE(salvatore-orlando): 'if query_filter' will try to evaluate the
|
# NOTE(salvatore-orlando): 'if query_filter' will try to evaluate the
|
||||||
# condition, raising an exception
|
# condition, raising an exception
|
||||||
@ -142,8 +147,11 @@ class CommonDbMixin(object):
|
|||||||
for _name, hooks in self._model_query_hooks.get(model,
|
for _name, hooks in self._model_query_hooks.get(model,
|
||||||
{}).iteritems():
|
{}).iteritems():
|
||||||
result_filter = hooks.get('result_filters', None)
|
result_filter = hooks.get('result_filters', None)
|
||||||
|
if isinstance(result_filter, basestring):
|
||||||
|
result_filter = getattr(self, result_filter, None)
|
||||||
|
|
||||||
if result_filter:
|
if result_filter:
|
||||||
query = result_filter(self, query, filters)
|
query = result_filter(query, filters)
|
||||||
return query
|
return query
|
||||||
|
|
||||||
def _get_collection_query(self, context, model, filters=None,
|
def _get_collection_query(self, context, model, filters=None,
|
||||||
|
@ -120,9 +120,9 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
|
|||||||
db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
|
db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
|
||||||
models_v2.Network,
|
models_v2.Network,
|
||||||
"external_net",
|
"external_net",
|
||||||
_network_model_hook,
|
'_network_model_hook',
|
||||||
_network_filter_hook,
|
'_network_filter_hook',
|
||||||
_network_result_filter_hook)
|
'_network_result_filter_hook')
|
||||||
|
|
||||||
def _get_router(self, context, id):
|
def _get_router(self, context, id):
|
||||||
try:
|
try:
|
||||||
|
@ -61,9 +61,9 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
|
|||||||
db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
|
db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
|
||||||
models_v2.Port,
|
models_v2.Port,
|
||||||
"portbindings_port",
|
"portbindings_port",
|
||||||
_port_model_hook,
|
'_port_model_hook',
|
||||||
None,
|
None,
|
||||||
_port_result_filter_hook)
|
'_port_result_filter_hook')
|
||||||
|
|
||||||
def _process_portbindings_create_and_update(self, context, port_data,
|
def _process_portbindings_create_and_update(self, context, port_data,
|
||||||
port):
|
port):
|
||||||
|
Loading…
Reference in New Issue
Block a user