use extra route api def from lib
Commit I0425384d5fd6864f336bd7a5c9a5e70f2b3568ff rehomed the extra route extension's API defintion to neutron-lib. This patch consumes it updating the code to use lib's implementation. NeutronLibImpact Change-Id: Iae3bd4f15e12c401e615cc06358b376b81b53dc5
This commit is contained in:
parent
c4b47529c7
commit
5319522bff
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import netaddr
|
||||
from neutron_lib.exceptions import extraroute as xroute_exc
|
||||
from neutron_lib.utils import helpers
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -24,7 +25,6 @@ from neutron.conf.db import extraroute_db
|
|||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.extensions import extraroute
|
||||
from neutron.extensions import l3
|
||||
from neutron.objects import router as l3_obj
|
||||
|
||||
|
@ -68,19 +68,19 @@ class ExtraRoute_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
|
|||
# so we need to check
|
||||
# nexthop belongs to one of cidrs of the router ports
|
||||
if not netaddr.all_matching_cidrs(nexthop, cidrs):
|
||||
raise extraroute.InvalidRoutes(
|
||||
raise xroute_exc.InvalidRoutes(
|
||||
routes=routes,
|
||||
reason=_('the nexthop is not connected with router'))
|
||||
#Note(nati) nexthop should not be same as fixed_ips
|
||||
if nexthop in ips:
|
||||
raise extraroute.InvalidRoutes(
|
||||
raise xroute_exc.InvalidRoutes(
|
||||
routes=routes,
|
||||
reason=_('the nexthop is used by router'))
|
||||
|
||||
def _validate_routes(self, context,
|
||||
router_id, routes):
|
||||
if len(routes) > cfg.CONF.max_routes:
|
||||
raise extraroute.RoutesExhausted(
|
||||
raise xroute_exc.RoutesExhausted(
|
||||
router_id=router_id,
|
||||
quota=cfg.CONF.max_routes)
|
||||
|
||||
|
@ -139,7 +139,7 @@ class ExtraRoute_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin):
|
|||
extra_routes = self._get_extra_routes_by_router_id(context, router_id)
|
||||
for route in extra_routes:
|
||||
if netaddr.all_matching_cidrs(route['nexthop'], [subnet_cidr]):
|
||||
raise extraroute.RouterInterfaceInUseByRoute(
|
||||
raise xroute_exc.RouterInterfaceInUseByRoute(
|
||||
router_id=router_id, subnet_id=subnet_id)
|
||||
|
||||
|
||||
|
|
|
@ -13,61 +13,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api import converters
|
||||
from neutron_lib.api.definitions import extraroute as apidef
|
||||
from neutron_lib.api import extensions
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as nexception
|
||||
|
||||
from neutron._i18n import _
|
||||
|
||||
|
||||
# Extra Routes Exceptions
|
||||
class InvalidRoutes(nexception.InvalidInput):
|
||||
message = _("Invalid format for routes: %(routes)s, %(reason)s")
|
||||
|
||||
|
||||
class RouterInterfaceInUseByRoute(nexception.InUse):
|
||||
message = _("Router interface for subnet %(subnet_id)s on router "
|
||||
"%(router_id)s cannot be deleted, as it is required "
|
||||
"by one or more routes.")
|
||||
|
||||
|
||||
class RoutesExhausted(nexception.BadRequest):
|
||||
message = _("Unable to complete operation for %(router_id)s. "
|
||||
"The number of routes exceeds the maximum %(quota)s.")
|
||||
|
||||
# Attribute Map
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'routers': {
|
||||
'routes': {'allow_post': False, 'allow_put': True,
|
||||
'validate': {'type:hostroutes': None},
|
||||
'convert_to': converters.convert_none_to_empty_list,
|
||||
'is_visible': True,
|
||||
'default': constants.ATTR_NOT_SPECIFIED},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Extraroute(extensions.ExtensionDescriptor):
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Neutron Extra Route"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "extraroute"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Extra routes configuration for L3 router"
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2013-02-01T10:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
||||
class Extraroute(extensions.APIExtensionDescriptor):
|
||||
api_definition = apidef
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import copy
|
||||
|
||||
from neutron_lib.api.definitions import extraroute as xroute_apidef
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.utils import helpers
|
||||
|
@ -23,7 +24,6 @@ from oslo_utils import uuidutils
|
|||
from webob import exc
|
||||
|
||||
from neutron.db import extraroute_db
|
||||
from neutron.extensions import extraroute
|
||||
from neutron.extensions import l3
|
||||
from neutron.tests.unit.api.v2 import test_base
|
||||
from neutron.tests.unit.extensions import test_l3
|
||||
|
@ -36,7 +36,7 @@ _get_path = test_base._get_path
|
|||
class ExtraRouteTestExtensionManager(object):
|
||||
|
||||
def get_resources(self):
|
||||
l3.L3().update_attributes_map(extraroute.EXTENDED_ATTRIBUTES_2_0)
|
||||
l3.L3().update_attributes_map(xroute_apidef.RESOURCE_ATTRIBUTE_MAP)
|
||||
return l3.L3.get_resources()
|
||||
|
||||
def get_actions(self):
|
||||
|
@ -49,14 +49,15 @@ class ExtraRouteTestExtensionManager(object):
|
|||
# This plugin class is for tests with plugin that integrates L3.
|
||||
class TestExtraRouteIntPlugin(test_l3.TestL3NatIntPlugin,
|
||||
extraroute_db.ExtraRoute_db_mixin):
|
||||
supported_extension_aliases = ["external-net", "router", "extraroute"]
|
||||
supported_extension_aliases = ["external-net", "router",
|
||||
xroute_apidef.ALIAS]
|
||||
|
||||
|
||||
# A fake l3 service plugin class with extra route capability for
|
||||
# plugins that delegate away L3 routing functionality
|
||||
class TestExtraRouteL3NatServicePlugin(test_l3.TestL3NatServicePlugin,
|
||||
extraroute_db.ExtraRoute_db_mixin):
|
||||
supported_extension_aliases = ["router", "extraroute"]
|
||||
supported_extension_aliases = ["router", xroute_apidef.ALIAS]
|
||||
|
||||
|
||||
class ExtraRouteDBTestCaseBase(object):
|
||||
|
|
Loading…
Reference in New Issue