Merge "VMware: consolidate NSX models"
This commit is contained in:
commit
b1f7347a2a
|
@ -67,12 +67,8 @@ from neutron.plugins.nec.db import packetfilter as nec_packetfilter # noqa
|
|||
from neutron.plugins.nec.db import router # noqa
|
||||
from neutron.plugins.nuage import nuage_models # noqa
|
||||
from neutron.plugins.openvswitch import ovs_models_v2 # noqa
|
||||
from neutron.plugins.vmware.dbexts import lsn_db # noqa
|
||||
from neutron.plugins.vmware.dbexts import maclearning # noqa
|
||||
from neutron.plugins.vmware.dbexts import models as vmware_models # noqa
|
||||
from neutron.plugins.vmware.dbexts import networkgw_db # noqa
|
||||
from neutron.plugins.vmware.dbexts import nsx_models # noqa
|
||||
from neutron.plugins.vmware.dbexts import nsxv_models # noqa
|
||||
from neutron.plugins.vmware.dbexts import qos_db # noqa
|
||||
from neutron.plugins.vmware.dbexts import vcns_models # noqa
|
||||
|
||||
|
||||
|
|
|
@ -20,15 +20,14 @@ from sqlalchemy.orm import exc
|
|||
|
||||
import neutron.db.api as db
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.plugins.vmware.dbexts import models
|
||||
from neutron.plugins.vmware.dbexts import networkgw_db
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_network_bindings(session, network_id):
|
||||
session = session or db.get_session()
|
||||
return (session.query(models.TzNetworkBinding).
|
||||
return (session.query(nsx_models.TzNetworkBinding).
|
||||
filter_by(network_id=network_id).
|
||||
all())
|
||||
|
||||
|
@ -36,19 +35,19 @@ def get_network_bindings(session, network_id):
|
|||
def get_network_bindings_by_vlanid_and_physical_net(session, vlan_id,
|
||||
phy_uuid):
|
||||
session = session or db.get_session()
|
||||
return (session.query(models.TzNetworkBinding).
|
||||
return (session.query(nsx_models.TzNetworkBinding).
|
||||
filter_by(vlan_id=vlan_id, phy_uuid=phy_uuid).
|
||||
all())
|
||||
|
||||
|
||||
def delete_network_bindings(session, network_id):
|
||||
return (session.query(models.TzNetworkBinding).
|
||||
return (session.query(nsx_models.TzNetworkBinding).
|
||||
filter_by(network_id=network_id).delete())
|
||||
|
||||
|
||||
def add_network_binding(session, network_id, binding_type, phy_uuid, vlan_id):
|
||||
with session.begin(subtransactions=True):
|
||||
binding = models.TzNetworkBinding(network_id, binding_type,
|
||||
binding = nsx_models.TzNetworkBinding(network_id, binding_type,
|
||||
phy_uuid, vlan_id)
|
||||
session.add(binding)
|
||||
return binding
|
||||
|
@ -56,7 +55,7 @@ def add_network_binding(session, network_id, binding_type, phy_uuid, vlan_id):
|
|||
|
||||
def add_neutron_nsx_network_mapping(session, neutron_id, nsx_switch_id):
|
||||
with session.begin(subtransactions=True):
|
||||
mapping = models.NeutronNsxNetworkMapping(
|
||||
mapping = nsx_models.NeutronNsxNetworkMapping(
|
||||
neutron_id=neutron_id, nsx_id=nsx_switch_id)
|
||||
session.add(mapping)
|
||||
return mapping
|
||||
|
@ -66,7 +65,7 @@ def add_neutron_nsx_port_mapping(session, neutron_id,
|
|||
nsx_switch_id, nsx_port_id):
|
||||
session.begin(subtransactions=True)
|
||||
try:
|
||||
mapping = models.NeutronNsxPortMapping(
|
||||
mapping = nsx_models.NeutronNsxPortMapping(
|
||||
neutron_id, nsx_switch_id, nsx_port_id)
|
||||
session.add(mapping)
|
||||
session.commit()
|
||||
|
@ -91,7 +90,7 @@ def add_neutron_nsx_port_mapping(session, neutron_id,
|
|||
|
||||
def add_neutron_nsx_router_mapping(session, neutron_id, nsx_router_id):
|
||||
with session.begin(subtransactions=True):
|
||||
mapping = models.NeutronNsxRouterMapping(
|
||||
mapping = nsx_models.NeutronNsxRouterMapping(
|
||||
neutron_id=neutron_id, nsx_id=nsx_router_id)
|
||||
session.add(mapping)
|
||||
return mapping
|
||||
|
@ -105,7 +104,7 @@ def add_neutron_nsx_security_group_mapping(session, neutron_id, nsx_id):
|
|||
:param nsx_id: a nsx security profile identifier
|
||||
"""
|
||||
with session.begin(subtransactions=True):
|
||||
mapping = models.NeutronNsxSecurityGroupMapping(
|
||||
mapping = nsx_models.NeutronNsxSecurityGroupMapping(
|
||||
neutron_id=neutron_id, nsx_id=nsx_id)
|
||||
session.add(mapping)
|
||||
return mapping
|
||||
|
@ -115,13 +114,13 @@ def get_nsx_switch_ids(session, neutron_id):
|
|||
# This function returns a list of NSX switch identifiers because of
|
||||
# the possibility of chained logical switches
|
||||
return [mapping['nsx_id'] for mapping in
|
||||
session.query(models.NeutronNsxNetworkMapping).filter_by(
|
||||
session.query(nsx_models.NeutronNsxNetworkMapping).filter_by(
|
||||
neutron_id=neutron_id)]
|
||||
|
||||
|
||||
def get_nsx_switch_and_port_id(session, neutron_id):
|
||||
try:
|
||||
mapping = (session.query(models.NeutronNsxPortMapping).
|
||||
mapping = (session.query(nsx_models.NeutronNsxPortMapping).
|
||||
filter_by(neutron_id=neutron_id).
|
||||
one())
|
||||
return mapping['nsx_switch_id'], mapping['nsx_port_id']
|
||||
|
@ -133,7 +132,7 @@ def get_nsx_switch_and_port_id(session, neutron_id):
|
|||
|
||||
def get_nsx_router_id(session, neutron_id):
|
||||
try:
|
||||
mapping = (session.query(models.NeutronNsxRouterMapping).
|
||||
mapping = (session.query(nsx_models.NeutronNsxRouterMapping).
|
||||
filter_by(neutron_id=neutron_id).one())
|
||||
return mapping['nsx_id']
|
||||
except exc.NoResultFound:
|
||||
|
@ -147,7 +146,7 @@ def get_nsx_security_group_id(session, neutron_id):
|
|||
Note: security groups are called 'security profiles' in NSX
|
||||
"""
|
||||
try:
|
||||
mapping = (session.query(models.NeutronNsxSecurityGroupMapping).
|
||||
mapping = (session.query(nsx_models.NeutronNsxSecurityGroupMapping).
|
||||
filter_by(neutron_id=neutron_id).
|
||||
one())
|
||||
return mapping['nsx_id']
|
||||
|
@ -163,30 +162,30 @@ def _delete_by_neutron_id(session, model, neutron_id):
|
|||
|
||||
def delete_neutron_nsx_port_mapping(session, neutron_id):
|
||||
return _delete_by_neutron_id(
|
||||
session, models.NeutronNsxPortMapping, neutron_id)
|
||||
session, nsx_models.NeutronNsxPortMapping, neutron_id)
|
||||
|
||||
|
||||
def delete_neutron_nsx_router_mapping(session, neutron_id):
|
||||
return _delete_by_neutron_id(
|
||||
session, models.NeutronNsxRouterMapping, neutron_id)
|
||||
session, nsx_models.NeutronNsxRouterMapping, neutron_id)
|
||||
|
||||
|
||||
def unset_default_network_gateways(session):
|
||||
with session.begin(subtransactions=True):
|
||||
session.query(networkgw_db.NetworkGateway).update(
|
||||
{networkgw_db.NetworkGateway.default: False})
|
||||
session.query(nsx_models.NetworkGateway).update(
|
||||
{nsx_models.NetworkGateway.default: False})
|
||||
|
||||
|
||||
def set_default_network_gateway(session, gw_id):
|
||||
with session.begin(subtransactions=True):
|
||||
gw = (session.query(networkgw_db.NetworkGateway).
|
||||
gw = (session.query(nsx_models.NetworkGateway).
|
||||
filter_by(id=gw_id).one())
|
||||
gw['default'] = True
|
||||
|
||||
|
||||
def set_multiprovider_network(session, network_id):
|
||||
with session.begin(subtransactions=True):
|
||||
multiprovider_network = models.MultiProviderNetworks(
|
||||
multiprovider_network = nsx_models.MultiProviderNetworks(
|
||||
network_id)
|
||||
session.add(multiprovider_network)
|
||||
return multiprovider_network
|
||||
|
@ -195,5 +194,5 @@ def set_multiprovider_network(session, network_id):
|
|||
def is_multiprovider_network(session, network_id):
|
||||
with session.begin(subtransactions=True):
|
||||
return bool(
|
||||
session.query(models.MultiProviderNetworks).filter_by(
|
||||
session.query(nsx_models.MultiProviderNetworks).filter_by(
|
||||
network_id=network_id).first())
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
# Copyright 2013 VMware, Inc.
|
||||
#
|
||||
# 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 sqlalchemy import Column, Enum, ForeignKey, Integer, String
|
||||
|
||||
from neutron.db import model_base
|
||||
|
||||
|
||||
class TzNetworkBinding(model_base.BASEV2):
|
||||
"""Represents a binding of a virtual network with a transport zone.
|
||||
|
||||
This model class associates a Neutron network with a transport zone;
|
||||
optionally a vlan ID might be used if the binding type is 'bridge'
|
||||
"""
|
||||
__tablename__ = 'tz_network_bindings'
|
||||
|
||||
# TODO(arosen) - it might be worth while refactoring the how this data
|
||||
# is stored later so every column does not need to be a primary key.
|
||||
network_id = Column(String(36),
|
||||
ForeignKey('networks.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
# 'flat', 'vlan', stt' or 'gre'
|
||||
binding_type = Column(Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext',
|
||||
name='tz_network_bindings_binding_type'),
|
||||
nullable=False, primary_key=True)
|
||||
phy_uuid = Column(String(36), primary_key=True, default='')
|
||||
vlan_id = Column(Integer, primary_key=True, autoincrement=False, default=0)
|
||||
|
||||
def __init__(self, network_id, binding_type, phy_uuid, vlan_id):
|
||||
self.network_id = network_id
|
||||
self.binding_type = binding_type
|
||||
self.phy_uuid = phy_uuid
|
||||
self.vlan_id = vlan_id
|
||||
|
||||
def __repr__(self):
|
||||
return "<NetworkBinding(%s,%s,%s,%s)>" % (self.network_id,
|
||||
self.binding_type,
|
||||
self.phy_uuid,
|
||||
self.vlan_id)
|
||||
|
||||
|
||||
class NeutronNsxNetworkMapping(model_base.BASEV2):
|
||||
"""Maps neutron network identifiers to NSX identifiers.
|
||||
|
||||
Because of chained logical switches more than one mapping might exist
|
||||
for a single Neutron network.
|
||||
"""
|
||||
__tablename__ = 'neutron_nsx_network_mappings'
|
||||
neutron_id = Column(String(36),
|
||||
ForeignKey('networks.id', ondelete='CASCADE'),
|
||||
primary_key=True)
|
||||
nsx_id = Column(String(36), primary_key=True)
|
||||
|
||||
|
||||
class NeutronNsxSecurityGroupMapping(model_base.BASEV2):
|
||||
"""Backend mappings for Neutron Security Group identifiers.
|
||||
|
||||
This class maps a neutron security group identifier to the corresponding
|
||||
NSX security profile identifier.
|
||||
"""
|
||||
|
||||
__tablename__ = 'neutron_nsx_security_group_mappings'
|
||||
neutron_id = Column(String(36),
|
||||
ForeignKey('securitygroups.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
nsx_id = Column(String(36), primary_key=True)
|
||||
|
||||
|
||||
class NeutronNsxPortMapping(model_base.BASEV2):
|
||||
"""Represents the mapping between neutron and nsx port uuids."""
|
||||
|
||||
__tablename__ = 'neutron_nsx_port_mappings'
|
||||
neutron_id = Column(String(36),
|
||||
ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
nsx_switch_id = Column(String(36))
|
||||
nsx_port_id = Column(String(36), nullable=False)
|
||||
|
||||
def __init__(self, neutron_id, nsx_switch_id, nsx_port_id):
|
||||
self.neutron_id = neutron_id
|
||||
self.nsx_switch_id = nsx_switch_id
|
||||
self.nsx_port_id = nsx_port_id
|
||||
|
||||
|
||||
class NeutronNsxRouterMapping(model_base.BASEV2):
|
||||
"""Maps neutron router identifiers to NSX identifiers."""
|
||||
__tablename__ = 'neutron_nsx_router_mappings'
|
||||
neutron_id = Column(String(36),
|
||||
ForeignKey('routers.id', ondelete='CASCADE'),
|
||||
primary_key=True)
|
||||
nsx_id = Column(String(36))
|
||||
|
||||
|
||||
class MultiProviderNetworks(model_base.BASEV2):
|
||||
"""Networks provisioned through multiprovider extension."""
|
||||
|
||||
__tablename__ = 'multi_provider_networks'
|
||||
network_id = Column(String(36),
|
||||
ForeignKey('networks.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
|
||||
def __init__(self, network_id):
|
||||
self.network_id = network_id
|
|
@ -27,6 +27,105 @@ from neutron.db import model_base
|
|||
from neutron.db import models_v2
|
||||
|
||||
|
||||
class TzNetworkBinding(model_base.BASEV2):
|
||||
"""Represents a binding of a virtual network with a transport zone.
|
||||
|
||||
This model class associates a Neutron network with a transport zone;
|
||||
optionally a vlan ID might be used if the binding type is 'bridge'
|
||||
"""
|
||||
__tablename__ = 'tz_network_bindings'
|
||||
|
||||
# TODO(arosen) - it might be worth while refactoring the how this data
|
||||
# is stored later so every column does not need to be a primary key.
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networks.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
# 'flat', 'vlan', stt' or 'gre'
|
||||
binding_type = sa.Column(sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext',
|
||||
name='tz_network_bindings_binding_type'),
|
||||
nullable=False, primary_key=True)
|
||||
phy_uuid = sa.Column(sa.String(36), primary_key=True, default='')
|
||||
vlan_id = sa.Column(sa.Integer, primary_key=True,
|
||||
autoincrement=False, default=0)
|
||||
|
||||
def __init__(self, network_id, binding_type, phy_uuid, vlan_id):
|
||||
self.network_id = network_id
|
||||
self.binding_type = binding_type
|
||||
self.phy_uuid = phy_uuid
|
||||
self.vlan_id = vlan_id
|
||||
|
||||
def __repr__(self):
|
||||
return "<NetworkBinding(%s,%s,%s,%s)>" % (self.network_id,
|
||||
self.binding_type,
|
||||
self.phy_uuid,
|
||||
self.vlan_id)
|
||||
|
||||
|
||||
class NeutronNsxNetworkMapping(model_base.BASEV2):
|
||||
"""Maps neutron network identifiers to NSX identifiers.
|
||||
|
||||
Because of chained logical switches more than one mapping might exist
|
||||
for a single Neutron network.
|
||||
"""
|
||||
__tablename__ = 'neutron_nsx_network_mappings'
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networks.id', ondelete='CASCADE'),
|
||||
primary_key=True)
|
||||
nsx_id = sa.Column(sa.String(36), primary_key=True)
|
||||
|
||||
|
||||
class NeutronNsxSecurityGroupMapping(model_base.BASEV2):
|
||||
"""Backend mappings for Neutron Security Group identifiers.
|
||||
|
||||
This class maps a neutron security group identifier to the corresponding
|
||||
NSX security profile identifier.
|
||||
"""
|
||||
|
||||
__tablename__ = 'neutron_nsx_security_group_mappings'
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('securitygroups.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
nsx_id = sa.Column(sa.String(36), primary_key=True)
|
||||
|
||||
|
||||
class NeutronNsxPortMapping(model_base.BASEV2):
|
||||
"""Represents the mapping between neutron and nsx port uuids."""
|
||||
|
||||
__tablename__ = 'neutron_nsx_port_mappings'
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
nsx_switch_id = sa.Column(sa.String(36))
|
||||
nsx_port_id = sa.Column(sa.String(36), nullable=False)
|
||||
|
||||
def __init__(self, neutron_id, nsx_switch_id, nsx_port_id):
|
||||
self.neutron_id = neutron_id
|
||||
self.nsx_switch_id = nsx_switch_id
|
||||
self.nsx_port_id = nsx_port_id
|
||||
|
||||
|
||||
class NeutronNsxRouterMapping(model_base.BASEV2):
|
||||
"""Maps neutron router identifiers to NSX identifiers."""
|
||||
__tablename__ = 'neutron_nsx_router_mappings'
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('routers.id', ondelete='CASCADE'),
|
||||
primary_key=True)
|
||||
nsx_id = sa.Column(sa.String(36))
|
||||
|
||||
|
||||
class MultiProviderNetworks(model_base.BASEV2):
|
||||
"""Networks provisioned through multiprovider extension."""
|
||||
|
||||
__tablename__ = 'multi_provider_networks'
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networks.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
|
||||
def __init__(self, network_id):
|
||||
self.network_id = network_id
|
||||
|
||||
|
||||
class NetworkConnection(model_base.BASEV2, models_v2.HasTenant):
|
||||
"""Defines a connection between a network gateway and a network."""
|
||||
# We use port_id as the primary key as one can connect a gateway
|
||||
|
|
|
@ -18,7 +18,7 @@ from oslo_db import exception as d_exc
|
|||
from neutron import context
|
||||
from neutron.db import models_v2
|
||||
from neutron.plugins.vmware.dbexts import db as nsx_db
|
||||
from neutron.plugins.vmware.dbexts import models
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ class NsxDBTestCase(testlib_api.SqlTestCase):
|
|||
# Call the method twice to trigger a db duplicate constraint error
|
||||
nsx_db.add_neutron_nsx_port_mapping(
|
||||
self.ctx.session, neutron_port_id, nsx_switch_id, nsx_port_id)
|
||||
result = (self.ctx.session.query(models.NeutronNsxPortMapping).
|
||||
result = (self.ctx.session.query(nsx_models.NeutronNsxPortMapping).
|
||||
filter_by(neutron_id=neutron_port_id).one())
|
||||
self.assertEqual(nsx_port_id, result.nsx_port_id)
|
||||
self.assertEqual(neutron_port_id, result.neutron_id)
|
||||
|
|
|
@ -23,7 +23,7 @@ from neutron.plugins.vmware.api_client import exception as api_exc
|
|||
from neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from neutron.plugins.vmware.common import nsx_utils
|
||||
from neutron.plugins.vmware.common import utils
|
||||
from neutron.plugins.vmware.dbexts import models
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron.plugins.vmware import nsxlib
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit import vmware
|
||||
|
@ -334,12 +334,12 @@ class NsxUtilsTestCase(base.BaseTestCase):
|
|||
self.assertEqual('whatever_tz_2', result_2['zone_uuid'])
|
||||
|
||||
def test_convert_to_nsx_transport_zones_with_bindings(self):
|
||||
binding_1 = models.TzNetworkBinding(
|
||||
binding_1 = nsx_models.TzNetworkBinding(
|
||||
'whatever',
|
||||
utils.NetworkTypes.VLAN,
|
||||
'whatever_tz_1',
|
||||
66)
|
||||
binding_2 = models.TzNetworkBinding(
|
||||
binding_2 = nsx_models.TzNetworkBinding(
|
||||
'whatever',
|
||||
utils.NetworkTypes.STT,
|
||||
'whatever_tz_2',
|
||||
|
|
Loading…
Reference in New Issue