Browse Source

Add a new column and a new option the 'os port list' cmd

This patch will add a new column called status to the
result of the 'os port list' command and --long option
to 'os port list' command.

Co-Authored-By: Ha Van Tu <tuhv@vn.fujitsu.com>
Change-Id: I4f942414e969687304b578ed7f003dd219c0f2f8
Closes-Bug: #1613995
Closes-Bug: #1614321
Partially-Implements: blueprint network-commands-options
tags/3.4.0
Nam Nguyen Hoai 3 years ago
parent
commit
2c1282cecf
4 changed files with 64 additions and 0 deletions
  1. +5
    -0
      doc/source/command-objects/port.rst
  2. +11
    -0
      openstackclient/network/v2/port.py
  3. +41
    -0
      openstackclient/tests/unit/network/v2/test_port.py
  4. +7
    -0
      releasenotes/notes/bug-1613995-10bb3895d702c063.yaml

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

@@ -117,6 +117,7 @@ List ports
[--device-owner <device-owner>]
[--router <router> | --server <server>]
[--network <network>]
[--long]

.. option:: --device-owner <device-owner>

@@ -135,6 +136,10 @@ List ports

List only ports attached to this network (name or ID)

.. option:: --long

List additional fields in output

port set
--------


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

@@ -360,6 +360,12 @@ class ListPort(command.Lister):
metavar='<server>',
help=_("List only ports attached to this server (name or ID)"),
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help=_("List additional fields in output")
)
return parser

def take_action(self, parsed_args):
@@ -371,15 +377,20 @@ class ListPort(command.Lister):
'name',
'mac_address',
'fixed_ips',
'status',
)
column_headers = (
'ID',
'Name',
'MAC Address',
'Fixed IP Addresses',
'Status',
)

filters = {}
if parsed_args.long:
columns += ('security_groups', 'device_owner',)
column_headers += ('Security Groups', 'Device Owner',)
if parsed_args.device_owner is not None:
filters['device_owner'] = parsed_args.device_owner
if parsed_args.router:

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

@@ -317,6 +317,17 @@ class TestListPort(TestPort):
'Name',
'MAC Address',
'Fixed IP Addresses',
'Status',
)

columns_long = (
'ID',
'Name',
'MAC Address',
'Fixed IP Addresses',
'Status',
'Security Groups',
'Device Owner',
)

data = []
@@ -326,6 +337,19 @@ class TestListPort(TestPort):
prt.name,
prt.mac_address,
utils.format_list_of_dicts(prt.fixed_ips),
prt.status,
))

data_long = []
for prt in _ports:
data_long.append((
prt.id,
prt.name,
prt.mac_address,
utils.format_list_of_dicts(prt.fixed_ips),
prt.status,
utils.format_list(prt.security_groups),
prt.device_owner,
))

def setUp(self):
@@ -439,6 +463,23 @@ class TestListPort(TestPort):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))

def test_list_port_with_long(self):
arglist = [
'--long',
]

verifylist = [
('long', True),
]

parsed_args = self.check_parser(self.cmd, arglist, verifylist)

columns, data = self.cmd.take_action(parsed_args)

self.network.ports.assert_called_once_with()
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))


class TestSetPort(TestPort):


+ 7
- 0
releasenotes/notes/bug-1613995-10bb3895d702c063.yaml View File

@@ -0,0 +1,7 @@
---
features:
- |
Add a new column ``status`` and ``--long`` option to the result of the
``os port list`` command.
[Bug `1613995 <https://bugs.launchpad.net/bugs/1613995>`_]
[Bug `1614321 <https://bugs.launchpad.net/bugs/1614321>`_]

Loading…
Cancel
Save