Relocate PortBindingPort DB Model

This patch moves PortBindingPort model under neutron/db/models for
consistency.There are no plans to implement an OVO object for the model
at this point in time. Actually, the model should probably eventually
go away from Neutron tree since it's not used by reference plugin,
and is just a remnant from the times when the neutron tree contained
lots of plugins, some of which were using the model.

Change-Id: I5728fea38816b7e500eaa836d5c5dadef51457f7
Partial-Bug: #1597913
This commit is contained in:
Nakul Dahiwade 2016-08-15 22:01:50 +00:00
parent e8b0d77f0f
commit 74229030b8
3 changed files with 50 additions and 23 deletions

View File

@ -44,7 +44,6 @@ from neutron.db.metering import metering_db # noqa
from neutron.db import models
from neutron.db import models_v2 # noqa
from neutron.db.port_security import models as ps_models # noqa
from neutron.db import portbindings_db # noqa
from neutron.db import provisioning_blocks # noqa
from neutron.db.qos import models as qos_models # noqa
from neutron.db.quota import models as quota_models # noqa

View File

@ -0,0 +1,32 @@
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
# 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.
from neutron_lib.db import model_base
import sqlalchemy as sa
from sqlalchemy import orm
from neutron.db import models_v2
class PortBindingPort(model_base.BASEV2):
port_id = sa.Column(sa.String(36),
sa.ForeignKey('ports.id', ondelete="CASCADE"),
primary_key=True)
host = sa.Column(sa.String(255), nullable=False)
port = orm.relationship(
models_v2.Port,
backref=orm.backref("portbinding",
lazy='joined', uselist=False,
cascade='delete'))

View File

@ -14,43 +14,33 @@
# under the License.
from neutron_lib.api import validators
from neutron_lib.db import model_base
import sqlalchemy as sa
from sqlalchemy import orm
from neutron.api.v2 import attributes
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db.models import portbinding as pmodels
from neutron.db import models_v2
from neutron.db import portbindings_base
from neutron.extensions import portbindings
class PortBindingPort(model_base.BASEV2):
port_id = sa.Column(sa.String(36),
sa.ForeignKey('ports.id', ondelete="CASCADE"),
primary_key=True)
host = sa.Column(sa.String(255), nullable=False)
port = orm.relationship(
models_v2.Port,
backref=orm.backref("portbinding",
lazy='joined', uselist=False,
cascade='delete'))
_deprecate._moved_global('PortBindingPort', new_module=pmodels)
class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
extra_binding_dict = None
def _port_model_hook(self, context, original_model, query):
query = query.outerjoin(PortBindingPort,
(original_model.id ==
PortBindingPort.port_id))
query = query.outerjoin(
pmodels.PortBindingPort,
(original_model.id == pmodels.PortBindingPort.port_id))
return query
def _port_result_filter_hook(self, query, filters):
values = filters and filters.get(portbindings.HOST_ID, [])
if not values:
return query
query = query.filter(PortBindingPort.host.in_(values))
query = query.filter(pmodels.PortBindingPort.host.in_(values))
return query
db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(
@ -80,11 +70,11 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
host_set = validators.is_attr_set(host)
with context.session.begin(subtransactions=True):
bind_port = context.session.query(
PortBindingPort).filter_by(port_id=port['id']).first()
pmodels.PortBindingPort).filter_by(port_id=port['id']).first()
if host_set:
if not bind_port:
context.session.add(PortBindingPort(port_id=port['id'],
host=host))
context.session.add(
pmodels.PortBindingPort(port_id=port['id'], host=host))
else:
bind_port.host = host
else:
@ -93,8 +83,11 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
def get_port_host(self, context, port_id):
with context.session.begin(subtransactions=True):
bind_port = context.session.query(
PortBindingPort).filter_by(port_id=port_id).first()
bind_port = (
context.session.query(pmodels.PortBindingPort).
filter_by(port_id=port_id).
first()
)
return bind_port.host if bind_port else None
def _extend_port_dict_binding_host(self, port_res, host):
@ -116,3 +109,6 @@ def _extend_port_dict_binding(plugin, port_res, port_db):
# Register dict extend functions for ports
db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
attributes.PORTS, [_extend_port_dict_binding])
_deprecate._MovedGlobals()