Skip to content

Commit ee1a477

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Further improve output for "os security group show""
2 parents a80ccd8 + 5ff660f commit ee1a477

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)