Skip to content

Commit 307d23b

Browse files
committed
port: add --host to list command
This adds an option to allow filtering ports bound to a specific host when listing them. Change-Id: I747ed0f8b070074c51789576a158345f670fe733
1 parent 9754a67 commit 307d23b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ def get_parser(self, prog_name):
515515
"This is the entity that uses the port (for example, "
516516
"network:dhcp).")
517517
)
518+
parser.add_argument(
519+
'--host',
520+
metavar='<host-id>',
521+
help=_("List only ports bound to this host ID"))
518522
parser.add_argument(
519523
'--network',
520524
metavar='<network>',
@@ -603,6 +607,8 @@ def take_action(self, parsed_args):
603607
server = utils.find_resource(compute_client.servers,
604608
parsed_args.server)
605609
filters['device_id'] = server.id
610+
if parsed_args.host:
611+
filters['binding:host_id'] = parsed_args.host
606612
if parsed_args.network:
607613
network = network_client.find_network(parsed_args.network,
608614
ignore_missing=False)

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,22 @@ def test_list_port_with_long(self):
10541054
self.assertEqual(self.columns_long, columns)
10551055
self.assertListItemEqual(self.data_long, list(data))
10561056

1057+
def test_port_list_host(self):
1058+
arglist = [
1059+
'--host', 'foobar',
1060+
]
1061+
verifylist = [
1062+
('host', 'foobar'),
1063+
]
1064+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1065+
1066+
columns, data = self.cmd.take_action(parsed_args)
1067+
filters = {'binding:host_id': 'foobar'}
1068+
1069+
self.network.ports.assert_called_once_with(**filters)
1070+
self.assertEqual(self.columns, columns)
1071+
self.assertListItemEqual(self.data, list(data))
1072+
10571073
def test_port_list_project(self):
10581074
project = identity_fakes.FakeProject.create_one_project()
10591075
self.projects_mock.get.return_value = project

0 commit comments

Comments
 (0)