Add port list command
This patch adds the ability to list all created ports Change-Id: Ie1a48c203cabc96346a4950f21b83493d58a66a5 Partial-bug: #1519909 Partially-implements: blueprint neutron-client
This commit is contained in:
parent
fc24f37ae2
commit
d548942645
@ -98,6 +98,16 @@ Delete port(s)
|
||||
|
||||
Port(s) to delete (name or ID)
|
||||
|
||||
port list
|
||||
---------
|
||||
|
||||
List ports
|
||||
|
||||
.. program:: port list
|
||||
.. code:: bash
|
||||
|
||||
os port list
|
||||
|
||||
port show
|
||||
---------
|
||||
|
||||
|
@ -238,6 +238,33 @@ class DeletePort(command.Command):
|
||||
client.delete_port(res)
|
||||
|
||||
|
||||
class ListPort(command.Lister):
|
||||
"""List ports"""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
'name',
|
||||
'mac_address',
|
||||
'fixed_ips',
|
||||
)
|
||||
column_headers = (
|
||||
'ID',
|
||||
'Name',
|
||||
'MAC Address',
|
||||
'Fixed IP Addresses',
|
||||
)
|
||||
|
||||
data = client.ports()
|
||||
return (column_headers,
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
formatters=_formatters,
|
||||
) for s in data))
|
||||
|
||||
|
||||
class ShowPort(command.ShowOne):
|
||||
"""Display port details"""
|
||||
|
||||
|
@ -199,6 +199,47 @@ class TestDeletePort(TestPort):
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestListPort(TestPort):
|
||||
|
||||
_ports = network_fakes.FakePort.create_ports(count=3)
|
||||
|
||||
columns = (
|
||||
'ID',
|
||||
'Name',
|
||||
'MAC Address',
|
||||
'Fixed IP Addresses',
|
||||
)
|
||||
|
||||
data = []
|
||||
for prt in _ports:
|
||||
data.append((
|
||||
prt.id,
|
||||
prt.name,
|
||||
prt.mac_address,
|
||||
utils.format_list_of_dicts(prt.fixed_ips),
|
||||
))
|
||||
|
||||
def setUp(self):
|
||||
super(TestListPort, self).setUp()
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = port.ListPort(self.app, self.namespace)
|
||||
|
||||
self.network.ports = mock.Mock(return_value=self._ports)
|
||||
|
||||
def test_port_list_no_options(self):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.ports.assert_called_with()
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
class TestShowPort(TestPort):
|
||||
|
||||
# The port to show.
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add support for the ``port list`` command.
|
||||
[Bug `1519909 <https://bugs.launchpad.net/python-openstackclient/+bug/1519909>`_]
|
@ -326,27 +326,34 @@ openstack.network.v2 =
|
||||
ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP
|
||||
ip_floating_list = openstackclient.network.v2.floating_ip:ListFloatingIP
|
||||
ip_floating_show = openstackclient.network.v2.floating_ip:ShowFloatingIP
|
||||
|
||||
network_create = openstackclient.network.v2.network:CreateNetwork
|
||||
network_delete = openstackclient.network.v2.network:DeleteNetwork
|
||||
network_list = openstackclient.network.v2.network:ListNetwork
|
||||
network_set = openstackclient.network.v2.network:SetNetwork
|
||||
network_show = openstackclient.network.v2.network:ShowNetwork
|
||||
|
||||
port_create = openstackclient.network.v2.port:CreatePort
|
||||
port_delete = openstackclient.network.v2.port:DeletePort
|
||||
port_list = openstackclient.network.v2.port:ListPort
|
||||
port_show = openstackclient.network.v2.port:ShowPort
|
||||
|
||||
router_create = openstackclient.network.v2.router:CreateRouter
|
||||
router_delete = openstackclient.network.v2.router:DeleteRouter
|
||||
router_list = openstackclient.network.v2.router:ListRouter
|
||||
router_set = openstackclient.network.v2.router:SetRouter
|
||||
router_show = openstackclient.network.v2.router:ShowRouter
|
||||
|
||||
security_group_delete = openstackclient.network.v2.security_group:DeleteSecurityGroup
|
||||
security_group_list = openstackclient.network.v2.security_group:ListSecurityGroup
|
||||
security_group_set = openstackclient.network.v2.security_group:SetSecurityGroup
|
||||
security_group_rule_delete = openstackclient.network.v2.security_group_rule:DeleteSecurityGroupRule
|
||||
security_group_rule_show = openstackclient.network.v2.security_group_rule:ShowSecurityGroupRule
|
||||
|
||||
subnet_delete = openstackclient.network.v2.subnet:DeleteSubnet
|
||||
subnet_list = openstackclient.network.v2.subnet:ListSubnet
|
||||
subnet_show = openstackclient.network.v2.subnet:ShowSubnet
|
||||
|
||||
subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool
|
||||
subnet_pool_list = openstackclient.network.v2.subnet_pool:ListSubnetPool
|
||||
subnet_pool_show = openstackclient.network.v2.subnet_pool:ShowSubnetPool
|
||||
|
Loading…
Reference in New Issue
Block a user