Skip to content

Commit 4a5bf8d

Browse files
committed
Add support for clearing router gateway
This patch adds the support to clear the gateway information from a router. Change-Id: I446c556750f080a6fc21fea8f531fd71838d648a Implements: blueprint neutron-client-advanced-router Partially-Implements: blueprint network-commands-options
1 parent e51a2b3 commit 4a5bf8d

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

doc/source/command-objects/router.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ Unset router properties
318318
319319
os router unset
320320
[--route destination=<subnet>,gateway=<ip-address>]
321+
[--external-gateway]
321322
<router>
322323
323324
.. option:: --route destination=<subnet>,gateway=<ip-address>
@@ -327,6 +328,10 @@ Unset router properties
327328
gateway: nexthop IP address
328329
(repeat option to unset multiple routes)
329330
331+
.. option:: --external-gateway
332+
333+
Remove external gateway information from the router
334+
330335
.. _router_unset-router:
331336
.. describe:: <router>
332337

openstackclient/network/v2/router.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ def get_parser(self, prog_name):
621621
"destination: destination subnet (in CIDR notation) "
622622
"gateway: nexthop IP address "
623623
"(repeat option to unset multiple routes)"))
624+
parser.add_argument(
625+
'--external-gateway',
626+
action='store_true',
627+
default=False,
628+
help=_("Remove external gateway information from the router"))
624629
parser.add_argument(
625630
'router',
626631
metavar="<router>",
@@ -642,5 +647,7 @@ def take_action(self, parsed_args):
642647
msg = (_("Router does not contain route %s") % route)
643648
raise exceptions.CommandError(msg)
644649
attrs['routes'] = tmp_routes
650+
if parsed_args.external_gateway:
651+
attrs['external_gateway_info'] = {}
645652
if attrs:
646653
client.update_router(obj, **attrs)

openstackclient/tests/unit/network/v2/test_router.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,3 +1021,16 @@ def test_unset_router_wrong_routes(self):
10211021
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
10221022
self.assertRaises(exceptions.CommandError,
10231023
self.cmd.take_action, parsed_args)
1024+
1025+
def test_unset_router_external_gateway(self):
1026+
arglist = [
1027+
'--external-gateway',
1028+
self._testrouter.name,
1029+
]
1030+
verifylist = [('external_gateway', True)]
1031+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1032+
result = self.cmd.take_action(parsed_args)
1033+
attrs = {'external_gateway_info': {}}
1034+
self.network.update_router.assert_called_once_with(
1035+
self._testrouter, **attrs)
1036+
self.assertIsNone(result)

releasenotes/notes/router-gateway-set-01d9c7ffe4461daf.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ features:
33
- |
44
Add support for setting the gateway information in a router,
55
by introducing the new option ``--external-gateway`` in
6-
``router set`` CLI.
6+
``router set`` command and clearing the gateway information in a router
7+
by introducing ``--external-gateway`` option in ``router unset`` command.
78
[ Blueprint `neutron-client-advanced-router <https://blueprints.launchpad.net/python-openstackclient/+spec/neutron-client-advanced-router>`_]

0 commit comments

Comments
 (0)