Skip to content

Commit 5ff660f

Browse files
committed
Further improve output for "os security group show"
Improve the security group rules output when running the "os security group show" command. Empty and duplicate information for each security group rule is now removed. This will ensure that the rules remain readable when direction and ethertype information is returned as part of the transition to neutron networking. Change-Id: Ib49c27a9d7f4d5d38ceb2b0d785ddf94d88b2d89 Partial-Bug: #1519511 Related-To: blueprint neutron-client
1 parent 4011649 commit 5ff660f

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

openstackclient/compute/v2/security_group.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ def _xform_security_group_rule(sgroup):
6262
return info
6363

6464

65+
def _xform_and_trim_security_group_rule(sgroup):
66+
info = _xform_security_group_rule(sgroup)
67+
# Trim parent security group ID since caller has this information.
68+
info.pop('parent_group_id', None)
69+
# Trim keys with empty string values.
70+
keys_to_trim = [
71+
'ip_protocol',
72+
'ip_range',
73+
'port_range',
74+
'remote_security_group',
75+
]
76+
for key in keys_to_trim:
77+
if key in info and not info[key]:
78+
info.pop(key)
79+
return info
80+
81+
6582
class CreateSecurityGroup(show.ShowOne):
6683
"""Create a new security group"""
6784

@@ -396,7 +413,8 @@ def take_action(self, parsed_args):
396413
)._info)
397414
rules = []
398415
for r in info['rules']:
399-
rules.append(utils.format_dict(_xform_security_group_rule(r)))
416+
formatted_rule = _xform_and_trim_security_group_rule(r)
417+
rules.append(utils.format_dict(formatted_rule))
400418

401419
# Format rules into a list of strings
402420
info.update(

0 commit comments

Comments
 (0)