Add columns support for share-replica-list

The share-replica-list command does not allow specifying
the required columns to format the output of the command.

Add parameter "--columns" and add a unit test for that.

Change-Id: I5d266572cb6efb1b2771e6b61e57a4aebc12ad89
Closes-bug: #1608664
This commit is contained in:
Faiz Abidi 2016-08-01 19:03:47 -04:00
parent 093a2e69f6
commit 49bffc48a1
3 changed files with 32 additions and 9 deletions

View File

@ -1765,6 +1765,15 @@ class ShellTest(test_utils.TestCase):
self.assert_called(
'GET', '/share-replicas/detail?share_id=fake-share-id')
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_share_replica_list_select_column(self):
self.run_command('share-replica-list --columns id,status')
self.assert_called('GET', '/share-replicas/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY, ['Id', 'Status'])
@ddt.data(
'fake-share-id --az fake-az',
'fake-share-id --availability-zone fake-az --share-network '

View File

@ -3264,20 +3264,31 @@ def do_cg_snapshot_delete(cs, args):
default=None,
action='single_alias',
help='List replicas belonging to share.')
@cliutils.arg(
'--columns',
metavar='<columns>',
type=str,
default=None,
help='Comma separated list of columns to be displayed '
'e.g. --columns "replica_state,id"')
@api_versions.wraps("2.11")
def do_share_replica_list(cs, args):
"""List share replicas (Experimental)."""
share = _find_share(cs, args.share_id) if args.share_id else None
list_of_keys = [
'ID',
'Status',
'Replica State',
'Share ID',
'Host',
'Availability Zone',
'Updated At',
]
if args.columns is not None:
list_of_keys = _split_columns(columns=args.columns)
else:
list_of_keys = [
'ID',
'Status',
'Replica State',
'Share ID',
'Host',
'Availability Zone',
'Updated At',
]
if share:
replicas = cs.share_replicas.list(share)
else:

View File

@ -0,0 +1,3 @@
---
fixes:
- Added "--columns" support for share-replica-list command.