Add filtering options --name,--enable,--disable to router list
Change-Id: I171b6be4501b02c3df66589c45177200919117db Closes-Bug: #1637945 Partially-Implements: blueprint network-commands-options
This commit is contained in:
parent
8ca1cc6370
commit
84beac5994
@ -134,12 +134,26 @@ List routers
|
||||
.. code:: bash
|
||||
|
||||
os router list
|
||||
[--name <name>]
|
||||
[--enable | --disable]
|
||||
[--long]
|
||||
|
||||
.. option:: --long
|
||||
|
||||
List additional fields in output
|
||||
|
||||
.. option:: --name <name>
|
||||
|
||||
List routers according to their name
|
||||
|
||||
.. option:: --enable
|
||||
|
||||
List enabled routers
|
||||
|
||||
.. option:: --disable
|
||||
|
||||
List disabled routers
|
||||
|
||||
router remove port
|
||||
------------------
|
||||
|
||||
|
@ -260,6 +260,22 @@ class ListRouter(command.Lister):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListRouter, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help=_("List routers according to their name")
|
||||
)
|
||||
admin_state_group = parser.add_mutually_exclusive_group()
|
||||
admin_state_group.add_argument(
|
||||
'--enable',
|
||||
action='store_true',
|
||||
help=_("List enabled routers")
|
||||
)
|
||||
admin_state_group.add_argument(
|
||||
'--disable',
|
||||
action='store_true',
|
||||
help=_("List disabled routers")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
@ -289,6 +305,17 @@ class ListRouter(command.Lister):
|
||||
'HA',
|
||||
'Project',
|
||||
)
|
||||
|
||||
args = {}
|
||||
|
||||
if parsed_args.name is not None:
|
||||
args['name'] = parsed_args.name
|
||||
|
||||
if parsed_args.enable:
|
||||
args['admin_state_up'] = True
|
||||
elif parsed_args.disable:
|
||||
args['admin_state_up'] = False
|
||||
|
||||
if parsed_args.long:
|
||||
columns = columns + (
|
||||
'routes',
|
||||
@ -308,7 +335,7 @@ class ListRouter(command.Lister):
|
||||
'Availability zones',
|
||||
)
|
||||
|
||||
data = client.routers()
|
||||
data = client.routers(**args)
|
||||
return (column_headers,
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
|
@ -427,6 +427,58 @@ class TestListRouter(TestRouter):
|
||||
self.assertEqual(self.columns_long_no_az, columns)
|
||||
self.assertEqual(self.data_long_no_az, list(data))
|
||||
|
||||
def test_list_name(self):
|
||||
test_name = "fakename"
|
||||
arglist = [
|
||||
'--name', test_name,
|
||||
]
|
||||
verifylist = [
|
||||
('long', False),
|
||||
('name', test_name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.routers.assert_called_once_with(
|
||||
**{'name': test_name}
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_router_list_enable(self):
|
||||
arglist = [
|
||||
'--enable',
|
||||
]
|
||||
verifylist = [
|
||||
('long', False),
|
||||
('enable', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.routers.assert_called_once_with(
|
||||
**{'admin_state_up': True}
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_router_list_disable(self):
|
||||
arglist = [
|
||||
'--disable',
|
||||
]
|
||||
verifylist = [
|
||||
('long', False),
|
||||
('disable', True)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.routers.assert_called_once_with(
|
||||
**{'admin_state_up': False}
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
class TestRemovePortFromRouter(TestRouter):
|
||||
'''Remove port from a Router '''
|
||||
|
5
releasenotes/notes/bug-1637945-f361c834381d409c.yaml
Normal file
5
releasenotes/notes/bug-1637945-f361c834381d409c.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--name``, ``--enable``, ``--disable`` to ``os router list``
|
||||
[Bug `1637945 <https://bugs.launchpad.net/bugs/1637945>`_]
|
Loading…
Reference in New Issue
Block a user