Add extension "router-enable-snat"

This new extension exposes the "enable_snat" flag of a router. The
"enable_snat" flag can be updated using the external gateway API
commands. However this is a router global configuration property
that is stored directly on the router register. As described in the
``update-external-gateways-of-router`` API section [1]:

  "The enable_snat field does not have any effect for extra gateways
  except for the first external gateway in the list."

[1]https://docs.openstack.org/api-ref/network/v2/index.html#update-external-gateways-of-router

Related-Bug: #2124252
Signed-off-by: Rodolfo Alonso Hernandez <ralonsoh@redhat.com>
Change-Id: I0ab856f56ff4e03cfff30075de938ae7178ebbff
This commit is contained in:
Rodolfo Alonso Hernandez
2025-09-18 09:45:55 +00:00
parent 718b9c07aa
commit 7e78006e5a
4 changed files with 82 additions and 0 deletions

View File

@@ -161,6 +161,13 @@ enable or disable automatic configuration of BFD for default routes of a router
created based on the default gateways of subnets accessible from a router's
gateway ports (see ``enable-default-route-ecmp`` extension).
Router exposes the "enable_snat" flag extension (``router-enable-snat``)
========================================================================
The ``router-enable-snat`` extension exposes, via the API, the router property
flag "enable_snat". This flag can be set during the router creation but can
only be modified using the external gateway API commands.
List routers
============
@@ -211,6 +218,7 @@ Response Parameters
- description: description
- admin_state_up: admin_state_up
- status: router-status
- enable_snat: router-enable_snat
- external_gateway_info: router-external_gateway_info
- external_gateways: router-external_gateways
- revision_number: revision_number
@@ -298,6 +306,7 @@ Response Parameters
- description: description
- admin_state_up: admin_state_up
- status: router-status
- enable_snat: router-enable_snat
- external_gateway_info: router-external_gateway_info
- external_gateways: router-external_gateways
- revision_number: revision_number
@@ -358,6 +367,7 @@ Response Parameters
- description: description
- admin_state_up: admin_state_up
- status: router-status
- enable_snat: router-enable_snat
- external_gateway_info: router-external_gateway_info
- external_gateways: router-external_gateways
- revision_number: revision_number
@@ -436,6 +446,7 @@ Response Parameters
- description: description
- admin_state_up: admin_state_up
- status: router-status
- enable_snat: router-enable_snat
- external_gateway_info: router-external_gateway_info
- external_gateways: router-external_gateways
- revision_number: revision_number

View File

@@ -131,6 +131,7 @@ from neutron_lib.api.definitions import rbac_subnetpool
from neutron_lib.api.definitions import revisionifmatch
from neutron_lib.api.definitions import router_admin_state_down_before_update
from neutron_lib.api.definitions import router_availability_zone
from neutron_lib.api.definitions import router_enable_snat
from neutron_lib.api.definitions import router_interface_fip
from neutron_lib.api.definitions import routerservicetype
from neutron_lib.api.definitions import security_groups_normalized_cidr
@@ -295,6 +296,7 @@ _ALL_API_DEFINITIONS = {
revisionifmatch,
router_admin_state_down_before_update,
router_availability_zone,
router_enable_snat,
router_interface_fip,
routerservicetype,
security_groups_normalized_cidr,

View File

@@ -0,0 +1,47 @@
# Copyright (c) 2025 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.api import converters
from neutron_lib.api.definitions import l3
ENABLE_SNAT = 'enable_snat'
ALIAS = 'router-enable-snat'
IS_SHIM_EXTENSION = False
IS_STANDARD_ATTR_EXTENSION = False
NAME = 'Exposes the router "enable_snat" read-only configuration flag'
API_PREFIX = ''
DESCRIPTION = 'Exposes the router "enable_snat" read-only configuration flag'
UPDATED_TIMESTAMP = '2025-09-18T18:00:00-00:00'
RESOURCE_NAME = l3.ROUTER
COLLECTION_NAME = l3.ROUTERS
RESOURCE_ATTRIBUTE_MAP = {
COLLECTION_NAME: {
ENABLE_SNAT: {'allow_post': False,
'allow_put': False,
'default': True,
'convert_to': converters.convert_to_boolean,
'required_by_policy': True,
'is_filter': True,
'is_sort_key': True,
'is_visible': True
},
},
}
SUB_RESOURCE_ATTRIBUTE_MAP = {}
ACTION_MAP = {}
REQUIRED_EXTENSIONS = []
OPTIONAL_EXTENSIONS = []
ACTION_STATUS = {}

View File

@@ -0,0 +1,22 @@
# Copyright 2025 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.api.definitions import router_enable_snat
from neutron_lib.tests.unit.api.definitions import base
class RouterEnableSnatTestCase(base.DefinitionBaseTestCase):
extension_module = router_enable_snat
extension_resources = (router_enable_snat.COLLECTION_NAME,)
extension_attributes = (router_enable_snat.ENABLE_SNAT,)