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
This commit is contained in:
parent
ea7f28fb4a
commit
2c1282cecf
@ -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
|
||||
--------
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
releasenotes/notes/bug-1613995-10bb3895d702c063.yaml
Normal file
7
releasenotes/notes/bug-1613995-10bb3895d702c063.yaml
Normal 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…
Reference in New Issue
Block a user