Merge "Router: Add "router show" command using SDK"
This commit is contained in:
commit
d72f6228cf
@ -5,7 +5,7 @@ router
|
|||||||
Network v2
|
Network v2
|
||||||
|
|
||||||
router create
|
router create
|
||||||
--------------
|
-------------
|
||||||
|
|
||||||
Create new router
|
Create new router
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ Create new router
|
|||||||
New router name
|
New router name
|
||||||
|
|
||||||
router delete
|
router delete
|
||||||
--------------
|
-------------
|
||||||
|
|
||||||
Delete router(s)
|
Delete router(s)
|
||||||
|
|
||||||
@ -113,3 +113,19 @@ Set router properties
|
|||||||
.. describe:: <router>
|
.. describe:: <router>
|
||||||
|
|
||||||
Router to modify (name or ID)
|
Router to modify (name or ID)
|
||||||
|
|
||||||
|
router show
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Display router details
|
||||||
|
|
||||||
|
.. program:: router show
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
os router show
|
||||||
|
<router>
|
||||||
|
|
||||||
|
.. _router_show-router:
|
||||||
|
.. describe:: <router>
|
||||||
|
|
||||||
|
Router to display (name or ID)
|
||||||
|
@ -273,3 +273,26 @@ class SetRouter(command.Command):
|
|||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
client.update_router(obj, **attrs)
|
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="<router>",
|
||||||
|
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)
|
||||||
|
@ -284,3 +284,61 @@ class TestSetRouter(TestRouter):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||||
parsed_args)
|
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)
|
||||||
|
@ -336,6 +336,7 @@ openstack.network.v2 =
|
|||||||
router_delete = openstackclient.network.v2.router:DeleteRouter
|
router_delete = openstackclient.network.v2.router:DeleteRouter
|
||||||
router_list = openstackclient.network.v2.router:ListRouter
|
router_list = openstackclient.network.v2.router:ListRouter
|
||||||
router_set = openstackclient.network.v2.router:SetRouter
|
router_set = openstackclient.network.v2.router:SetRouter
|
||||||
|
router_show = openstackclient.network.v2.router:ShowRouter
|
||||||
|
|
||||||
openstack.object_store.v1 =
|
openstack.object_store.v1 =
|
||||||
object_store_account_set = openstackclient.object.v1.account:SetAccount
|
object_store_account_set = openstackclient.object.v1.account:SetAccount
|
||||||
|
Loading…
x
Reference in New Issue
Block a user