2323
2424from openstackclient .i18n import _
2525from openstackclient .identity import common as identity_common
26+ from openstackclient .network import sdk_utils
2627
2728
2829LOG = logging .getLogger (__name__ )
@@ -117,11 +118,12 @@ def _get_common_parse_arguments(parser, is_create=True):
117118
118119
119120def _get_columns (item ):
120- columns = list (item .keys ())
121- if 'tenant_id' in columns :
122- columns .remove ('tenant_id' )
123- columns .append ('project_id' )
124- return tuple (sorted (columns ))
121+ column_map = {
122+ 'is_dhcp_enabled' : 'enable_dhcp' ,
123+ 'subnet_pool_id' : 'subnetpool_id' ,
124+ 'tenant_id' : 'project_id' ,
125+ }
126+ return sdk_utils .get_osc_show_columns_for_sdk_resource (item , column_map )
125127
126128
127129def convert_entries_to_nexthop (entries ):
@@ -217,6 +219,8 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
217219 return attrs
218220
219221
222+ # TODO(abhiraut): Use the SDK resource mapped attribute names once the
223+ # OSC minimum requirements include SDK 1.0.
220224class CreateSubnet (command .ShowOne ):
221225 _description = _ ("Create a subnet" )
222226
@@ -323,9 +327,9 @@ def take_action(self, parsed_args):
323327 client = self .app .client_manager .network
324328 attrs = _get_attrs (self .app .client_manager , parsed_args )
325329 obj = client .create_subnet (** attrs )
326- columns = _get_columns (obj )
330+ display_columns , columns = _get_columns (obj )
327331 data = utils .get_item_properties (obj , columns , formatters = _formatters )
328- return (columns , data )
332+ return (display_columns , data )
329333
330334
331335class DeleteSubnet (command .Command ):
@@ -362,6 +366,8 @@ def take_action(self, parsed_args):
362366 raise exceptions .CommandError (msg )
363367
364368
369+ # TODO(abhiraut): Use only the SDK resource mapped attribute names once the
370+ # OSC minimum requirements include SDK 1.0.
365371class ListSubnet (command .Lister ):
366372 _description = _ ("List subnets" )
367373
@@ -443,8 +449,10 @@ def take_action(self, parsed_args):
443449 filters ['ip_version' ] = parsed_args .ip_version
444450 if parsed_args .dhcp :
445451 filters ['enable_dhcp' ] = True
452+ filters ['is_dhcp_enabled' ] = True
446453 elif parsed_args .no_dhcp :
447454 filters ['enable_dhcp' ] = False
455+ filters ['is_dhcp_enabled' ] = False
448456 if parsed_args .service_types :
449457 filters ['service_types' ] = parsed_args .service_types
450458 if parsed_args .project :
@@ -454,6 +462,7 @@ def take_action(self, parsed_args):
454462 parsed_args .project_domain ,
455463 ).id
456464 filters ['tenant_id' ] = project_id
465+ filters ['project_id' ] = project_id
457466 if parsed_args .network :
458467 network_id = network_client .find_network (parsed_args .network ,
459468 ignore_missing = False ).id
@@ -472,7 +481,7 @@ def take_action(self, parsed_args):
472481 headers += ('Project' , 'DHCP' , 'Name Servers' ,
473482 'Allocation Pools' , 'Host Routes' , 'IP Version' ,
474483 'Gateway' , 'Service Types' )
475- columns += ('tenant_id ' , 'enable_dhcp ' , 'dns_nameservers' ,
484+ columns += ('project_id ' , 'is_dhcp_enabled ' , 'dns_nameservers' ,
476485 'allocation_pools' , 'host_routes' , 'ip_version' ,
477486 'gateway_ip' , 'service_types' )
478487
@@ -483,6 +492,8 @@ def take_action(self, parsed_args):
483492 ) for s in data ))
484493
485494
495+ # TODO(abhiraut): Use the SDK resource mapped attribute names once the
496+ # OSC minimum requirements include SDK 1.0.
486497class SetSubnet (command .Command ):
487498 _description = _ ("Set subnet properties" )
488499
@@ -564,9 +575,9 @@ def get_parser(self, prog_name):
564575 def take_action (self , parsed_args ):
565576 obj = self .app .client_manager .network .find_subnet (parsed_args .subnet ,
566577 ignore_missing = False )
567- columns = _get_columns (obj )
578+ display_columns , columns = _get_columns (obj )
568579 data = utils .get_item_properties (obj , columns , formatters = _formatters )
569- return (columns , data )
580+ return (display_columns , data )
570581
571582
572583class UnsetSubnet (command .Command ):
0 commit comments