diff --git a/vmware_nsx/plugins/common/plugin.py b/vmware_nsx/plugins/common/plugin.py index 441c5c5ad6..a323fc4adf 100644 --- a/vmware_nsx/plugins/common/plugin.py +++ b/vmware_nsx/plugins/common/plugin.py @@ -27,6 +27,9 @@ from neutron_lib.api.definitions import network as net_def from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import subnet as subnet_def from neutron_lib.api import validators +from neutron_lib.callbacks import events +from neutron_lib.callbacks import registry +from neutron_lib.callbacks import resources from neutron_lib import constants from neutron_lib import context as n_context from neutron_lib import exceptions as n_exc @@ -308,3 +311,24 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2, "with no subnet") % network_id raise n_exc.BadRequest(resource='router', msg=msg) return gw_info + + def get_subnets_by_network(self, context, network_id): + return [self._make_subnet_dict(subnet_obj) for subnet_obj in + self._get_subnets_by_network(context.elevated(), network_id)] + + +# Register the callback +def _validate_network_has_subnet(resource, event, trigger, **kwargs): + network_id = kwargs.get('network_id') + subnets = kwargs.get('subnets') + if not subnets: + msg = _('No subnet defined on network %s') % network_id + raise n_exc.InvalidInput(error_message=msg) + + +def subscribe(): + registry.subscribe(_validate_network_has_subnet, + resources.ROUTER_GATEWAY, events.BEFORE_CREATE) + + +subscribe() diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 64060f5e7f..c424fc28cf 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -4525,20 +4525,3 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, if not self._nsx_policy_is_hidden(policy): results.append(self._nsx_policy_to_dict(policy)) return results - - -# Register the callback -def _validate_network_has_subnet(resource, event, trigger, **kwargs): - network_id = kwargs.get('network_id') - subnets = kwargs.get('subnets') - if not subnets: - msg = _('No subnet defined on network %s') % network_id - raise n_exc.InvalidInput(error_message=msg) - - -def subscribe(): - registry.subscribe(_validate_network_has_subnet, - resources.ROUTER_GATEWAY, events.BEFORE_CREATE) - - -subscribe()