Relocate Tag DB model
This patch relocates Tag db model from neutron/db to neutron/db/models Change-Id: Ibb9325f30af85300afe62bb5415388271cf13833 Partial-Bug: #1597913
This commit is contained in:
parent
0c76de8d01
commit
b6a296edf6
|
@ -43,7 +43,6 @@ from neutron.db.qos import models as qos_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 tag_db # noqa
|
||||
from neutron.ipam.drivers.neutrondb_ipam import db_models # noqa
|
||||
from neutron.plugins.ml2 import models as ml2_models # noqa
|
||||
from neutron.services.auto_allocate import models as aa_models # noqa
|
||||
|
|
|
@ -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.
|
||||
#
|
||||
|
||||
from neutron_lib.db import model_base
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from neutron.db import standard_attr
|
||||
|
||||
|
||||
class Tag(model_base.BASEV2):
|
||||
standard_attr_id = sa.Column(
|
||||
sa.BigInteger().with_variant(sa.Integer(), 'sqlite'),
|
||||
sa.ForeignKey(standard_attr.StandardAttribute.id, ondelete="CASCADE"),
|
||||
nullable=False, primary_key=True)
|
||||
tag = sa.Column(sa.String(60), nullable=False, primary_key=True)
|
||||
standard_attr = orm.relationship(
|
||||
'StandardAttribute',
|
||||
backref=orm.backref('tags', lazy='joined', viewonly=True))
|
|
@ -12,23 +12,12 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
from neutron_lib.db import model_base
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.orm import aliased
|
||||
|
||||
from neutron.db import standard_attr
|
||||
from neutron.common import _deprecate
|
||||
from neutron.db.models import tag as tag_model
|
||||
|
||||
|
||||
class Tag(model_base.BASEV2):
|
||||
standard_attr_id = sa.Column(
|
||||
sa.BigInteger().with_variant(sa.Integer(), 'sqlite'),
|
||||
sa.ForeignKey(standard_attr.StandardAttribute.id, ondelete="CASCADE"),
|
||||
nullable=False, primary_key=True)
|
||||
tag = sa.Column(sa.String(60), nullable=False, primary_key=True)
|
||||
standard_attr = orm.relationship(
|
||||
'StandardAttribute',
|
||||
backref=orm.backref('tags', lazy='joined', viewonly=True))
|
||||
_deprecate._moved_global('Tag', new_module=tag_model)
|
||||
|
||||
|
||||
def _get_tag_list(tag_strings):
|
||||
|
@ -64,40 +53,43 @@ def apply_tag_filters(model, query, filters):
|
|||
if 'tags' in filters:
|
||||
tags = _get_tag_list(filters.pop('tags'))
|
||||
first_tag = tags.pop(0)
|
||||
query = query.join(Tag,
|
||||
model.standard_attr_id == Tag.standard_attr_id)
|
||||
query = query.filter(Tag.tag == first_tag)
|
||||
query = query.join(tag_model.Tag,
|
||||
model.standard_attr_id == tag_model.Tag.standard_attr_id)
|
||||
query = query.filter(tag_model.Tag.tag == first_tag)
|
||||
|
||||
for tag in tags:
|
||||
tag_alias = aliased(Tag)
|
||||
tag_alias = aliased(tag_model.Tag)
|
||||
query = query.join(tag_alias,
|
||||
model.standard_attr_id == tag_alias.standard_attr_id)
|
||||
query = query.filter(tag_alias.tag == tag)
|
||||
|
||||
if 'tags-any' in filters:
|
||||
tags = _get_tag_list(filters.pop('tags-any'))
|
||||
query = query.join(Tag,
|
||||
model.standard_attr_id == Tag.standard_attr_id)
|
||||
query = query.filter(Tag.tag.in_(tags))
|
||||
query = query.join(tag_model.Tag,
|
||||
model.standard_attr_id == tag_model.Tag.standard_attr_id)
|
||||
query = query.filter(tag_model.Tag.tag.in_(tags))
|
||||
|
||||
if 'not-tags' in filters:
|
||||
tags = _get_tag_list(filters.pop('not-tags'))
|
||||
first_tag = tags.pop(0)
|
||||
subq = query.session.query(Tag.standard_attr_id)
|
||||
subq = subq.filter(Tag.tag == first_tag)
|
||||
subq = query.session.query(tag_model.Tag.standard_attr_id)
|
||||
subq = subq.filter(tag_model.Tag.tag == first_tag)
|
||||
|
||||
for tag in tags:
|
||||
tag_alias = aliased(Tag)
|
||||
tag_alias = aliased(tag_model.Tag)
|
||||
subq = subq.join(tag_alias,
|
||||
Tag.standard_attr_id == tag_alias.standard_attr_id)
|
||||
tag_model.Tag.standard_attr_id == tag_alias.standard_attr_id)
|
||||
subq = subq.filter(tag_alias.tag == tag)
|
||||
|
||||
query = query.filter(~model.standard_attr_id.in_(subq))
|
||||
|
||||
if 'not-tags-any' in filters:
|
||||
tags = _get_tag_list(filters.pop('not-tags-any'))
|
||||
subq = query.session.query(Tag.standard_attr_id)
|
||||
subq = subq.filter(Tag.tag.in_(tags))
|
||||
subq = query.session.query(tag_model.Tag.standard_attr_id)
|
||||
subq = subq.filter(tag_model.Tag.tag.in_(tags))
|
||||
query = query.filter(~model.standard_attr_id.in_(subq))
|
||||
|
||||
return query
|
||||
|
||||
|
||||
_deprecate._MovedGlobals()
|
||||
|
|
|
@ -22,8 +22,9 @@ from sqlalchemy.orm import exc
|
|||
from neutron.api.v2 import attributes
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.db.models import tag as tag_model
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import tag_db as tag_model
|
||||
from neutron.db import tag_db as tag_methods
|
||||
from neutron.extensions import tag as tag_ext
|
||||
|
||||
|
||||
|
@ -121,4 +122,4 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase):
|
|||
resource, [_extend_tags_dict])
|
||||
common_db_mixin.CommonDbMixin.register_model_query_hook(
|
||||
model, "tag", None, None,
|
||||
functools.partial(tag_model.apply_tag_filters, model))
|
||||
functools.partial(tag_methods.apply_tag_filters, model))
|
||||
|
|
|
@ -20,8 +20,8 @@ from oslo_utils import timeutils
|
|||
|
||||
from neutron import context
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db.models import tag as tag_model
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import tag_db as tag_module
|
||||
from neutron.extensions import timestamp
|
||||
from neutron import manager
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
|
@ -256,8 +256,8 @@ class TimeStampDBMixinTestCase(TimeStampChangedsinceTestCase):
|
|||
ctx = context.get_admin_context()
|
||||
for tag in tags:
|
||||
with ctx.session.begin(subtransactions=True):
|
||||
tag_db = tag_module.Tag(standard_attr_id=standard_attr_id,
|
||||
tag=tag)
|
||||
tag_db = tag_model.Tag(standard_attr_id=standard_attr_id,
|
||||
tag=tag)
|
||||
ctx.session.add(tag_db)
|
||||
|
||||
def test_update_timpestamp(self):
|
||||
|
|
Loading…
Reference in New Issue