Add options to allow filtering on agent list
Add options to allow filtering via --agent-type and --host on agent list Change-Id: I1800f0777aa92a76b4b95f64f8acc18454809e81 Closes-Bug: #1641868 Partially-Implements: blueprint network-commands-options
This commit is contained in:
parent
3816b4b90a
commit
2e78c11c8d
@ -35,6 +35,19 @@ List network agents
|
|||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
openstack network agent list
|
openstack network agent list
|
||||||
|
[--agent-type <agent-type>]
|
||||||
|
[--host <host>]
|
||||||
|
|
||||||
|
.. option:: --agent-type <agent-type>
|
||||||
|
|
||||||
|
List only agents with the specified agent type.
|
||||||
|
The supported agent types are: dhcp, open-vswitch,
|
||||||
|
linux-bridge, ofa, l3, loadbalancer, metering,
|
||||||
|
metadata, macvtap, nic.
|
||||||
|
|
||||||
|
.. option:: --host <host>
|
||||||
|
|
||||||
|
List only agents running on the specified host
|
||||||
|
|
||||||
network agent set
|
network agent set
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -72,6 +72,25 @@ class DeleteNetworkAgent(command.Command):
|
|||||||
class ListNetworkAgent(command.Lister):
|
class ListNetworkAgent(command.Lister):
|
||||||
_description = _("List network agents")
|
_description = _("List network agents")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListNetworkAgent, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'--agent-type',
|
||||||
|
metavar='<agent-type>',
|
||||||
|
choices=["dhcp", "open-vswitch", "linux-bridge", "ofa", "l3",
|
||||||
|
"loadbalancer", "metering", "metadata", "macvtap", "nic"],
|
||||||
|
help=_("List only agents with the specified agent type. "
|
||||||
|
"The supported agent types are: dhcp, open-vswitch, "
|
||||||
|
"linux-bridge, ofa, l3, loadbalancer, metering, "
|
||||||
|
"metadata, macvtap, nic.")
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--host',
|
||||||
|
metavar='<host>',
|
||||||
|
help=_("List only agents running on the specified host")
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = self.app.client_manager.network
|
client = self.app.client_manager.network
|
||||||
columns = (
|
columns = (
|
||||||
@ -92,7 +111,27 @@ class ListNetworkAgent(command.Lister):
|
|||||||
'State',
|
'State',
|
||||||
'Binary'
|
'Binary'
|
||||||
)
|
)
|
||||||
data = client.agents()
|
|
||||||
|
key_value = {
|
||||||
|
'dhcp': 'DHCP agent',
|
||||||
|
'open-vswitch': 'Open vSwitch agent',
|
||||||
|
'linux-bridge': 'Linux bridge agent',
|
||||||
|
'ofa': 'OFA driver agent',
|
||||||
|
'l3': 'L3 agent',
|
||||||
|
'loadbalancer': 'Loadbalancer agent',
|
||||||
|
'metering': 'Metering agent',
|
||||||
|
'metadata': 'Metadata agent',
|
||||||
|
'macvtap': 'Macvtap agent',
|
||||||
|
'nic': 'NIC Switch agent'
|
||||||
|
}
|
||||||
|
|
||||||
|
filters = {}
|
||||||
|
if parsed_args.agent_type is not None:
|
||||||
|
filters['agent_type'] = key_value[parsed_args.agent_type]
|
||||||
|
if parsed_args.host is not None:
|
||||||
|
filters['host'] = parsed_args.host
|
||||||
|
|
||||||
|
data = client.agents(**filters)
|
||||||
return (column_headers,
|
return (column_headers,
|
||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
s, columns, formatters=_formatters,
|
s, columns, formatters=_formatters,
|
||||||
|
@ -130,6 +130,7 @@ class TestListNetworkAgent(TestNetworkAgent):
|
|||||||
)
|
)
|
||||||
data = []
|
data = []
|
||||||
for agent in network_agents:
|
for agent in network_agents:
|
||||||
|
agent.agent_type = 'DHCP agent'
|
||||||
data.append((
|
data.append((
|
||||||
agent.id,
|
agent.id,
|
||||||
agent.agent_type,
|
agent.agent_type,
|
||||||
@ -159,6 +160,40 @@ class TestListNetworkAgent(TestNetworkAgent):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, list(data))
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
def test_network_agents_list_agent_type(self):
|
||||||
|
arglist = [
|
||||||
|
'--agent-type', 'dhcp',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('agent_type', 'dhcp'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.network.agents.assert_called_once_with(**{
|
||||||
|
'agent_type': self.network_agents[0].agent_type,
|
||||||
|
})
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
def test_network_agents_list_host(self):
|
||||||
|
arglist = [
|
||||||
|
'--host', self.network_agents[0].host,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('host', self.network_agents[0].host),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.network.agents.assert_called_once_with(**{
|
||||||
|
'host': self.network_agents[0].host,
|
||||||
|
})
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
|
||||||
class TestSetNetworkAgent(TestNetworkAgent):
|
class TestSetNetworkAgent(TestNetworkAgent):
|
||||||
|
|
||||||
|
6
releasenotes/notes/bug-1641868-97c284e33f944c2d.yaml
Normal file
6
releasenotes/notes/bug-1641868-97c284e33f944c2d.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add filters ``--agent-type`` and ``--host``
|
||||||
|
to ``network agent list`` command
|
||||||
|
[Bug `1641868 <https://bugs.launchpad.net/bugs/1641868>`_]
|
Loading…
Reference in New Issue
Block a user