Skip to content

Commit 62d71aa

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Allow override of distributed router flag"
2 parents b168f2d + fe59e33 commit 62d71aa

4 files changed

Lines changed: 60 additions & 6 deletions

File tree

doc/source/command-objects/router.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Create new router
6363
openstack router create
6464
[--project <project> [--project-domain <project-domain>]]
6565
[--enable | --disable]
66-
[--distributed]
66+
[--distributed | --centralized]
6767
[--ha | --no-ha]
6868
[--description <description>]
6969
[--availability-zone-hint <availability-zone>]
@@ -90,6 +90,19 @@ Create new router
9090
9191
Create a distributed router
9292
93+
The default router type (distributed vs centralized) is determined by a
94+
configuration setting in the OpenStack deployment. Since we are unable
95+
to know that default wihtout attempting to actually create a router it
96+
is suggested to use either :option:`--distributed` or :option:`--centralized`
97+
in situations where multiple cloud deployments may be used.
98+
99+
.. option:: --centralized
100+
101+
Create a centralized router
102+
103+
See the note in :option:`--distributed` regarding the default used when
104+
creating a new router.
105+
93106
.. option:: --ha
94107
95108
Create a highly available router

openstackclient/network/v2/router.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def _get_attrs(client_manager, parsed_args):
7878
attrs['admin_state_up'] = True
7979
if parsed_args.disable:
8080
attrs['admin_state_up'] = False
81-
# centralized is available only for SetRouter and not for CreateRouter
82-
if 'centralized' in parsed_args and parsed_args.centralized:
81+
if parsed_args.centralized:
8382
attrs['distributed'] = False
8483
if parsed_args.distributed:
8584
attrs['distributed'] = True
@@ -176,13 +175,17 @@ def get_parser(self, prog_name):
176175
action='store_true',
177176
help=_("Disable router")
178177
)
179-
parser.add_argument(
178+
distribute_group = parser.add_mutually_exclusive_group()
179+
distribute_group.add_argument(
180180
'--distributed',
181-
dest='distributed',
182181
action='store_true',
183-
default=False,
184182
help=_("Create a distributed router")
185183
)
184+
distribute_group.add_argument(
185+
'--centralized',
186+
action='store_true',
187+
help=_("Create a centralized router")
188+
)
186189
ha_group = parser.add_mutually_exclusive_group()
187190
ha_group.add_argument(
188191
'--ha',

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@ def test_create_with_ha_option(self):
211211
def test_create_with_no_ha_option(self):
212212
self._test_create_with_ha_options('--no-ha', False)
213213

214+
def _test_create_with_distributed_options(self, option, distributed):
215+
arglist = [
216+
option,
217+
self.new_router.name,
218+
]
219+
verifylist = [
220+
('name', self.new_router.name),
221+
('enable', True),
222+
('distributed', distributed),
223+
('centralized', not distributed),
224+
]
225+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
226+
227+
columns, data = (self.cmd.take_action(parsed_args))
228+
229+
self.network.create_router.assert_called_once_with(**{
230+
'admin_state_up': True,
231+
'name': self.new_router.name,
232+
'distributed': distributed,
233+
})
234+
self.assertEqual(self.columns, columns)
235+
self.assertEqual(self.data, data)
236+
237+
def test_create_with_distributed_option(self):
238+
self._test_create_with_distributed_options('--distributed', True)
239+
240+
def test_create_with_centralized_option(self):
241+
self._test_create_with_distributed_options('--centralized', False)
242+
214243
def test_create_with_AZ_hints(self):
215244
arglist = [
216245
self.new_router.name,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
fixes:
3+
- |
4+
Allow users to create centralized (distributed=False)
5+
routers using the ``--centralized`` option in ``router create``.
6+
Without this, routers are created based on the default
7+
neutron configuration of the deployment, which, for example,
8+
could be 'distributed'.
9+
[Bug `1664255 <https://bugs.launchpad.net/bugs/1664255>`_]

0 commit comments

Comments
 (0)