NSX: Move DB models as part of core vendor decomposition
As part of core vendor decomposition, this patch moves the models from neutron repository to vmware-nsx repository. Change-Id: I99f358af73fd80246aea0c40ecbeb8ce84f5453d Depends-On: I5d5b0acf34417889c2a449f22b92fd105697d90d Partial-bug: #1483453
This commit is contained in:
parent
cdfa26e99c
commit
865fccf9ab
setup.cfg
vmware_nsx/neutron
plugins/vmware
dbexts
db.pylsn_db.pymaclearning.pynetworkgw_db.pynsx_models.pynsxrouter.pynsxv_db.pynsxv_models.pyqos_db.pyvcns_models.pyvnic_index_db.py
plugins
tests/unit/vmware
@ -26,6 +26,8 @@ console_scripts =
|
||||
neutron-check-nsx-config = vmware_nsx.neutron.plugins.vmware.check_nsx_config:main
|
||||
neutron.db.alembic_migrations =
|
||||
vmware-nsx = vmware_nsx.neutron.db.migration:alembic_migrations
|
||||
neutron.core_plugins =
|
||||
vmware = vmware_nsx.neutron.plugins.vmware.plugin:NsxMhPlugin
|
||||
neutron.service_plugins =
|
||||
vmware_nsx_l2gw = vmware_nsx.neutron.services.l2gateway.plugin:NsxL2GatewayPlugin
|
||||
vmware_nsx.neutron.nsxv.router_type_drivers =
|
||||
|
@ -20,7 +20,8 @@ from oslo_utils import excutils
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
import neutron.db.api as db
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -19,8 +19,8 @@ from oslo_db import exception as d_exc
|
||||
from oslo_log import log as logging
|
||||
from sqlalchemy import orm
|
||||
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -17,9 +17,10 @@ from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware.extensions import maclearning as mac
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -17,11 +17,11 @@ from sqlalchemy.orm import exc as sa_orm_exc
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import exceptions
|
||||
from neutron.plugins.common import utils
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware.extensions import networkgw
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
274
vmware_nsx/neutron/plugins/vmware/dbexts/nsx_models.py
Normal file
274
vmware_nsx/neutron/plugins/vmware/dbexts/nsx_models.py
Normal file
@ -0,0 +1,274 @@
|
||||
# Copyright 2015 VMware, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
NSX data models.
|
||||
|
||||
This module defines data models used by the VMware NSX plugin family.
|
||||
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy import sql
|
||||
|
||||
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
|
||||
# to a network in multiple ways (and we cannot use the same port form
|
||||
# more than a single gateway)
|
||||
network_gateway_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networkgateways.id',
|
||||
ondelete='CASCADE'))
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networks.id', ondelete='CASCADE'))
|
||||
segmentation_type = sa.Column(
|
||||
sa.Enum('flat', 'vlan',
|
||||
name='networkconnections_segmentation_type'))
|
||||
segmentation_id = sa.Column(sa.Integer)
|
||||
__table_args__ = (sa.UniqueConstraint(network_gateway_id,
|
||||
segmentation_type,
|
||||
segmentation_id),
|
||||
model_base.BASEV2.__table_args__)
|
||||
# Also, storing port id comes back useful when disconnecting a network
|
||||
# from a gateway
|
||||
port_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete='CASCADE'),
|
||||
primary_key=True)
|
||||
|
||||
|
||||
class NetworkGatewayDeviceReference(model_base.BASEV2):
|
||||
id = sa.Column(sa.String(36), primary_key=True)
|
||||
network_gateway_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networkgateways.id',
|
||||
ondelete='CASCADE'),
|
||||
primary_key=True)
|
||||
interface_name = sa.Column(sa.String(64), primary_key=True)
|
||||
|
||||
|
||||
class NetworkGatewayDevice(model_base.BASEV2, models_v2.HasId,
|
||||
models_v2.HasTenant):
|
||||
nsx_id = sa.Column(sa.String(36))
|
||||
# Optional name for the gateway device
|
||||
name = sa.Column(sa.String(255))
|
||||
# Transport connector type. Not using enum as range of
|
||||
# connector types might vary with backend version
|
||||
connector_type = sa.Column(sa.String(10))
|
||||
# Transport connector IP Address
|
||||
connector_ip = sa.Column(sa.String(64))
|
||||
# operational status
|
||||
status = sa.Column(sa.String(16))
|
||||
|
||||
|
||||
class NetworkGateway(model_base.BASEV2, models_v2.HasId,
|
||||
models_v2.HasTenant):
|
||||
"""Defines the data model for a network gateway."""
|
||||
name = sa.Column(sa.String(255))
|
||||
# Tenant id is nullable for this resource
|
||||
tenant_id = sa.Column(sa.String(36))
|
||||
default = sa.Column(sa.Boolean())
|
||||
devices = orm.relationship(NetworkGatewayDeviceReference,
|
||||
backref='networkgateways',
|
||||
cascade='all,delete')
|
||||
network_connections = orm.relationship(NetworkConnection, lazy='joined')
|
||||
|
||||
|
||||
class MacLearningState(model_base.BASEV2):
|
||||
|
||||
port_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
mac_learning_enabled = sa.Column(sa.Boolean(), nullable=False)
|
||||
|
||||
# Add a relationship to the Port model using the backref attribute.
|
||||
# This will instruct SQLAlchemy to eagerly load this association.
|
||||
port = orm.relationship(
|
||||
models_v2.Port,
|
||||
backref=orm.backref("mac_learning_state", lazy='joined',
|
||||
uselist=False, cascade='delete'))
|
||||
|
||||
|
||||
class LsnPort(models_v2.model_base.BASEV2):
|
||||
|
||||
__tablename__ = 'lsn_port'
|
||||
|
||||
lsn_port_id = sa.Column(sa.String(36), primary_key=True)
|
||||
|
||||
lsn_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('lsn.lsn_id', ondelete="CASCADE"),
|
||||
nullable=False)
|
||||
sub_id = sa.Column(sa.String(36), nullable=False, unique=True)
|
||||
mac_addr = sa.Column(sa.String(32), nullable=False, unique=True)
|
||||
|
||||
def __init__(self, lsn_port_id, subnet_id, mac_address, lsn_id):
|
||||
self.lsn_port_id = lsn_port_id
|
||||
self.lsn_id = lsn_id
|
||||
self.sub_id = subnet_id
|
||||
self.mac_addr = mac_address
|
||||
|
||||
|
||||
class Lsn(models_v2.model_base.BASEV2):
|
||||
__tablename__ = 'lsn'
|
||||
|
||||
lsn_id = sa.Column(sa.String(36), primary_key=True)
|
||||
net_id = sa.Column(sa.String(36), nullable=False)
|
||||
|
||||
def __init__(self, net_id, lsn_id):
|
||||
self.net_id = net_id
|
||||
self.lsn_id = lsn_id
|
||||
|
||||
|
||||
class QoSQueue(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
|
||||
name = sa.Column(sa.String(255))
|
||||
default = sa.Column(sa.Boolean, default=False, server_default=sql.false())
|
||||
min = sa.Column(sa.Integer, nullable=False)
|
||||
max = sa.Column(sa.Integer, nullable=True)
|
||||
qos_marking = sa.Column(sa.Enum('untrusted', 'trusted',
|
||||
name='qosqueues_qos_marking'))
|
||||
dscp = sa.Column(sa.Integer)
|
||||
|
||||
|
||||
class PortQueueMapping(model_base.BASEV2):
|
||||
port_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey("ports.id", ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
|
||||
queue_id = sa.Column(sa.String(36), sa.ForeignKey("qosqueues.id"),
|
||||
primary_key=True)
|
||||
|
||||
# Add a relationship to the Port model adding a backref which will
|
||||
# allow SQLAlchemy for eagerly load the queue binding
|
||||
port = orm.relationship(
|
||||
models_v2.Port,
|
||||
backref=orm.backref("qos_queue", uselist=False,
|
||||
cascade='delete', lazy='joined'))
|
||||
|
||||
|
||||
class NetworkQueueMapping(model_base.BASEV2):
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey("networks.id", ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
|
||||
queue_id = sa.Column(sa.String(36), sa.ForeignKey("qosqueues.id",
|
||||
ondelete="CASCADE"))
|
||||
|
||||
# Add a relationship to the Network model adding a backref which will
|
||||
# allow SQLAlcremy for eagerly load the queue binding
|
||||
network = orm.relationship(
|
||||
models_v2.Network,
|
||||
backref=orm.backref("qos_queue", uselist=False,
|
||||
cascade='delete', lazy='joined'))
|
@ -15,9 +15,10 @@
|
||||
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.extensions import l3
|
||||
from neutron.plugins.vmware.dbexts import nsxv_models
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_models
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
# under the License.
|
||||
|
||||
import neutron.db.api as db
|
||||
from neutron.plugins.vmware.dbexts import nsxv_models
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
@ -24,8 +23,10 @@ from sqlalchemy.orm import exc
|
||||
from sqlalchemy.sql import expression as expr
|
||||
|
||||
from neutron.i18n import _, _LE
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_models
|
||||
from vmware_nsx.neutron.plugins.vmware.vshield.common import constants
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
259
vmware_nsx/neutron/plugins/vmware/dbexts/nsxv_models.py
Normal file
259
vmware_nsx/neutron/plugins/vmware/dbexts/nsxv_models.py
Normal file
@ -0,0 +1,259 @@
|
||||
# Copyright 2015 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.
|
||||
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants
|
||||
|
||||
|
||||
class NsxvRouterBinding(model_base.BASEV2, models_v2.HasStatusDescription):
|
||||
"""Represents the mapping between neutron router and vShield Edge."""
|
||||
|
||||
__tablename__ = 'nsxv_router_bindings'
|
||||
|
||||
# no ForeignKey to routers.id because for now, a router can be removed
|
||||
# from routers when delete_router is executed, but the binding is only
|
||||
# removed after the Edge is deleted
|
||||
router_id = sa.Column(sa.String(36),
|
||||
primary_key=True)
|
||||
edge_id = sa.Column(sa.String(36),
|
||||
nullable=True)
|
||||
lswitch_id = sa.Column(sa.String(36),
|
||||
nullable=True)
|
||||
appliance_size = sa.Column(sa.Enum(
|
||||
nsxv_constants.COMPACT,
|
||||
nsxv_constants.LARGE,
|
||||
nsxv_constants.XLARGE,
|
||||
nsxv_constants.QUADLARGE,
|
||||
name='nsxv_router_bindings_appliance_size'))
|
||||
edge_type = sa.Column(sa.Enum(nsxv_constants.SERVICE_EDGE,
|
||||
nsxv_constants.VDR_EDGE,
|
||||
name='nsxv_router_bindings_edge_type'))
|
||||
|
||||
|
||||
class NsxvEdgeVnicBinding(model_base.BASEV2):
|
||||
"""Represents mapping between vShield Edge vnic and neutron netowrk."""
|
||||
|
||||
__tablename__ = 'nsxv_edge_vnic_bindings'
|
||||
|
||||
edge_id = sa.Column(sa.String(36),
|
||||
primary_key=True)
|
||||
vnic_index = sa.Column(sa.Integer(),
|
||||
primary_key=True)
|
||||
tunnel_index = sa.Column(sa.Integer(),
|
||||
primary_key=True)
|
||||
network_id = sa.Column(sa.String(36), nullable=True)
|
||||
|
||||
|
||||
class NsxvEdgeDhcpStaticBinding(model_base.BASEV2):
|
||||
"""Represents mapping between mac addr and bindingId."""
|
||||
|
||||
__tablename__ = 'nsxv_edge_dhcp_static_bindings'
|
||||
|
||||
edge_id = sa.Column(sa.String(36), primary_key=True)
|
||||
mac_address = sa.Column(sa.String(32), primary_key=True)
|
||||
binding_id = sa.Column(sa.String(36), nullable=False)
|
||||
|
||||
|
||||
class NsxvInternalNetworks(model_base.BASEV2):
|
||||
"""Represents internal networks between NSXV plugin elements."""
|
||||
|
||||
__tablename__ = 'nsxv_internal_networks'
|
||||
|
||||
network_purpose = sa.Column(
|
||||
sa.Enum(nsxv_constants.INTER_EDGE_PURPOSE,
|
||||
name='nsxv_internal_networks_purpose'),
|
||||
primary_key=True)
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey("networks.id", ondelete="CASCADE"),
|
||||
nullable=True)
|
||||
|
||||
|
||||
class NsxvInternalEdges(model_base.BASEV2):
|
||||
"""Represents internal Edge appliances for NSXV plugin operations."""
|
||||
|
||||
__tablename__ = 'nsxv_internal_edges'
|
||||
|
||||
ext_ip_address = sa.Column(sa.String(64), primary_key=True)
|
||||
router_id = sa.Column(sa.String(36), nullable=True)
|
||||
purpose = sa.Column(
|
||||
sa.Enum(nsxv_constants.INTER_EDGE_PURPOSE,
|
||||
name='nsxv_internal_edges_purpose'))
|
||||
|
||||
|
||||
class NsxvSecurityGroupSectionMapping(model_base.BASEV2):
|
||||
"""Backend mappings for Neutron Rule Sections.
|
||||
|
||||
This class maps a neutron security group identifier to the corresponding
|
||||
NSX layer 3 section.
|
||||
"""
|
||||
|
||||
__tablename__ = 'nsxv_security_group_section_mappings'
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('securitygroups.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
ip_section_id = sa.Column(sa.String(100))
|
||||
|
||||
|
||||
class NsxvRuleMapping(model_base.BASEV2):
|
||||
"""Backend mappings for Neutron Rule Sections.
|
||||
|
||||
This class maps a neutron security group identifier to the corresponding
|
||||
NSX layer 3 and layer 2 sections.
|
||||
"""
|
||||
|
||||
__tablename__ = 'nsxv_rule_mappings'
|
||||
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('securitygrouprules.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
nsx_rule_id = sa.Column(sa.String(36), primary_key=True)
|
||||
|
||||
|
||||
class NsxvPortVnicMapping(model_base.BASEV2):
|
||||
"""Maps neutron port to NSXv VM Vnic Id."""
|
||||
|
||||
__tablename__ = 'nsxv_port_vnic_mappings'
|
||||
|
||||
neutron_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
nsx_id = sa.Column(sa.String(42), primary_key=True)
|
||||
|
||||
|
||||
class NsxvRouterExtAttributes(model_base.BASEV2):
|
||||
"""Router attributes managed by NSX plugin extensions."""
|
||||
|
||||
__tablename__ = 'nsxv_router_ext_attributes'
|
||||
|
||||
router_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('routers.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
distributed = sa.Column(sa.Boolean, default=False, nullable=False)
|
||||
router_type = sa.Column(
|
||||
sa.Enum('shared', 'exclusive',
|
||||
name='nsxv_router_type'),
|
||||
default='exclusive', nullable=False)
|
||||
service_router = sa.Column(sa.Boolean, default=False, nullable=False)
|
||||
# Add a relationship to the Router model in order to instruct
|
||||
# SQLAlchemy to eagerly load this association
|
||||
router = orm.relationship(
|
||||
l3_db.Router,
|
||||
backref=orm.backref("nsx_attributes", lazy='joined',
|
||||
uselist=False, cascade='delete'))
|
||||
|
||||
|
||||
class NsxvTzNetworkBinding(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__ = 'nsxv_tz_network_bindings'
|
||||
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networks.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
binding_type = sa.Column(
|
||||
sa.Enum('flat', 'vlan', 'portgroup',
|
||||
name='nsxv_tz_network_bindings_binding_type'),
|
||||
nullable=False, primary_key=True)
|
||||
phy_uuid = sa.Column(sa.String(36), primary_key=True, nullable=True)
|
||||
vlan_id = sa.Column(sa.Integer, primary_key=True, nullable=True,
|
||||
autoincrement=False)
|
||||
|
||||
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 "<NsxvTzNetworkBinding(%s,%s,%s,%s)>" % (self.network_id,
|
||||
self.binding_type,
|
||||
self.phy_uuid,
|
||||
self.vlan_id)
|
||||
|
||||
|
||||
class NsxvPortIndexMapping(model_base.BASEV2):
|
||||
"""Associates attached Neutron ports with the instance VNic index."""
|
||||
|
||||
__tablename__ = 'nsxv_port_index_mappings'
|
||||
|
||||
port_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('ports.id', ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
device_id = sa.Column(sa.String(255), nullable=False)
|
||||
index = sa.Column(sa.Integer, nullable=False)
|
||||
__table_args__ = (sa.UniqueConstraint(device_id, index),
|
||||
model_base.BASEV2.__table_args__)
|
||||
|
||||
# Add a relationship to the Port model in order to instruct SQLAlchemy to
|
||||
# eagerly read port vnic-index
|
||||
port = orm.relationship(
|
||||
models_v2.Port,
|
||||
backref=orm.backref("vnic_index", lazy='joined',
|
||||
uselist=False, cascade='delete'))
|
||||
|
||||
|
||||
class NsxvEdgeFirewallRuleBinding(model_base.BASEV2):
|
||||
"""Mapping between firewall rule and edge firewall rule_id."""
|
||||
|
||||
__tablename__ = 'nsxv_firewall_rule_bindings'
|
||||
|
||||
rule_id = sa.Column(sa.String(36),
|
||||
primary_key=True)
|
||||
edge_id = sa.Column(sa.String(36), primary_key=True)
|
||||
rule_vse_id = sa.Column(sa.String(36))
|
||||
|
||||
|
||||
class NsxvSpoofGuardPolicyNetworkMapping(model_base.BASEV2):
|
||||
"""Mapping between SpoofGuard and neutron networks"""
|
||||
|
||||
__tablename__ = 'nsxv_spoofguard_policy_network_mappings'
|
||||
|
||||
network_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('networks.id', ondelete='CASCADE'),
|
||||
primary_key=True,
|
||||
nullable=False)
|
||||
policy_id = sa.Column(sa.String(36), nullable=False)
|
||||
|
||||
|
||||
class NsxvVdrDhcpBinding(model_base.BASEV2):
|
||||
"""1:1 mapping between VDR and a DHCP Edge."""
|
||||
|
||||
__tablename__ = 'nsxv_vdr_dhcp_bindings'
|
||||
|
||||
vdr_router_id = sa.Column(sa.String(36), primary_key=True)
|
||||
dhcp_router_id = sa.Column(sa.String(36), nullable=False)
|
||||
dhcp_edge_id = sa.Column(sa.String(36), nullable=False)
|
||||
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint(
|
||||
dhcp_router_id,
|
||||
name='unique_nsxv_vdr_dhcp_bindings0dhcp_router_id'),
|
||||
sa.UniqueConstraint(
|
||||
dhcp_edge_id,
|
||||
name='unique_nsxv_vdr_dhcp_bindings0dhcp_edge_id'))
|
@ -18,12 +18,12 @@ from sqlalchemy.orm import exc
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import models_v2
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron.i18n import _LI
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from neutron.i18n import _LI
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware.extensions import qos
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
37
vmware_nsx/neutron/plugins/vmware/dbexts/vcns_models.py
Normal file
37
vmware_nsx/neutron/plugins/vmware/dbexts/vcns_models.py
Normal file
@ -0,0 +1,37 @@
|
||||
# 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.
|
||||
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.db import model_base
|
||||
from neutron.db import models_v2
|
||||
|
||||
|
||||
class VcnsRouterBinding(model_base.BASEV2, models_v2.HasStatusDescription):
|
||||
"""Represents the mapping between neutron router and vShield Edge."""
|
||||
|
||||
__tablename__ = 'vcns_router_bindings'
|
||||
|
||||
# no ForeignKey to routers.id because for now, a router can be removed
|
||||
# from routers when delete_router is executed, but the binding is only
|
||||
# removed after the Edge is deleted
|
||||
router_id = sa.Column(sa.String(36),
|
||||
primary_key=True)
|
||||
edge_id = sa.Column(sa.String(16),
|
||||
nullable=True)
|
||||
lswitch_id = sa.Column(sa.String(36),
|
||||
nullable=False)
|
@ -17,9 +17,10 @@ from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.plugins.vmware.dbexts import nsxv_models
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_models
|
||||
from vmware_nsx.neutron.plugins.vmware.extensions import vnicindex as vnicidx
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -58,7 +58,6 @@ from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron.i18n import _LE, _LI, _LW
|
||||
from neutron.plugins.common import constants as plugin_const
|
||||
from neutron.plugins.common import utils
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
from vmware_nsx.neutron.plugins import vmware
|
||||
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
|
||||
@ -71,6 +70,7 @@ from vmware_nsx.neutron.plugins.vmware.common import utils as c_utils
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import db as nsx_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import maclearning as mac_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import networkgw_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import qos_db
|
||||
from vmware_nsx.neutron.plugins.vmware import dhcpmeta_modes
|
||||
from vmware_nsx.neutron.plugins.vmware.extensions import maclearning as mac_ext
|
||||
@ -2406,18 +2406,18 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
bulk_rule = {'security_group_rules': [security_group_rule]}
|
||||
return self.create_security_group_rule_bulk(context, bulk_rule)[0]
|
||||
|
||||
def create_security_group_rule_bulk(self, context, security_group_rule):
|
||||
def create_security_group_rule_bulk(self, context, security_group_rules):
|
||||
"""Create security group rules.
|
||||
|
||||
:param security_group_rule: list of rules to create
|
||||
"""
|
||||
s = security_group_rule.get('security_group_rules')
|
||||
s = security_group_rules.get('security_group_rules')
|
||||
|
||||
# TODO(arosen) is there anyway we could avoid having the update of
|
||||
# the security group rules in nsx outside of this transaction?
|
||||
with context.session.begin(subtransactions=True):
|
||||
security_group_id = self._validate_security_group_rules(
|
||||
context, security_group_rule)
|
||||
context, security_group_rules)
|
||||
# Check to make sure security group exists
|
||||
security_group = super(NsxPluginV2, self).get_security_group(
|
||||
context, security_group_id)
|
||||
@ -2439,7 +2439,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
combined_rules)
|
||||
return super(
|
||||
NsxPluginV2, self).create_security_group_rule_bulk_native(
|
||||
context, security_group_rule)
|
||||
context, security_group_rules)
|
||||
|
||||
def delete_security_group_rule(self, context, sgrid):
|
||||
"""Delete a security group rule
|
||||
|
@ -1871,17 +1871,17 @@ class NsxVPluginV2(agents_db.AgentDbMixin,
|
||||
bulk_rule = {'security_group_rules': [security_group_rule]}
|
||||
return self.create_security_group_rule_bulk(context, bulk_rule)[0]
|
||||
|
||||
def create_security_group_rule_bulk(self, context, security_group_rule):
|
||||
def create_security_group_rule_bulk(self, context, security_group_rules):
|
||||
"""Create security group rules.
|
||||
|
||||
:param security_group_rule: list of rules to create
|
||||
:param security_group_rules: list of rules to create
|
||||
"""
|
||||
ruleids = set()
|
||||
nsx_rules = []
|
||||
|
||||
self._validate_security_group_rules(context, security_group_rule)
|
||||
self._validate_security_group_rules(context, security_group_rules)
|
||||
# Translating Neutron rules to Nsx DFW rules
|
||||
for r in security_group_rule['security_group_rules']:
|
||||
for r in security_group_rules['security_group_rules']:
|
||||
rule = r['security_group_rule']
|
||||
rule['id'] = uuidutils.generate_uuid()
|
||||
ruleids.add(rule['id'])
|
||||
@ -1904,7 +1904,7 @@ class NsxVPluginV2(agents_db.AgentDbMixin,
|
||||
with context.session.begin(subtransactions=True):
|
||||
new_rule_list = super(
|
||||
NsxVPluginV2, self).create_security_group_rule_bulk_native(
|
||||
context, security_group_rule)
|
||||
context, security_group_rules)
|
||||
for pair in rule_pairs:
|
||||
neutron_rule_id = pair['neutron_id']
|
||||
nsx_rule_id = pair['nsx_id']
|
||||
|
@ -18,11 +18,11 @@ from oslo_config import cfg
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.plugins.vmware.dbexts import nsxv_models
|
||||
from oslo_log import log as logging
|
||||
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.common import locking
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_models
|
||||
from vmware_nsx.neutron.plugins.vmware.plugins import nsx_v
|
||||
from vmware_nsx.neutron.plugins.vmware.plugins.nsx_v_drivers import (
|
||||
abstract_router_driver as router_driver)
|
||||
|
@ -14,12 +14,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
from neutron import context
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron.tests.unit import testlib_api
|
||||
from sqlalchemy import orm
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import lsn_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
|
||||
class LSNTestCase(testlib_api.SqlTestCase):
|
||||
|
@ -13,13 +13,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_db import exception as d_exc
|
||||
|
||||
from neutron import context
|
||||
from neutron.db import models_v2
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron.tests.unit import testlib_api
|
||||
from oslo_db import exception as d_exc
|
||||
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import db as nsx_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
|
||||
|
||||
class NsxDBTestCase(testlib_api.SqlTestCase):
|
||||
|
@ -25,7 +25,6 @@ from neutron import context
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron import manager
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron import quota
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.api import test_extensions
|
||||
@ -35,6 +34,7 @@ from neutron.tests.unit.db import test_db_base_plugin_v2 as test_db_plugin
|
||||
from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import networkgw_db
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware.extensions import networkgw
|
||||
from vmware_nsx.neutron.plugins.vmware import nsxlib
|
||||
from vmware_nsx.neutron.plugins.vmware.nsxlib import l2gateway as l2gwlib
|
||||
|
@ -17,7 +17,6 @@ import mock
|
||||
from neutron.db import api as db_api
|
||||
from neutron.extensions import multiprovidernet as mpnet
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.plugins.vmware.dbexts import nsx_models
|
||||
from neutron.tests import base
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
@ -25,6 +24,7 @@ from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc
|
||||
from vmware_nsx.neutron.plugins.vmware.common import nsx_utils
|
||||
from vmware_nsx.neutron.plugins.vmware.common import utils
|
||||
from vmware_nsx.neutron.plugins.vmware.dbexts import nsx_models
|
||||
from vmware_nsx.neutron.plugins.vmware import nsxlib
|
||||
from vmware_nsx.neutron.tests.unit import vmware
|
||||
from vmware_nsx.neutron.tests.unit.vmware.nsxlib import base as nsx_base
|
||||
|
Loading…
x
Reference in New Issue
Block a user