Browse Source

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
changes/71/276371/11
Jas 5 years ago
parent
commit
d548942645
5 changed files with 90 additions and 0 deletions
  1. +10
    -0
      doc/source/command-objects/port.rst
  2. +27
    -0
      openstackclient/network/v2/port.py
  3. +41
    -0
      openstackclient/tests/network/v2/test_port.py
  4. +5
    -0
      releasenotes/notes/add-port-list-command-29b4452003bc6bab.yaml
  5. +7
    -0
      setup.cfg

+ 10
- 0
doc/source/command-objects/port.rst View File

@ -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
---------


+ 27
- 0
openstackclient/network/v2/port.py View File

@ -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"""


+ 41
- 0
openstackclient/tests/network/v2/test_port.py View File

@ -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.


+ 5
- 0
releasenotes/notes/add-port-list-command-29b4452003bc6bab.yaml View File

@ -0,0 +1,5 @@
---
features:
- |
Add support for the ``port list`` command.
[Bug `1519909 <https://bugs.launchpad.net/python-openstackclient/+bug/1519909>`_]

+ 7
- 0
setup.cfg View File

@ -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…
Cancel
Save