Relocate AddressScope DB model

Required to resolve cyclic import issue when integrating with Oslo
Versioned Object for AddressScope

Change-Id: If57e472c5827033f09a59d1f8d9359a3f241c17c
Partial-Bug: #1597913
This commit is contained in:
Mohit Malik 2016-08-10 09:57:33 -07:00
parent b9169e34e3
commit 72a722e69d
4 changed files with 45 additions and 18 deletions

View File

@ -12,29 +12,21 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
from neutron_lib import constants
from oslo_utils import uuidutils
import sqlalchemy as sa
from sqlalchemy.orm import exc
from neutron._i18n import _
from neutron.api.v2 import attributes as attr
from neutron.common import _deprecate
from neutron.db import db_base_plugin_v2
from neutron.db import model_base
from neutron.db.models import address_scope as address_scope_model
from neutron.extensions import address_scope as ext_address_scope
from neutron.objects import subnetpool as subnetpool_obj
class AddressScope(model_base.BASEV2, model_base.HasId, model_base.HasProject):
"""Represents a neutron address scope."""
__tablename__ = "address_scopes"
name = sa.Column(sa.String(attr.NAME_MAX_LEN), nullable=False)
shared = sa.Column(sa.Boolean, nullable=False)
ip_version = sa.Column(sa.Integer(), nullable=False)
class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
"""Mixin class to add address scope to db_base_plugin_v2."""
@ -50,7 +42,8 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
def _get_address_scope(self, context, id):
try:
return self._get_by_id(context, AddressScope, id)
return self._get_by_id(context, address_scope_model.AddressScope,
id)
except exc.NoResultFound:
raise ext_address_scope.AddressScopeNotFound(address_scope_id=id)
@ -83,7 +76,7 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
'name': a_s['name'],
'shared': a_s['shared'],
'ip_version': a_s['ip_version']}
address_scope = AddressScope(**pool_args)
address_scope = address_scope_model.AddressScope(**pool_args)
context.session.add(address_scope)
return self._make_address_scope_dict(address_scope)
@ -108,7 +101,8 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
sorts=None, limit=None, marker=None,
page_reverse=False):
marker_obj = self._get_marker_obj(context, 'addrscope', limit, marker)
collection = self._get_collection(context, AddressScope,
collection = self._get_collection(context,
address_scope_model.AddressScope,
self._make_address_scope_dict,
filters=filters, fields=fields,
sorts=sorts,
@ -118,7 +112,8 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
return collection
def get_address_scopes_count(self, context, filters=None):
return self._get_collection_count(context, AddressScope,
return self._get_collection_count(context,
address_scope_model.AddressScope,
filters=filters)
def delete_address_scope(self, context, id):
@ -147,3 +142,10 @@ class AddressScopeDbMixin(ext_address_scope.AddressScopePluginBase):
db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
attr.NETWORKS, ['_extend_network_dict_address_scope'])
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
_OLD_REF = sys.modules[__name__]
sys.modules[__name__] = _deprecate._DeprecateSubset(globals(),
address_scope_model)
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE

View File

@ -24,7 +24,6 @@ Based on this comparison database can be healed with healing migration.
import os.path
from neutron.common import utils
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 import dns_db # noqa

View File

@ -0,0 +1,26 @@
# 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.api.v2 import attributes as attr
from neutron.db import model_base
class AddressScope(model_base.BASEV2, model_base.HasId, model_base.HasProject):
"""Represents a neutron address scope."""
__tablename__ = "address_scopes"
name = sa.Column(sa.String(attr.NAME_MAX_LEN), nullable=False)
shared = sa.Column(sa.Boolean, nullable=False)
ip_version = sa.Column(sa.Integer(), nullable=False)

View File

@ -15,7 +15,7 @@
from oslo_versionedobjects import base as obj_base
from oslo_versionedobjects import fields as obj_fields
from neutron.db import address_scope_db as models
from neutron.db.models import address_scope as models
from neutron.objects import base
from neutron.objects import common_types