Relocate subnet_service_types db models
This patch will relocate subnet_service_types db models and separate it from mixins for OVO implementation. Change-Id: Iec3db14a5049920cd370297ab6282b0b070156e7 Partial-Bug: #1597913
This commit is contained in:
parent
d1227c2ff8
commit
16ba121305
|
@ -33,9 +33,9 @@ from neutron.common import exceptions as n_exc
|
|||
from neutron.common import ipv6_utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.db import db_base_plugin_common
|
||||
from neutron.db.models import subnet_service_type as sst_model
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import segments_db
|
||||
from neutron.db import subnet_service_type_db_models as service_type_db
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import segment
|
||||
from neutron.ipam import exceptions as ipam_exceptions
|
||||
|
@ -181,13 +181,12 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
|
|||
|
||||
def _update_subnet_service_types(self, context, subnet_id, s):
|
||||
old_types = context.session.query(
|
||||
service_type_db.SubnetServiceType).filter_by(
|
||||
subnet_id=subnet_id)
|
||||
sst_model.SubnetServiceType).filter_by(subnet_id=subnet_id)
|
||||
for service_type in old_types:
|
||||
context.session.delete(service_type)
|
||||
updated_types = s.pop('service_types')
|
||||
for service_type in updated_types:
|
||||
new_type = service_type_db.SubnetServiceType(
|
||||
new_type = sst_model.SubnetServiceType(
|
||||
subnet_id=subnet_id,
|
||||
service_type=service_type)
|
||||
context.session.add(new_type)
|
||||
|
@ -523,7 +522,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
|
|||
|
||||
if validators.is_attr_set(service_types):
|
||||
for service_type in service_types:
|
||||
service_type_entry = service_type_db.SubnetServiceType(
|
||||
service_type_entry = sst_model.SubnetServiceType(
|
||||
subnet_id=subnet.id,
|
||||
service_type=service_type)
|
||||
context.session.add(service_type_entry)
|
||||
|
@ -566,7 +565,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
|
|||
return fixed_ip_list
|
||||
|
||||
def _query_filter_service_subnets(self, query, service_type):
|
||||
ServiceType = service_type_db.SubnetServiceType
|
||||
ServiceType = sst_model.SubnetServiceType
|
||||
query = query.add_entity(ServiceType)
|
||||
query = query.outerjoin(ServiceType)
|
||||
query = query.filter(or_(ServiceType.service_type.is_(None),
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright 2016 Hewlett Packard Enterprise Development Company, LP
|
||||
# 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.
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
|
||||
|
||||
class SubnetServiceType(model_base.BASEV2):
|
||||
"""Subnet Service Types table"""
|
||||
|
||||
__tablename__ = "subnet_service_types"
|
||||
|
||||
subnet_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('subnets.id', ondelete="CASCADE"))
|
||||
# Service types must be valid device owners, therefore share max length
|
||||
service_type = sa.Column(sa.String(
|
||||
length=attributes.DEVICE_OWNER_MAX_LEN))
|
||||
subnet = orm.relationship(models_v2.Subnet,
|
||||
backref=orm.backref('service_types',
|
||||
lazy='joined',
|
||||
cascade='all, delete-orphan',
|
||||
uselist=True))
|
||||
__table_args__ = (
|
||||
sa.PrimaryKeyConstraint('subnet_id', 'service_type'),
|
||||
model_base.BASEV2.__table_args__
|
||||
)
|
|
@ -13,34 +13,15 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
# TODO(ihrachys): consider renaming the module since now it does not contain
|
||||
# any models at all
|
||||
|
||||
import sys
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import _deprecate
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
|
||||
|
||||
class SubnetServiceType(model_base.BASEV2):
|
||||
"""Subnet Service Types table"""
|
||||
|
||||
__tablename__ = "subnet_service_types"
|
||||
|
||||
subnet_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('subnets.id', ondelete="CASCADE"))
|
||||
# Service types must be valid device owners, therefore share max length
|
||||
service_type = sa.Column(sa.String(
|
||||
length=attributes.DEVICE_OWNER_MAX_LEN))
|
||||
subnet = orm.relationship(models_v2.Subnet,
|
||||
backref=orm.backref('service_types',
|
||||
lazy='joined',
|
||||
cascade='all, delete-orphan',
|
||||
uselist=True))
|
||||
__table_args__ = (
|
||||
sa.PrimaryKeyConstraint('subnet_id', 'service_type'),
|
||||
model_base.BASEV2.__table_args__
|
||||
)
|
||||
from neutron.db.models import subnet_service_type as sst_model
|
||||
|
||||
|
||||
class SubnetServiceTypeMixin(object):
|
||||
|
@ -53,3 +34,9 @@ class SubnetServiceTypeMixin(object):
|
|||
|
||||
common_db_mixin.CommonDbMixin.register_dict_extend_funcs(
|
||||
attributes.SUBNETS, [_extend_subnet_service_types])
|
||||
|
||||
|
||||
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
|
||||
_OLD_REF = sys.modules[__name__]
|
||||
sys.modules[__name__] = _deprecate._DeprecateSubset(globals(), sst_model)
|
||||
# WARNING: THESE MUST BE THE LAST TWO LINES IN THIS MODULE
|
||||
|
|
Loading…
Reference in New Issue