Check if l2gw has been used before creating l2gw-connection

Only single vlan is supported for one l2 gateway edge, so only one bridge can be created
in one edge. If user tried to connect multiple network to one l2gw
, the exception will be raised.

Change-Id: Ib17174b9735ca536b3701fdba4212123d51a0b23
This commit is contained in:
Zhenmei 2015-11-24 21:38:33 -05:00
parent 5fef099084
commit 791cb44ddf
2 changed files with 9 additions and 1 deletions

View File

@ -151,3 +151,7 @@ class NsxL2GWConnectionMappingNotFound(n_exc.NotFound):
class NsxL2GWDeviceNotFound(n_exc.NotFound):
message = _('Unable to find logical L2 gateway device.')
class NsxL2GWInUse(n_exc.InUse):
message = _("L2 Gateway '%(gateway_id)s' has been used")

View File

@ -112,12 +112,16 @@ class NsxvL2GatewayDriver(l2gateway_db.L2GatewayMixin):
"""Create a L2 gateway connection."""
gw_connection = l2_gateway_connection.get(l2gw_const.
CONNECTION_RESOURCE_NAME)
l2gw_id = gw_connection.get(l2gw_const.L2GATEWAY_ID)
gw_db = self._get_l2_gateway(context, l2gw_id)
if gw_db.network_connections:
raise nsx_exc.NsxL2GWInUse(gateway_id=l2gw_id)
l2gw_connection = super(
NsxvL2GatewayDriver, self).create_l2_gateway_connection(
context, l2_gateway_connection)
network_id = gw_connection.get('network_id')
virtual_wire = nsx_db.get_nsx_switch_ids(context.session, network_id)
l2gw_id = gw_connection.get(l2gw_const.L2GATEWAY_ID)
# In NSX-v, there will be only one device configured per L2 gateway.
# The name of the device shall carry the backend DLR.
device = self._get_device(context, l2gw_id)