summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodion Tikunov <rtikunov@mirantis.com>2016-11-08 17:34:22 +0300
committerRodion Tikunov <rtikunov@mirantis.com>2016-11-25 12:16:00 +0000
commit40b55be84e34083d272ff905457d03f4154571e3 (patch)
treeb815cfcb3534d847f85959c8b4828687312deaee
parentf3a9d40fc811290f9ac427fd03abae72c3b07cdf (diff)
downloadpython-neutronclient-40b55be84e34083d272ff905457d03f4154571e3.tar.gz
Added --enable-snat option for router-gateway-set
If enable_snat_by_default option set to false and disable snat via cli it becomes unavailable to enable snat again. This commit allows to enable snat after disabling it. Change-Id: I01009d5cd5edd5be3eead615c37d6aa2e3224442 Closes-Bug: #1598171 (cherry picked from commit cc1d3fdd3582b0bbc2e24b65b9c690b5f0318148)
-rw-r--r--neutronclient/neutron/v2_0/router.py5
-rw-r--r--neutronclient/tests/unit/test_cli20_router.py12
2 files changed, 17 insertions, 0 deletions
diff --git a/neutronclient/neutron/v2_0/router.py b/neutronclient/neutron/v2_0/router.py
index 5eba1f2..caf7831 100644
--- a/neutronclient/neutron/v2_0/router.py
+++ b/neutronclient/neutron/v2_0/router.py
@@ -221,6 +221,9 @@ class SetGatewayRouter(neutronV20.NeutronCommand):
'external_network', metavar='EXTERNAL-NETWORK',
help=_('ID or name of the external network for the gateway.'))
parser.add_argument(
+ '--enable-snat', action='store_true',
+ help=_('Enable source NAT on the router gateway.'))
+ parser.add_argument(
'--disable-snat', action='store_true',
help=_('Disable source NAT on the router gateway.'))
parser.add_argument(
@@ -242,6 +245,8 @@ class SetGatewayRouter(neutronV20.NeutronCommand):
_ext_net_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, 'network', parsed_args.external_network)
router_dict = {'network_id': _ext_net_id}
+ if parsed_args.enable_snat:
+ router_dict['enable_snat'] = True
if parsed_args.disable_snat:
router_dict['enable_snat'] = False
if parsed_args.fixed_ip:
diff --git a/neutronclient/tests/unit/test_cli20_router.py b/neutronclient/tests/unit/test_cli20_router.py
index 66372f8..7e2bb64 100644
--- a/neutronclient/tests/unit/test_cli20_router.py
+++ b/neutronclient/tests/unit/test_cli20_router.py
@@ -345,6 +345,18 @@ class CLITestV20RouterJSON(test_cli20.CLITestV20Base):
{"network_id": "externalid"}}
)
+ def test_set_gateway_enable_snat(self):
+ # enable external gateway for router: myid externalid.
+ resource = 'router'
+ cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
+ args = ['myid', 'externalid', '--enable-snat']
+ self._test_update_resource(resource, cmd, 'myid',
+ args,
+ {"external_gateway_info":
+ {"network_id": "externalid",
+ "enable_snat": True}}
+ )
+
def test_set_gateway_disable_snat(self):
# set external gateway for router: myid externalid.
resource = 'router'