diff --git a/devstack/lib/vmware_nsx_v b/devstack/lib/vmware_nsx_v index 7a330f4373..3f56dc23f6 100644 --- a/devstack/lib/vmware_nsx_v +++ b/devstack/lib/vmware_nsx_v @@ -102,6 +102,7 @@ function neutron_plugin_configure_service { _nsxv_ini_set nova_metadata_ips "$NSXV_NOVA_METADATA_IPS" _nsxv_ini_set metadata_shared_secret "$NSXV_METADATA_SHARED_SECRET" _nsxv_ini_set edge_ha "$NSXV_EDGE_HA" + _nsxv_ini_set exclusive_router_appliance_size "$NSXV_EXCLUSIVE_ROUTER_APPLIANCE_SIZE" } function neutron_plugin_setup_interface_driver { diff --git a/etc/nsx.ini b/etc/nsx.ini index faf2f2bf8d..643ab12745 100644 --- a/etc/nsx.ini +++ b/etc/nsx.ini @@ -143,6 +143,13 @@ # (Optional) Deploys NSX Edges in HA mode # edge_ha = False + +# (Optional) Edge appliance size to be used for creating exclusive router. +# Valid values: ['compact', 'large', 'xlarge', 'quadlarge'] +# This exclusive_router_appliance_size will be picked up if --router-size +# parameter is not specified while doing neutron router-create +# exclusive_router_appliance_size = compact + # (ListOpt) Ordered list of router_types to allocate as tenant routers. # It limits the router types that the Nsxv can support for tenants: # distributed: router is supported by distributed edge at the backend. diff --git a/vmware_nsx/common/config.py b/vmware_nsx/common/config.py index 6fbae48a3c..dc90fc87a2 100644 --- a/vmware_nsx/common/config.py +++ b/vmware_nsx/common/config.py @@ -324,7 +324,14 @@ nsxv_opts = [ "initialize the metadata infrastructure")), cfg.BoolOpt('edge_ha', default=False, - help=_("Enable HA for NSX Edges")) + help=_("Enable HA for NSX Edges")), + cfg.StrOpt('exclusive_router_appliance_size', + default="compact", + help=_("Edge appliance size to be used for creating exclusive " + "router. Valid values: ['compact', 'large', 'xlarge', " + "'quadlarge']. This edge_appliance_size will be picked " + "up if --router-size parameter is not specified while " + "doing neutron router-create")), ] # Register the configuration options diff --git a/vmware_nsx/extensions/routersize.py b/vmware_nsx/extensions/routersize.py index 1e29f4aece..2ada64a22c 100644 --- a/vmware_nsx/extensions/routersize.py +++ b/vmware_nsx/extensions/routersize.py @@ -17,11 +17,11 @@ from neutron.api.v2 import attributes ROUTER_SIZE = 'router_size' +VALID_EDGE_SIZES = ['compact', 'large', 'xlarge', 'quadlarge'] EXTENDED_ATTRIBUTES_2_0 = { 'routers': { ROUTER_SIZE: {'allow_post': True, 'allow_put': False, - 'validate': {'type:values': ['compact', 'large', - 'xlarge', 'quadlarge']}, + 'validate': {'type:values': VALID_EDGE_SIZES}, 'default': attributes.ATTR_NOT_SPECIFIED, 'is_visible': True}, } diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index e2da5bc3fc..869e9a10f1 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -80,6 +80,7 @@ from vmware_nsx.plugins.nsx_v.vshield import vcns_driver LOG = logging.getLogger(__name__) PORTGROUP_PREFIX = 'dvportgroup' ROUTER_SIZE = routersize.ROUTER_SIZE +VALID_EDGE_SIZES = routersize.VALID_EDGE_SIZES class NsxVPluginV2(agents_db.AgentDbMixin, @@ -1366,7 +1367,16 @@ class NsxVPluginV2(agents_db.AgentDbMixin, raise n_exc.BadRequest(resource="router", msg=msg) elif r.get(ROUTER_SIZE) == attr.ATTR_NOT_SPECIFIED: if r.get('router_type') == nsxv_constants.EXCLUSIVE: - r[ROUTER_SIZE] = nsxv_constants.COMPACT + appliance_size = cfg.CONF.nsxv.exclusive_router_appliance_size + if appliance_size not in VALID_EDGE_SIZES: + msg = (_("Invalid edge size specified in nsx.ini file. " + "Specified value: %(specified)s; " + "Valid values: %(valid)s") % + {'specified': appliance_size, + 'valid': VALID_EDGE_SIZES}) + raise n_exc.BadRequest(resource="router", msg=msg) + else: + r[ROUTER_SIZE] = appliance_size def create_router(self, context, router, allow_metadata=True): self._validate_router_size(router) diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index 11163d8421..6e34757941 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -1850,6 +1850,30 @@ class TestExclusiveRouterTestCase(L3NatTest, L3NatTestCaseBase, router = self.deserialize(self.fmt, res) self.assertEqual(size, router['router']['router_size']) + def test_router_create_overriding_default_edge_size(self): + data = {'router': { + 'tenant_id': 'whatever', + 'name': 'test_router', + 'router_type': 'exclusive'}} + cfg.CONF.set_override('exclusive_router_appliance_size', + 'xlarge', group='nsxv') + router_req = self.new_create_request('routers', data, self.fmt) + res = router_req.get_response(self.ext_api) + router = self.deserialize(self.fmt, res) + self.assertEqual('xlarge', router['router']['router_size']) + + def test_router_create_fails_when_bad_edge_size_specified(self): + data = {'router': { + 'tenant_id': 'whatever', + 'name': 'test_router', + 'router_type': 'exclusive'}} + cfg.CONF.set_override('exclusive_router_appliance_size', + 'foobar', group='nsxv') + router_req = self.new_create_request('routers', data, self.fmt) + res = router_req.get_response(self.ext_api) + router = self.deserialize(self.fmt, res) + self.assertEqual("BadRequest", router['NeutronError']['type']) + def test_router_add_gateway_invalid_network_returns_404(self): # NOTE(salv-orlando): This unit test has been overriden # as the nsx plugin support the ext_gw_mode extension