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 cc1d3fdd35)
This commit is contained in:
Rodion Tikunov 2016-11-08 17:34:22 +03:00
parent f3a9d40fc8
commit 40b55be84e
2 changed files with 17 additions and 0 deletions

View File

@ -220,6 +220,9 @@ class SetGatewayRouter(neutronV20.NeutronCommand):
parser.add_argument(
'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.'))
@ -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:

View File

@ -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'