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)