diff --git a/doc/source/command-objects/router.rst b/doc/source/command-objects/router.rst index 13a75158f4..335de17999 100644 --- a/doc/source/command-objects/router.rst +++ b/doc/source/command-objects/router.rst @@ -63,7 +63,7 @@ Create new router os router create [--project [--project-domain ]] [--enable | --disable] - [--distributed] + [--distributed] [--ha] [--description ] [--availability-zone-hint ] @@ -89,6 +89,10 @@ Create new router Create a distributed router +.. option:: --ha + + Create a highly available router + .. option:: --description Set router description diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index cb40d7741b..48a3a92cd3 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -94,7 +94,6 @@ def _get_attrs(client_manager, parsed_args): ).id attrs['tenant_id'] = project_id - # TODO(tangchen): Support getting 'ha' property. # TODO(tangchen): Support getting 'external_gateway_info' property. return attrs @@ -180,10 +179,15 @@ class CreateRouter(command.ShowOne): default=False, help=_("Create a distributed router") ) + parser.add_argument( + '--ha', + action='store_true', + help=_("Create a highly available router") + ) parser.add_argument( '--description', metavar='', - help=_('Set router description') + help=_("Set router description") ) parser.add_argument( '--project', @@ -207,6 +211,8 @@ class CreateRouter(command.ShowOne): client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) + if parsed_args.ha: + attrs['ha'] = parsed_args.ha obj = client.create_router(**attrs) columns = _get_columns(obj) diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py index d12289e15f..6a44586221 100644 --- a/openstackclient/tests/unit/network/v2/test_router.py +++ b/openstackclient/tests/unit/network/v2/test_router.py @@ -166,6 +166,7 @@ class TestCreateRouter(TestRouter): ('name', self.new_router.name), ('enable', True), ('distributed', False), + ('ha', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -178,6 +179,29 @@ class TestCreateRouter(TestRouter): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_create_with_ha_option(self): + arglist = [ + '--ha', + self.new_router.name, + ] + verifylist = [ + ('name', self.new_router.name), + ('enable', True), + ('distributed', False), + ('ha', True), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + + self.network.create_router.assert_called_once_with(**{ + 'admin_state_up': True, + 'name': self.new_router.name, + 'ha': True, + }) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + def test_create_with_AZ_hints(self): arglist = [ self.new_router.name, @@ -189,6 +213,7 @@ class TestCreateRouter(TestRouter): ('availability_zone_hints', ['fake-az', 'fake-az2']), ('enable', True), ('distributed', False), + ('ha', False) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) diff --git a/releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml b/releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml new file mode 100644 index 0000000000..9cdbba49f6 --- /dev/null +++ b/releasenotes/notes/bug-1610161-7c34c7b735701bd4.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--ha`` option to ``router create`` command. + [Bug `1610161 `_] \ No newline at end of file