Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit 0e38ef8

Browse files
committed
Improve output for "os security group show"
Improve the security group rules output when running the "os security group show" command. Each security group rule is now displayed on a separate line. Current output example: $ openstack security group show default +-------------+------------------------- ... ---+ | Field | Value ... | +-------------+------------------------- ... ---+ | description | Default security group ... | | id | 048a5fc3-3be1-407d-ae47-9... | | name | default ... | | project_id | 3b96bb2020c1459da76963f9e... | | rules | [u"id='5d812367-9829-4340...t"] | +-------------+------------------------- ... ---+ New output example: +-------------+------------------------- ... ---+ | Field | Value ... | +-------------+------------------------- ... ---+ | description | Default security group ... | | id | 048a5fc3-3be1-407d-ae47-9... | | name | default ... | | project_id | 3b96bb2020c1459da76963f9e... | | rules | id='5d812367-9829-4340-95...lt' | | | id='ee451d1c-ade3-4975-8e...lt' | +-------------+------------------------- ... ---+ Change-Id: I1386075310896c58a2b776e2bbec3603bd00eff1 Partial-Bug: #1519511 Related-To: blueprint neutron-client
1 parent 49bed38 commit 0e38ef8

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

openstackclient/common/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ def format_dict(data):
154154
return output[:-2]
155155

156156

157-
def format_list(data):
157+
def format_list(data, separator=', '):
158158
"""Return a formatted strings
159159
160160
:param data: a list of strings
161-
:rtype: a string formatted to a,b,c
161+
:param separator: the separator to use between strings (default: ', ')
162+
:rtype: a string formatted based on separator
162163
"""
163164

164-
return ', '.join(sorted(data))
165+
return separator.join(sorted(data))
165166

166167

167168
def get_field(item, field):

openstackclient/compute/v2/security_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def take_action(self, parsed_args):
390390

391391
# Format rules into a list of strings
392392
info.update(
393-
{'rules': rules}
393+
{'rules': utils.format_list(rules, separator='\n')}
394394
)
395395
# Map 'tenant_id' column to 'project_id'
396396
info.update(

openstackclient/tests/common/test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,10 @@ def test_format_list(self):
347347
expected = 'a, b, c'
348348
self.assertEqual(expected, utils.format_list(['a', 'b', 'c']))
349349
self.assertEqual(expected, utils.format_list(['c', 'b', 'a']))
350+
351+
def test_format_list_separator(self):
352+
expected = 'a\nb\nc'
353+
actual_pre_sorted = utils.format_list(['a', 'b', 'c'], separator='\n')
354+
actual_unsorted = utils.format_list(['c', 'b', 'a'], separator='\n')
355+
self.assertEqual(expected, actual_pre_sorted)
356+
self.assertEqual(expected, actual_unsorted)

0 commit comments

Comments
 (0)