Relocate Flat Allocation DB model
Since there would be a circular import issue once we try to implement an object relying on the model, and adopt it in tree for database accessing code, this patch prepares the ground for this work by moving the model out of database accessing modules into neutron/db/models. Change-Id: I7876d28d35c5c4b9167520733e1a1b08dabc6951 Partial-Bug: #1597913
This commit is contained in:
parent
665fd24623
commit
a2e915977a
|
@ -52,7 +52,6 @@ from neutron.db import segments_db # noqa
|
|||
from neutron.db import servicetype_db # noqa
|
||||
from neutron.db import tag_db # noqa
|
||||
from neutron.ipam.drivers.neutrondb_ipam import db_models # noqa
|
||||
from neutron.plugins.ml2.drivers import type_flat # noqa
|
||||
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
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# 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 neutron.db import model_base
|
||||
|
||||
|
||||
class FlatAllocation(model_base.BASEV2):
|
||||
"""Represent persistent allocation state of a physical network.
|
||||
|
||||
If a record exists for a physical network, then that physical
|
||||
network has been allocated as a flat network.
|
||||
"""
|
||||
|
||||
__tablename__ = 'ml2_flat_allocations'
|
||||
|
||||
physical_network = sa.Column(sa.String(64), nullable=False,
|
||||
primary_key=True)
|
|
@ -13,16 +13,18 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from neutron_lib import exceptions as exc
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron._i18n import _, _LI, _LW
|
||||
from neutron.common import _deprecate
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.db import model_base
|
||||
from neutron.db.models.plugins.ml2 import flatallocation as type_flat_model
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron.plugins.ml2.drivers import helpers
|
||||
|
@ -41,19 +43,6 @@ flat_opts = [
|
|||
cfg.CONF.register_opts(flat_opts, "ml2_type_flat")
|
||||
|
||||
|
||||
class FlatAllocation(model_base.BASEV2):
|
||||
"""Represent persistent allocation state of a physical network.
|
||||
|
||||
If a record exists for a physical network, then that physical
|
||||
network has been allocated as a flat network.
|
||||
"""
|
||||
|
||||
__tablename__ = 'ml2_flat_allocations'
|
||||
|
||||
physical_network = sa.Column(sa.String(64), nullable=False,
|
||||
primary_key=True)
|
||||
|
||||
|
||||
class FlatTypeDriver(helpers.BaseTypeDriver):
|
||||
"""Manage state for flat networks with ML2.
|
||||
|
||||
|
@ -114,7 +103,8 @@ class FlatTypeDriver(helpers.BaseTypeDriver):
|
|||
try:
|
||||
LOG.debug("Reserving flat network on physical "
|
||||
"network %s", physical_network)
|
||||
alloc = FlatAllocation(physical_network=physical_network)
|
||||
alloc = type_flat_model.FlatAllocation(
|
||||
physical_network=physical_network)
|
||||
alloc.save(session)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise n_exc.FlatNetworkInUse(
|
||||
|
@ -129,7 +119,7 @@ class FlatTypeDriver(helpers.BaseTypeDriver):
|
|||
def release_segment(self, session, segment):
|
||||
physical_network = segment[api.PHYSICAL_NETWORK]
|
||||
with session.begin(subtransactions=True):
|
||||
count = (session.query(FlatAllocation).
|
||||
count = (session.query(type_flat_model.FlatAllocation).
|
||||
filter_by(physical_network=physical_network).
|
||||
delete())
|
||||
if count:
|
||||
|
@ -147,3 +137,9 @@ class FlatTypeDriver(helpers.BaseTypeDriver):
|
|||
if physical_network in self.physnet_mtus:
|
||||
mtu.append(int(self.physnet_mtus[physical_network]))
|
||||
return min(mtu) if mtu else 0
|
||||
|
||||
|
||||
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
|
||||
_OLD_REF = sys.modules[__name__]
|
||||
sys.modules[__name__] = _deprecate._DeprecateSubset(globals(), type_flat_model)
|
||||
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
|
||||
|
|
|
@ -17,6 +17,7 @@ from neutron_lib import exceptions as exc
|
|||
|
||||
from neutron.common import exceptions as n_exc
|
||||
import neutron.db.api as db
|
||||
from neutron.db.models.plugins.ml2 import flatallocation as type_flat_model
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2 import config
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
|
@ -39,7 +40,7 @@ class FlatTypeTest(testlib_api.SqlTestCase):
|
|||
self.driver.physnet_mtus = []
|
||||
|
||||
def _get_allocation(self, session, segment):
|
||||
return session.query(type_flat.FlatAllocation).filter_by(
|
||||
return session.query(type_flat_model.FlatAllocation).filter_by(
|
||||
physical_network=segment[api.PHYSICAL_NETWORK]).first()
|
||||
|
||||
def test_is_partial_segment(self):
|
||||
|
|
Loading…
Reference in New Issue