Skip to content

Commit e2fc436

Browse files
committed
Add --ha option to os router create command
This patch added --ha option which the 'os router create' command was missed. Change-Id: I77635fb17af32beb0d8ed9aa080ef79285719fdc Closes-Bug: #1610161
1 parent 15069ef commit e2fc436

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

doc/source/command-objects/router.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Create new router
6363
os router create
6464
[--project <project> [--project-domain <project-domain>]]
6565
[--enable | --disable]
66-
[--distributed]
66+
[--distributed] [--ha]
6767
[--description <description>]
6868
[--availability-zone-hint <availability-zone>]
6969
<name>
@@ -89,6 +89,10 @@ Create new router
8989
9090
Create a distributed router
9191
92+
.. option:: --ha
93+
94+
Create a highly available router
95+
9296
.. option:: --description <description>
9397
9498
Set router description

openstackclient/network/v2/router.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def _get_attrs(client_manager, parsed_args):
9494
).id
9595
attrs['tenant_id'] = project_id
9696

97-
# TODO(tangchen): Support getting 'ha' property.
9897
# TODO(tangchen): Support getting 'external_gateway_info' property.
9998

10099
return attrs
@@ -180,10 +179,15 @@ def get_parser(self, prog_name):
180179
default=False,
181180
help=_("Create a distributed router")
182181
)
182+
parser.add_argument(
183+
'--ha',
184+
action='store_true',
185+
help=_("Create a highly available router")
186+
)
183187
parser.add_argument(
184188
'--description',
185189
metavar='<description>',
186-
help=_('Set router description')
190+
help=_("Set router description")
187191
)
188192
parser.add_argument(
189193
'--project',
@@ -207,6 +211,8 @@ def take_action(self, parsed_args):
207211
client = self.app.client_manager.network
208212

209213
attrs = _get_attrs(self.app.client_manager, parsed_args)
214+
if parsed_args.ha:
215+
attrs['ha'] = parsed_args.ha
210216
obj = client.create_router(**attrs)
211217

212218
columns = _get_columns(obj)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def test_create_default_options(self):
166166
('name', self.new_router.name),
167167
('enable', True),
168168
('distributed', False),
169+
('ha', False),
169170
]
170171
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
171172

@@ -178,6 +179,29 @@ def test_create_default_options(self):
178179
self.assertEqual(self.columns, columns)
179180
self.assertEqual(self.data, data)
180181

182+
def test_create_with_ha_option(self):
183+
arglist = [
184+
'--ha',
185+
self.new_router.name,
186+
]
187+
verifylist = [
188+
('name', self.new_router.name),
189+
('enable', True),
190+
('distributed', False),
191+
('ha', True),
192+
]
193+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
194+
195+
columns, data = (self.cmd.take_action(parsed_args))
196+
197+
self.network.create_router.assert_called_once_with(**{
198+
'admin_state_up': True,
199+
'name': self.new_router.name,
200+
'ha': True,
201+
})
202+
self.assertEqual(self.columns, columns)
203+
self.assertEqual(self.data, data)
204+
181205
def test_create_with_AZ_hints(self):
182206
arglist = [
183207
self.new_router.name,
@@ -189,6 +213,7 @@ def test_create_with_AZ_hints(self):
189213
('availability_zone_hints', ['fake-az', 'fake-az2']),
190214
('enable', True),
191215
('distributed', False),
216+
('ha', False)
192217
]
193218
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
194219

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--ha`` option to ``router create`` command.
5+
[Bug `1610161 <https://bugs.launchpad.net/bugs/1610161>`_]

0 commit comments

Comments
 (0)