Merge "Relocate VlanAllocation DB model"
This commit is contained in:
commit
ec158688f4
|
@ -51,7 +51,6 @@ from neutron.db import servicetype_db # noqa
|
||||||
from neutron.db import tag_db # noqa
|
from neutron.db import tag_db # noqa
|
||||||
from neutron.ipam.drivers.neutrondb_ipam import db_models # noqa
|
from neutron.ipam.drivers.neutrondb_ipam import db_models # noqa
|
||||||
from neutron.plugins.ml2.drivers import type_geneve # noqa
|
from neutron.plugins.ml2.drivers import type_geneve # noqa
|
||||||
from neutron.plugins.ml2.drivers import type_vlan # noqa
|
|
||||||
from neutron.plugins.ml2 import models as ml2_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.auto_allocate import models as aa_models # noqa
|
||||||
from neutron.services.segments import db # noqa
|
from neutron.services.segments import db # noqa
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
class VlanAllocation(model_base.BASEV2):
|
||||||
|
"""Represent allocation state of a vlan_id on a physical network.
|
||||||
|
|
||||||
|
If allocated is False, the vlan_id on the physical_network is
|
||||||
|
available for allocation to a tenant network. If allocated is
|
||||||
|
True, the vlan_id on the physical_network is in use, either as a
|
||||||
|
tenant or provider network.
|
||||||
|
|
||||||
|
When an allocation is released, if the vlan_id for the
|
||||||
|
physical_network is inside the pool described by
|
||||||
|
VlanTypeDriver.network_vlan_ranges, then allocated is set to
|
||||||
|
False. If it is outside the pool, the record is deleted.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__tablename__ = 'ml2_vlan_allocations'
|
||||||
|
__table_args__ = (
|
||||||
|
sa.Index('ix_ml2_vlan_allocations_physical_network_allocated',
|
||||||
|
'physical_network', 'allocated'),
|
||||||
|
model_base.BASEV2.__table_args__,)
|
||||||
|
|
||||||
|
physical_network = sa.Column(sa.String(64), nullable=False,
|
||||||
|
primary_key=True)
|
||||||
|
vlan_id = sa.Column(sa.Integer, nullable=False, primary_key=True,
|
||||||
|
autoincrement=False)
|
||||||
|
allocated = sa.Column(sa.Boolean, nullable=False)
|
|
@ -15,15 +15,15 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from neutron_lib.db import model_base
|
|
||||||
from neutron_lib import exceptions as exc
|
from neutron_lib import exceptions as exc
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from six import moves
|
from six import moves
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
from neutron._i18n import _, _LE, _LI, _LW
|
from neutron._i18n import _, _LE, _LI, _LW
|
||||||
|
from neutron.common import _deprecate
|
||||||
from neutron.db import api as db_api
|
from neutron.db import api as db_api
|
||||||
|
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
|
||||||
from neutron.plugins.common import constants as p_const
|
from neutron.plugins.common import constants as p_const
|
||||||
from neutron.plugins.common import utils as plugin_utils
|
from neutron.plugins.common import utils as plugin_utils
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
from neutron.plugins.ml2 import driver_api as api
|
||||||
|
@ -43,32 +43,7 @@ vlan_opts = [
|
||||||
|
|
||||||
cfg.CONF.register_opts(vlan_opts, "ml2_type_vlan")
|
cfg.CONF.register_opts(vlan_opts, "ml2_type_vlan")
|
||||||
|
|
||||||
|
_deprecate._moved_global('VlanAllocation', new_module=vlan_alloc_model)
|
||||||
class VlanAllocation(model_base.BASEV2):
|
|
||||||
"""Represent allocation state of a vlan_id on a physical network.
|
|
||||||
|
|
||||||
If allocated is False, the vlan_id on the physical_network is
|
|
||||||
available for allocation to a tenant network. If allocated is
|
|
||||||
True, the vlan_id on the physical_network is in use, either as a
|
|
||||||
tenant or provider network.
|
|
||||||
|
|
||||||
When an allocation is released, if the vlan_id for the
|
|
||||||
physical_network is inside the pool described by
|
|
||||||
VlanTypeDriver.network_vlan_ranges, then allocated is set to
|
|
||||||
False. If it is outside the pool, the record is deleted.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__tablename__ = 'ml2_vlan_allocations'
|
|
||||||
__table_args__ = (
|
|
||||||
sa.Index('ix_ml2_vlan_allocations_physical_network_allocated',
|
|
||||||
'physical_network', 'allocated'),
|
|
||||||
model_base.BASEV2.__table_args__,)
|
|
||||||
|
|
||||||
physical_network = sa.Column(sa.String(64), nullable=False,
|
|
||||||
primary_key=True)
|
|
||||||
vlan_id = sa.Column(sa.Integer, nullable=False, primary_key=True,
|
|
||||||
autoincrement=False)
|
|
||||||
allocated = sa.Column(sa.Boolean, nullable=False)
|
|
||||||
|
|
||||||
|
|
||||||
class VlanTypeDriver(helpers.SegmentTypeDriver):
|
class VlanTypeDriver(helpers.SegmentTypeDriver):
|
||||||
|
@ -83,7 +58,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(VlanTypeDriver, self).__init__(VlanAllocation)
|
super(VlanTypeDriver, self).__init__(vlan_alloc_model.VlanAllocation)
|
||||||
self._parse_network_vlan_ranges()
|
self._parse_network_vlan_ranges()
|
||||||
|
|
||||||
def _parse_network_vlan_ranges(self):
|
def _parse_network_vlan_ranges(self):
|
||||||
|
@ -101,7 +76,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
# get existing allocations for all physical networks
|
# get existing allocations for all physical networks
|
||||||
allocations = dict()
|
allocations = dict()
|
||||||
allocs = (session.query(VlanAllocation).
|
allocs = (session.query(vlan_alloc_model.VlanAllocation).
|
||||||
with_lockmode('update'))
|
with_lockmode('update'))
|
||||||
for alloc in allocs:
|
for alloc in allocs:
|
||||||
if alloc.physical_network not in allocations:
|
if alloc.physical_network not in allocations:
|
||||||
|
@ -139,7 +114,8 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
||||||
|
|
||||||
# add missing allocatable vlans to table
|
# add missing allocatable vlans to table
|
||||||
for vlan_id in sorted(vlan_ids):
|
for vlan_id in sorted(vlan_ids):
|
||||||
alloc = VlanAllocation(physical_network=physical_network,
|
alloc = vlan_alloc_model.VlanAllocation(
|
||||||
|
physical_network=physical_network,
|
||||||
vlan_id=vlan_id,
|
vlan_id=vlan_id,
|
||||||
allocated=False)
|
allocated=False)
|
||||||
session.add(alloc)
|
session.add(alloc)
|
||||||
|
@ -235,7 +211,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
||||||
inside = any(lo <= vlan_id <= hi for lo, hi in ranges)
|
inside = any(lo <= vlan_id <= hi for lo, hi in ranges)
|
||||||
|
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
query = (session.query(VlanAllocation).
|
query = (session.query(vlan_alloc_model.VlanAllocation).
|
||||||
filter_by(physical_network=physical_network,
|
filter_by(physical_network=physical_network,
|
||||||
vlan_id=vlan_id))
|
vlan_id=vlan_id))
|
||||||
if inside:
|
if inside:
|
||||||
|
@ -267,3 +243,6 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
||||||
if physical_network in self.physnet_mtus:
|
if physical_network in self.physnet_mtus:
|
||||||
mtu.append(int(self.physnet_mtus[physical_network]))
|
mtu.append(int(self.physnet_mtus[physical_network]))
|
||||||
return min(mtu) if mtu else 0
|
return min(mtu) if mtu else 0
|
||||||
|
|
||||||
|
|
||||||
|
_deprecate._MovedGlobals()
|
||||||
|
|
|
@ -18,6 +18,7 @@ from neutron_lib import exceptions as exc
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
import neutron.db.api as db
|
import neutron.db.api as db
|
||||||
|
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
|
||||||
from neutron.plugins.common import constants as p_const
|
from neutron.plugins.common import constants as p_const
|
||||||
from neutron.plugins.common import utils as plugin_utils
|
from neutron.plugins.common import utils as plugin_utils
|
||||||
from neutron.plugins.ml2 import config
|
from neutron.plugins.ml2 import config
|
||||||
|
@ -59,7 +60,7 @@ class VlanTypeTest(testlib_api.SqlTestCase):
|
||||||
self.driver._parse_network_vlan_ranges)
|
self.driver._parse_network_vlan_ranges)
|
||||||
|
|
||||||
def _get_allocation(self, session, segment):
|
def _get_allocation(self, session, segment):
|
||||||
return session.query(type_vlan.VlanAllocation).filter_by(
|
return session.query(vlan_alloc_model.VlanAllocation).filter_by(
|
||||||
physical_network=segment[api.PHYSICAL_NETWORK],
|
physical_network=segment[api.PHYSICAL_NETWORK],
|
||||||
vlan_id=segment[api.SEGMENTATION_ID]).first()
|
vlan_id=segment[api.SEGMENTATION_ID]).first()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue