Relocate dvr model
As there would be issue of cyclic imports while implementation of Oslo-Versioned Objects for DVR which has db models definition and mixins in same file, this patch will relocate DVR models. Change-Id: I4005570c7507ae9c28fd2910b368e4fdf5e603b0 Co-Authored-By: Victor Morales <victor.morales@intel.com> Partial-Bug: #1597913
This commit is contained in:
parent
b6a296edf6
commit
509bc4c2ab
@ -14,13 +14,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib.db import model_base
|
|
||||||
from neutron_lib import exceptions as n_exc
|
from neutron_lib import exceptions as n_exc
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
from oslo_log import helpers as log_helpers
|
from oslo_log import helpers as log_helpers
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import sqlalchemy as sa
|
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
from sqlalchemy.orm import exc
|
from sqlalchemy.orm import exc
|
||||||
|
|
||||||
@ -28,13 +26,17 @@ from neutron._i18n import _, _LE
|
|||||||
from neutron.callbacks import events
|
from neutron.callbacks import events
|
||||||
from neutron.callbacks import registry
|
from neutron.callbacks import registry
|
||||||
from neutron.callbacks import resources
|
from neutron.callbacks import resources
|
||||||
|
from neutron.common import _deprecate
|
||||||
from neutron.common import utils
|
from neutron.common import utils
|
||||||
from neutron.db import api as db_api
|
from neutron.db import api as db_api
|
||||||
|
from neutron.db.models import dvr as dvr_models
|
||||||
from neutron.db import models_v2
|
from neutron.db import models_v2
|
||||||
from neutron.extensions import dvr as ext_dvr
|
from neutron.extensions import dvr as ext_dvr
|
||||||
from neutron.extensions import portbindings
|
from neutron.extensions import portbindings
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
|
|
||||||
|
_deprecate._moved_global('DistributedVirtualRouterMacAddress',
|
||||||
|
new_module=dvr_models)
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -55,15 +57,6 @@ dvr_mac_address_opts = [
|
|||||||
cfg.CONF.register_opts(dvr_mac_address_opts)
|
cfg.CONF.register_opts(dvr_mac_address_opts)
|
||||||
|
|
||||||
|
|
||||||
class DistributedVirtualRouterMacAddress(model_base.BASEV2):
|
|
||||||
"""Represents a v2 neutron distributed virtual router mac address."""
|
|
||||||
|
|
||||||
__tablename__ = 'dvr_host_macs'
|
|
||||||
|
|
||||||
host = sa.Column(sa.String(255), primary_key=True, nullable=False)
|
|
||||||
mac_address = sa.Column(sa.String(32), nullable=False, unique=True)
|
|
||||||
|
|
||||||
|
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
def _delete_mac_associated_with_agent(resource, event, trigger, context, agent,
|
def _delete_mac_associated_with_agent(resource, event, trigger, context, agent,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
@ -76,8 +69,11 @@ def _delete_mac_associated_with_agent(resource, event, trigger, context, agent,
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
entry = (context.session.query(DistributedVirtualRouterMacAddress).
|
entry = (context.session.query(
|
||||||
filter(DistributedVirtualRouterMacAddress.host == host).
|
dvr_models.DistributedVirtualRouterMacAddress).
|
||||||
|
filter(
|
||||||
|
dvr_models.DistributedVirtualRouterMacAddress.host ==
|
||||||
|
host).
|
||||||
one())
|
one())
|
||||||
context.session.delete(entry)
|
context.session.delete(entry)
|
||||||
except exc.NoResultFound:
|
except exc.NoResultFound:
|
||||||
@ -107,9 +103,11 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
|||||||
|
|
||||||
def _get_dvr_mac_address_by_host(self, context, host):
|
def _get_dvr_mac_address_by_host(self, context, host):
|
||||||
try:
|
try:
|
||||||
query = context.session.query(DistributedVirtualRouterMacAddress)
|
query = context.session.query(
|
||||||
|
dvr_models.DistributedVirtualRouterMacAddress)
|
||||||
dvrma = query.filter(
|
dvrma = query.filter(
|
||||||
DistributedVirtualRouterMacAddress.host == host).one()
|
dvr_models.DistributedVirtualRouterMacAddress.host == host
|
||||||
|
).one()
|
||||||
except exc.NoResultFound:
|
except exc.NoResultFound:
|
||||||
raise ext_dvr.DVRMacAddressNotFound(host=host)
|
raise ext_dvr.DVRMacAddressNotFound(host=host)
|
||||||
return dvrma
|
return dvrma
|
||||||
@ -119,7 +117,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
|||||||
def _create_dvr_mac_address_retry(self, context, host, base_mac):
|
def _create_dvr_mac_address_retry(self, context, host, base_mac):
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
mac_address = utils.get_random_mac(base_mac)
|
mac_address = utils.get_random_mac(base_mac)
|
||||||
dvr_mac_binding = DistributedVirtualRouterMacAddress(
|
dvr_mac_binding = dvr_models.DistributedVirtualRouterMacAddress(
|
||||||
host=host, mac_address=mac_address)
|
host=host, mac_address=mac_address)
|
||||||
context.session.add(dvr_mac_binding)
|
context.session.add(dvr_mac_binding)
|
||||||
LOG.debug("Generated DVR mac for host %(host)s "
|
LOG.debug("Generated DVR mac for host %(host)s "
|
||||||
@ -144,7 +142,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
|||||||
def get_dvr_mac_address_list(self, context):
|
def get_dvr_mac_address_list(self, context):
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
return (context.session.
|
return (context.session.
|
||||||
query(DistributedVirtualRouterMacAddress).all())
|
query(dvr_models.DistributedVirtualRouterMacAddress).all())
|
||||||
|
|
||||||
def get_dvr_mac_address_by_host(self, context, host):
|
def get_dvr_mac_address_by_host(self, context, host):
|
||||||
"""Determine the MAC for the DVR port associated to host."""
|
"""Determine the MAC for the DVR port associated to host."""
|
||||||
@ -221,3 +219,6 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
|||||||
internal_port = internal_gateway_ports[0]
|
internal_port = internal_gateway_ports[0]
|
||||||
subnet_info['gateway_mac'] = internal_port['mac_address']
|
subnet_info['gateway_mac'] = internal_port['mac_address']
|
||||||
return subnet_info
|
return subnet_info
|
||||||
|
|
||||||
|
|
||||||
|
_deprecate._MovedGlobals()
|
||||||
|
@ -29,7 +29,6 @@ from neutron.common import utils
|
|||||||
from neutron.db import agents_db # noqa
|
from neutron.db import agents_db # noqa
|
||||||
from neutron.db import agentschedulers_db # noqa
|
from neutron.db import agentschedulers_db # noqa
|
||||||
from neutron.db import dns_db # noqa
|
from neutron.db import dns_db # noqa
|
||||||
from neutron.db import dvr_mac_db # noqa
|
|
||||||
from neutron.db.extra_dhcp_opt import models as edo_models # noqa
|
from neutron.db.extra_dhcp_opt import models as edo_models # noqa
|
||||||
from neutron.db import flavors_db # noqa
|
from neutron.db import flavors_db # noqa
|
||||||
from neutron.db import l3_attrs_db # noqa
|
from neutron.db import l3_attrs_db # noqa
|
||||||
|
26
neutron/db/models/dvr.py
Normal file
26
neutron/db/models/dvr.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Copyright 2016 Hewlett-Packard Development Company, L.P.
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from neutron_lib.db import model_base
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
class DistributedVirtualRouterMacAddress(model_base.BASEV2):
|
||||||
|
"""Represents a v2 neutron distributed virtual router mac address."""
|
||||||
|
|
||||||
|
__tablename__ = 'dvr_host_macs'
|
||||||
|
|
||||||
|
host = sa.Column(sa.String(255), primary_key=True, nullable=False)
|
||||||
|
mac_address = sa.Column(sa.String(32), nullable=False, unique=True)
|
@ -21,6 +21,7 @@ from neutron.callbacks import registry
|
|||||||
from neutron.callbacks import resources
|
from neutron.callbacks import resources
|
||||||
from neutron import context
|
from neutron import context
|
||||||
from neutron.db import dvr_mac_db
|
from neutron.db import dvr_mac_db
|
||||||
|
from neutron.db.models import dvr as dvr_models
|
||||||
from neutron.extensions import dvr
|
from neutron.extensions import dvr
|
||||||
from neutron.extensions import portbindings
|
from neutron.extensions import portbindings
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
@ -42,13 +43,13 @@ class DvrDbMixinTestCase(test_plugin.Ml2PluginV2TestCase):
|
|||||||
|
|
||||||
def _create_dvr_mac_entry(self, host, mac_address):
|
def _create_dvr_mac_entry(self, host, mac_address):
|
||||||
with self.ctx.session.begin(subtransactions=True):
|
with self.ctx.session.begin(subtransactions=True):
|
||||||
entry = dvr_mac_db.DistributedVirtualRouterMacAddress(
|
entry = dvr_models.DistributedVirtualRouterMacAddress(
|
||||||
host=host, mac_address=mac_address)
|
host=host, mac_address=mac_address)
|
||||||
self.ctx.session.add(entry)
|
self.ctx.session.add(entry)
|
||||||
|
|
||||||
def test__get_dvr_mac_address_by_host(self):
|
def test__get_dvr_mac_address_by_host(self):
|
||||||
with self.ctx.session.begin(subtransactions=True):
|
with self.ctx.session.begin(subtransactions=True):
|
||||||
entry = dvr_mac_db.DistributedVirtualRouterMacAddress(
|
entry = dvr_models.DistributedVirtualRouterMacAddress(
|
||||||
host='foo_host', mac_address='foo_mac_address')
|
host='foo_host', mac_address='foo_mac_address')
|
||||||
self.ctx.session.add(entry)
|
self.ctx.session.add(entry)
|
||||||
result = self.mixin._get_dvr_mac_address_by_host(self.ctx, 'foo_host')
|
result = self.mixin._get_dvr_mac_address_by_host(self.ctx, 'foo_host')
|
||||||
|
Loading…
Reference in New Issue
Block a user