From 791cb44ddf3dc3bdb77ad7bdb8dcf849525c1a59 Mon Sep 17 00:00:00 2001 From: Zhenmei Date: Tue, 24 Nov 2015 21:38:33 -0500 Subject: [PATCH] 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 --- vmware_nsx/common/exceptions.py | 4 ++++ vmware_nsx/services/l2gateway/nsx_v/driver.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/common/exceptions.py b/vmware_nsx/common/exceptions.py index be39f76548..d5f4e2a10c 100644 --- a/vmware_nsx/common/exceptions.py +++ b/vmware_nsx/common/exceptions.py @@ -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") diff --git a/vmware_nsx/services/l2gateway/nsx_v/driver.py b/vmware_nsx/services/l2gateway/nsx_v/driver.py index d7446b1663..be5891c217 100644 --- a/vmware_nsx/services/l2gateway/nsx_v/driver.py +++ b/vmware_nsx/services/l2gateway/nsx_v/driver.py @@ -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)