diff options
| author | Dinesh Bhor <dinesh.bhor@nttdata.com> | 2017-01-20 16:08:36 +0530 |
|---|---|---|
| committer | Dinesh Bhor <dinesh.bhor@nttdata.com> | 2017-02-14 09:20:34 +0530 |
| commit | 2a64ed887c6884423e4ea092bb9ac63ad7a6e08b (patch) | |
| tree | 2a94f18eb9b768099a3cd56f5ecd493fcd83f0aa /cinderclient/v2/shell.py | |
| parent | fd3c44f06fc44c65d3d19395b1e6743adf5a06d9 (diff) | |
| download | python-cinderclient-2a64ed887c6884423e4ea092bb9ac63ad7a6e08b.tar.gz | |
Remove duplicate columns from list output
If you specify duplicate fields in --fields, then it prints duplicate
columns on the console. By default 'ID' column is added to the output
so if you specified it in --fields, then it shouldn't be displayed
twice.
A user can pass 'NaMe', ' Name ' or 'naMe' in --fields option and it
displays same name values three times under the user supplied column
names. If a user doesn't pass --fields option, then it shows "Name"
column in the list. To maintain consistency between user supplied
column and default column names, converted it into title case and
removed leading and trailing whitespaces. Kept ID field as capital
only('ID') for consistency.
Closes-Bug: #1659742
Change-Id: I98999e4c5934b56cd2e5a3fac1fe4d2a73a0d5a1
Diffstat (limited to 'cinderclient/v2/shell.py')
| -rw-r--r-- | cinderclient/v2/shell.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index aa9262c..abc2a29 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -17,6 +17,7 @@ from __future__ import print_function import argparse +import collections import copy import os import warnings @@ -154,7 +155,11 @@ def do_list(cs, args): setattr(vol, 'attached_to', ','.join(map(str, servers))) if field_titles: - key_list = ['ID'] + field_titles + # Remove duplicate fields + key_list = ['ID'] + unique_titles = [k for k in collections.OrderedDict.fromkeys( + [x.title().strip() for x in field_titles]) if k != 'Id'] + key_list.extend(unique_titles) else: key_list = ['ID', 'Status', 'Name', 'Size', 'Volume Type', 'Bootable', 'Attached to'] |
