models: move AllowedAddressPair model under neutron/db/models
This patch moves the module into the canonical place. It does it in backwards compatible way, by leaving the model available under the old location, only emitting a deprecation warning on access from there. In the future, the old module will be completely cleaned up. This patch also makes head.py file that is used to import and register all models in the tree to import everything from under neutron.db.models without explicitly naming each module. In that way, we can avoid the need to import each new module with models as long as it's located in the designated place. The file is a well known abuser in terms of git conflicts, and it's better to avoid manual work. Change-Id: I084031e6b3c8d9113cc6ee6e3967f0e1edaee0b5 Partial-Bug: #1597913
This commit is contained in:
parent
a92647300d
commit
7c0f189309
|
@ -10,21 +10,13 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
import sys
|
||||
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
from neutron.common import _deprecate
|
||||
from neutron.db.models import allowed_address_pair as aap_models
|
||||
|
||||
|
||||
class AllowedAddressPair(model_base.BASEV2):
|
||||
port_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
mac_address = sa.Column(sa.String(32), nullable=False, primary_key=True)
|
||||
ip_address = sa.Column(sa.String(64), nullable=False, primary_key=True)
|
||||
|
||||
port = orm.relationship(
|
||||
models_v2.Port,
|
||||
backref=orm.backref("allowed_address_pairs",
|
||||
lazy="joined", cascade="delete"))
|
||||
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
|
||||
_OLD_REF = sys.modules[__name__]
|
||||
sys.modules[__name__] = _deprecate._DeprecateSubset(globals(), aap_models)
|
||||
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
|
||||
|
|
|
@ -30,11 +30,11 @@ from neutron.callbacks import registry
|
|||
from neutron.callbacks import resources
|
||||
from neutron.common import constants as l3_const
|
||||
from neutron.common import utils as n_utils
|
||||
from neutron.db.allowed_address_pairs import models as addr_pair_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import l3_agentschedulers_db as l3_sched_db
|
||||
from neutron.db import l3_attrs_db
|
||||
from neutron.db import l3_db
|
||||
from neutron.db.models import allowed_address_pair as aap_models
|
||||
from neutron.db import models_v2
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import portbindings
|
||||
|
@ -213,8 +213,8 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
|||
"""Return all active ports associated with the allowed_addr_pair ip."""
|
||||
query = context.session.query(
|
||||
models_v2.Port).filter(
|
||||
models_v2.Port.id == addr_pair_db.AllowedAddressPair.port_id,
|
||||
addr_pair_db.AllowedAddressPair.ip_address == fixed_ip,
|
||||
models_v2.Port.id == aap_models.AllowedAddressPair.port_id,
|
||||
aap_models.AllowedAddressPair.ip_address == fixed_ip,
|
||||
models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.admin_state_up == True) # noqa
|
||||
return query.all()
|
||||
|
|
|
@ -21,14 +21,17 @@ Based on this comparison database can be healed with healing migration.
|
|||
|
||||
"""
|
||||
|
||||
# TODO(ihrachys): move the module under neutron/tests
|
||||
|
||||
import os.path
|
||||
|
||||
from neutron.db import address_scope_db # noqa
|
||||
from neutron.db import agents_db # noqa
|
||||
from neutron.db import agentschedulers_db # noqa
|
||||
from neutron.db.allowed_address_pairs import models # noqa
|
||||
from neutron.db import dns_db # noqa
|
||||
from neutron.db import dvr_mac_db # noqa
|
||||
from neutron.db import external_net_db # noqa
|
||||
from neutron.db.extra_dhcp_opt import models # noqa
|
||||
from neutron.db.extra_dhcp_opt import models as edo_models # noqa
|
||||
from neutron.db import extraroute_db # noqa
|
||||
from neutron.db import flavors_db # noqa
|
||||
from neutron.db import l3_agentschedulers_db # noqa
|
||||
|
@ -39,13 +42,13 @@ from neutron.db import l3_gwmode_db # noqa
|
|||
from neutron.db import l3_hamode_db # noqa
|
||||
from neutron.db.metering import metering_db # noqa
|
||||
from neutron.db import model_base
|
||||
from neutron.db.models import securitygroup # noqa
|
||||
from neutron.db import models
|
||||
from neutron.db import models_v2 # noqa
|
||||
from neutron.db.port_security import models # 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 # noqa
|
||||
from neutron.db.quota import models as quota_models # noqa
|
||||
from neutron.db import rbac_db_models # noqa
|
||||
from neutron.db import segments_db # noqa
|
||||
from neutron.db import servicetype_db # noqa
|
||||
|
@ -56,10 +59,14 @@ from neutron.plugins.ml2.drivers import type_geneve # noqa
|
|||
from neutron.plugins.ml2.drivers import type_gre # noqa
|
||||
from neutron.plugins.ml2.drivers import type_vlan # noqa
|
||||
from neutron.plugins.ml2.drivers import type_vxlan # noqa
|
||||
from neutron.plugins.ml2 import models # noqa
|
||||
from neutron.services.auto_allocate import models # noqa
|
||||
from neutron.plugins.ml2 import models as ml2_models # noqa
|
||||
from neutron.services.auto_allocate import models as aa_models # noqa
|
||||
from neutron.services.segments import db # noqa
|
||||
from neutron.services.trunk import models # noqa
|
||||
from neutron.services.trunk import models as trunk_models # noqa
|
||||
from neutron.tests import tools
|
||||
|
||||
|
||||
tools.import_modules_recursively(os.path.dirname(models.__file__))
|
||||
|
||||
|
||||
def get_metadata():
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# 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.
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
|
||||
|
||||
class AllowedAddressPair(model_base.BASEV2):
|
||||
port_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
mac_address = sa.Column(sa.String(32), nullable=False, primary_key=True)
|
||||
ip_address = sa.Column(sa.String(64), nullable=False, primary_key=True)
|
||||
|
||||
port = orm.relationship(
|
||||
models_v2.Port,
|
||||
backref=orm.backref("allowed_address_pairs",
|
||||
lazy="joined", cascade="delete"))
|
|
@ -21,7 +21,7 @@ from sqlalchemy.orm import exc
|
|||
from neutron._i18n import _, _LW
|
||||
from neutron.common import ipv6_utils as ipv6
|
||||
from neutron.common import utils
|
||||
from neutron.db.allowed_address_pairs import models as addr_pair
|
||||
from neutron.db.models import allowed_address_pair as aap_models
|
||||
from neutron.db.models import securitygroup as sg_models
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import securitygroups_db as sg_db
|
||||
|
@ -271,14 +271,14 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin):
|
|||
# table instead of via the Port table skip an unnecessary intermediary
|
||||
query = context.session.query(sg_binding_sgid,
|
||||
models_v2.IPAllocation.ip_address,
|
||||
addr_pair.AllowedAddressPair.ip_address)
|
||||
aap_models.AllowedAddressPair.ip_address)
|
||||
query = query.join(models_v2.IPAllocation,
|
||||
ip_port == sg_binding_port)
|
||||
# Outerjoin because address pairs may be null and we still want the
|
||||
# IP for the port.
|
||||
query = query.outerjoin(
|
||||
addr_pair.AllowedAddressPair,
|
||||
sg_binding_port == addr_pair.AllowedAddressPair.port_id)
|
||||
aap_models.AllowedAddressPair,
|
||||
sg_binding_port == aap_models.AllowedAddressPair.port_id)
|
||||
query = query.filter(sg_binding_sgid.in_(remote_group_ids))
|
||||
# Each allowed address pair IP record for a port beyond the 1st
|
||||
# will have a duplicate regular IP in the query response since
|
||||
|
|
|
@ -14,7 +14,7 @@ from oslo_versionedobjects import base as obj_base
|
|||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.common import utils
|
||||
from neutron.db.allowed_address_pairs import models
|
||||
from neutron.db.models import allowed_address_pair as models
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
|
Loading…
Reference in New Issue