2121from openstackclient .i18n import _
2222from openstackclient .identity import common as identity_common
2323from openstackclient .network import common
24+ from openstackclient .network import sdk_utils
2425from openstackclient .network import utils as network_utils
2526
2627
@@ -34,6 +35,7 @@ def _format_network_security_group_rules(sg_rules):
3435 sg_rule .pop (key )
3536 sg_rule .pop ('security_group_id' , None )
3637 sg_rule .pop ('tenant_id' , None )
38+ sg_rule .pop ('project_id' , None )
3739 return utils .format_list_of_dicts (sg_rules )
3840
3941
@@ -72,29 +74,15 @@ def _format_compute_security_group_rules(sg_rules):
7274
7375
7476def _get_columns (item ):
75- # Build the display columns and a list of the property columns
76- # that need to be mapped (display column name, property name).
77- columns = list (item .to_dict ().keys ())
78- property_column_mappings = []
79- if 'security_group_rules' in columns :
80- columns .append ('rules' )
81- columns .remove ('security_group_rules' )
82- property_column_mappings .append (('rules' , 'security_group_rules' ))
83- if 'tenant_id' in columns :
84- columns .remove ('tenant_id' )
85- if 'project_id' not in columns :
86- columns .append ('project_id' )
87- property_column_mappings .append (('project_id' , 'tenant_id' ))
88- display_columns = sorted (columns )
89-
90- # Build the property columns and apply any column mappings.
91- property_columns = sorted (columns )
92- for property_column_mapping in property_column_mappings :
93- property_index = property_columns .index (property_column_mapping [0 ])
94- property_columns [property_index ] = property_column_mapping [1 ]
95- return tuple (display_columns ), property_columns
77+ column_map = {
78+ 'security_group_rules' : 'rules' ,
79+ 'tenant_id' : 'project_id' ,
80+ }
81+ return sdk_utils .get_osc_show_columns_for_sdk_resource (item , column_map )
9682
9783
84+ # TODO(abhiraut): Use the SDK resource mapped attribute names once the
85+ # OSC minimum requirements include SDK 1.0.
9886class CreateSecurityGroup (common .NetworkAndComputeShowOne ):
9987 _description = _ ("Create a new security group" )
10088
@@ -190,6 +178,8 @@ def take_action_compute(self, client, parsed_args):
190178 client .security_groups .delete (data .id )
191179
192180
181+ # TODO(rauta): Use the SDK resource mapped attribute names once
182+ # the OSC minimum requirements include SDK 1.0.
193183class ListSecurityGroup (common .NetworkAndComputeLister ):
194184 _description = _ ("List security groups" )
195185
@@ -245,6 +235,7 @@ def take_action_network(self, client, parsed_args):
245235 parsed_args .project_domain ,
246236 ).id
247237 filters ['tenant_id' ] = project_id
238+ filters ['project_id' ] = project_id
248239 return self ._get_return_data (client .security_groups (** filters ))
249240
250241 def take_action_compute (self , client , parsed_args ):
0 commit comments