diff --git a/doc/source/command-objects/router.rst b/doc/source/command-objects/router.rst index 952415a8ac..e881065dd4 100644 --- a/doc/source/command-objects/router.rst +++ b/doc/source/command-objects/router.rst @@ -5,7 +5,7 @@ router Network v2 router create --------------- +------------- Create new router @@ -45,7 +45,7 @@ Create new router New router name router delete --------------- +------------- Delete router(s) @@ -113,3 +113,19 @@ Set router properties .. describe:: Router to modify (name or ID) + +router show +----------- + +Display router details + +.. program:: router show +.. code:: bash + + os router show + + +.. _router_show-router: +.. describe:: + + Router to display (name or ID) diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index d084db1f75..5ad7ccd284 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -273,3 +273,26 @@ class SetRouter(command.Command): raise exceptions.CommandError(msg) client.update_router(obj, **attrs) + + +class ShowRouter(show.ShowOne): + """Display router details""" + + log = logging.getLogger(__name__ + '.ShowRouter') + + def get_parser(self, prog_name): + parser = super(ShowRouter, self).get_parser(prog_name) + parser.add_argument( + 'router', + metavar="", + help="Router to display (name or ID)" + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)' % parsed_args) + client = self.app.client_manager.network + obj = client.find_router(parsed_args.router, ignore_missing=False) + columns = sorted(obj.keys()) + data = utils.get_item_properties(obj, columns, formatters=_formatters) + return (tuple(columns), data) diff --git a/openstackclient/tests/network/v2/test_router.py b/openstackclient/tests/network/v2/test_router.py index e40d2d7105..d483be85dd 100644 --- a/openstackclient/tests/network/v2/test_router.py +++ b/openstackclient/tests/network/v2/test_router.py @@ -284,3 +284,61 @@ class TestSetRouter(TestRouter): parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.assertRaises(exceptions.CommandError, self.cmd.take_action, parsed_args) + + +class TestShowRouter(TestRouter): + + # The router to set. + _router = network_fakes.FakeRouter.create_one_router() + + columns = ( + 'admin_state_up', + 'distributed', + 'ha', + 'id', + 'name', + 'tenant_id', + ) + + data = ( + router._format_admin_state(_router.admin_state_up), + _router.distributed, + _router.ha, + _router.id, + _router.name, + _router.tenant_id, + ) + + def setUp(self): + super(TestShowRouter, self).setUp() + + self.network.find_router = mock.Mock(return_value=self._router) + + # Get the command object to test + self.cmd = router.ShowRouter(self.app, self.namespace) + + def test_show_no_options(self): + arglist = [] + verifylist = [] + + try: + # Missing required args should bail here + self.check_parser(self.cmd, arglist, verifylist) + except tests_utils.ParserException: + pass + + def test_show_all_options(self): + arglist = [ + self._router.name, + ] + verifylist = [ + ('router', self._router.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + self.network.find_router.assert_called_with(self._router.name, + ignore_missing=False) + self.assertEqual(tuple(self.columns), columns) + self.assertEqual(self.data, data) diff --git a/setup.cfg b/setup.cfg index d55dd1c989..7f54fb1fb0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -336,6 +336,7 @@ openstack.network.v2 = router_delete = openstackclient.network.v2.router:DeleteRouter router_list = openstackclient.network.v2.router:ListRouter router_set = openstackclient.network.v2.router:SetRouter + router_show = openstackclient.network.v2.router:ShowRouter openstack.object_store.v1 = object_store_account_set = openstackclient.object.v1.account:SetAccount