Get rid of ml2 port model hook join

The binding is already joined to the port via a backref relationship
so we can just utilize that rather than join to the table an additional
time.

Partial-Bug: #1649317
Change-Id: I267a808b411f44b2128955dc93bd8da34d1fac91
(cherry picked from commit 3ea5f7ce56)
This commit is contained in:
Kevin Benton 2016-12-13 18:07:42 -08:00 committed by Daniel Alvarez
parent e334c042a4
commit 5935b617fb
1 changed files with 3 additions and 8 deletions

View File

@ -608,22 +608,17 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
# registration of hooks in portbindings_db.py used by other
# plugins.
def _ml2_port_model_hook(self, context, original_model, query):
query = query.outerjoin(models.PortBinding,
(original_model.id ==
models.PortBinding.port_id))
return query
def _ml2_port_result_filter_hook(self, query, filters):
values = filters and filters.get(portbindings.HOST_ID, [])
if not values:
return query
return query.filter(models.PortBinding.host.in_(values))
bind_criteria = models.PortBinding.host.in_(values)
return query.filter(models_v2.Port.port_binding.has(bind_criteria))
db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
models_v2.Port,
"ml2_port_bindings",
'_ml2_port_model_hook',
None,
None,
'_ml2_port_result_filter_hook')