Add extra filtering options to qos policy list
The patch adds filtering "--project", "--project-domain", "--share", "--no-share" options to qos policy list. Change-Id: I5c012fb27fb952f736ddc9fbc54ef6da4d0af5e0 Partially-Implements: blueprint network-commands-options
This commit is contained in:
parent
4a19f6753b
commit
9fd3dba11e
@ -73,6 +73,25 @@ List Network QoS policies
|
||||
.. code:: bash
|
||||
|
||||
openstack network qos policy list
|
||||
[--project <project> [--project-domain <project-domain>]]
|
||||
[--share | --no-share]
|
||||
|
||||
.. option:: --project <project>
|
||||
|
||||
List qos policies according to their project (name or ID)
|
||||
|
||||
.. option:: --project-domain <project-domain>
|
||||
|
||||
Domain the project belongs to (name or ID).
|
||||
This can be used in case collisions between project names exist.
|
||||
|
||||
.. option:: --share
|
||||
|
||||
List qos policies shared between projects
|
||||
|
||||
.. option:: --no-share
|
||||
|
||||
List qos policies not shared between projects
|
||||
|
||||
network qos policy set
|
||||
----------------------
|
||||
|
@ -37,9 +37,9 @@ def _get_columns(item):
|
||||
|
||||
def _get_attrs(client_manager, parsed_args):
|
||||
attrs = {}
|
||||
if parsed_args.name is not None:
|
||||
if 'name' in parsed_args and parsed_args.name is not None:
|
||||
attrs['name'] = str(parsed_args.name)
|
||||
if parsed_args.description is not None:
|
||||
if 'description' in parsed_args and parsed_args.description is not None:
|
||||
attrs['description'] = parsed_args.description
|
||||
if parsed_args.share:
|
||||
attrs['shared'] = True
|
||||
@ -143,6 +143,27 @@ class DeleteNetworkQosPolicy(command.Command):
|
||||
class ListNetworkQosPolicy(command.Lister):
|
||||
_description = _("List QoS policies")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListNetworkQosPolicy, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--project',
|
||||
metavar='<project>',
|
||||
help=_("List qos policies according to their project (name or ID)")
|
||||
)
|
||||
identity_common.add_project_domain_option_to_parser(parser)
|
||||
shared_group = parser.add_mutually_exclusive_group()
|
||||
shared_group.add_argument(
|
||||
'--share',
|
||||
action='store_true',
|
||||
help=_("List qos policies shared between projects")
|
||||
)
|
||||
shared_group.add_argument(
|
||||
'--no-share',
|
||||
action='store_true',
|
||||
help=_("List qos policies not shared between projects")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
columns = (
|
||||
@ -157,8 +178,8 @@ class ListNetworkQosPolicy(command.Lister):
|
||||
'Shared',
|
||||
'Project',
|
||||
)
|
||||
data = client.qos_policies()
|
||||
|
||||
attrs = _get_attrs(self.app.client_manager, parsed_args)
|
||||
data = client.qos_policies(**attrs)
|
||||
return (column_headers,
|
||||
(utils.get_item_properties(
|
||||
s, columns, formatters={},
|
||||
|
@ -250,6 +250,59 @@ class TestListNetworkQosPolicy(TestQosPolicy):
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_qos_policy_list_share(self):
|
||||
arglist = [
|
||||
'--share',
|
||||
]
|
||||
verifylist = [
|
||||
('share', True),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.qos_policies.assert_called_once_with(
|
||||
**{'shared': True}
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_qos_policy_list_no_share(self):
|
||||
arglist = [
|
||||
'--no-share',
|
||||
]
|
||||
verifylist = [
|
||||
('no_share', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.qos_policies.assert_called_once_with(
|
||||
**{'shared': False}
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
def test_network_qos_list_project(self):
|
||||
project = identity_fakes_v3.FakeProject.create_one_project()
|
||||
self.projects_mock.get.return_value = project
|
||||
arglist = [
|
||||
'--project', project.id,
|
||||
'--project-domain', project.domain_id,
|
||||
]
|
||||
verifylist = [
|
||||
('project', project.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.network.qos_policies.assert_called_once_with(
|
||||
**{'tenant_id': project.id}
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
class TestSetNetworkQosPolicy(TestQosPolicy):
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- Add ``--share``, ``--no-share``, ``--project``, ``--project-domain``
|
||||
options to ``qos policy list`` command.
|
||||
[Blueprint `network-commands-options <https://blueprints.launchpad.net/python-openstackclient/+spec/network-commands-options>`_]
|
Loading…
Reference in New Issue
Block a user