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__ )
@@ -126,11 +127,12 @@ def _get_common_parse_arguments(parser, is_create=True):
126127
127128
128129def _get_columns (item ):
129- columns = list (item .keys ())
130- if 'tenant_id' in columns :
131- columns .remove ('tenant_id' )
132- columns .append ('project_id' )
133- return tuple (sorted (columns ))
130+ column_map = {
131+ 'is_dhcp_enabled' : 'enable_dhcp' ,
132+ 'subnet_pool_id' : 'subnetpool_id' ,
133+ 'tenant_id' : 'project_id' ,
134+ }
135+ return sdk_utils .get_osc_show_columns_for_sdk_resource (item , column_map )
134136
135137
136138def convert_entries_to_nexthop (entries ):
@@ -226,6 +228,8 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
226228 return attrs
227229
228230
231+ # TODO(abhiraut): Use the SDK resource mapped attribute names once the
232+ # OSC minimum requirements include SDK 1.0.
229233class CreateSubnet (command .ShowOne ):
230234 _description = _ ("Create a subnet" )
231235
@@ -332,9 +336,9 @@ def take_action(self, parsed_args):
332336 client = self .app .client_manager .network
333337 attrs = _get_attrs (self .app .client_manager , parsed_args )
334338 obj = client .create_subnet (** attrs )
335- columns = _get_columns (obj )
339+ display_columns , columns = _get_columns (obj )
336340 data = utils .get_item_properties (obj , columns , formatters = _formatters )
337- return (columns , data )
341+ return (display_columns , data )
338342
339343
340344class DeleteSubnet (command .Command ):
@@ -371,6 +375,8 @@ def take_action(self, parsed_args):
371375 raise exceptions .CommandError (msg )
372376
373377
378+ # TODO(abhiraut): Use only the SDK resource mapped attribute names once the
379+ # OSC minimum requirements include SDK 1.0.
374380class ListSubnet (command .Lister ):
375381 _description = _ ("List subnets" )
376382
@@ -452,8 +458,10 @@ def take_action(self, parsed_args):
452458 filters ['ip_version' ] = parsed_args .ip_version
453459 if parsed_args .dhcp :
454460 filters ['enable_dhcp' ] = True
461+ filters ['is_dhcp_enabled' ] = True
455462 elif parsed_args .no_dhcp :
456463 filters ['enable_dhcp' ] = False
464+ filters ['is_dhcp_enabled' ] = False
457465 if parsed_args .service_types :
458466 filters ['service_types' ] = parsed_args .service_types
459467 if parsed_args .project :
@@ -463,6 +471,7 @@ def take_action(self, parsed_args):
463471 parsed_args .project_domain ,
464472 ).id
465473 filters ['tenant_id' ] = project_id
474+ filters ['project_id' ] = project_id
466475 if parsed_args .network :
467476 network_id = network_client .find_network (parsed_args .network ,
468477 ignore_missing = False ).id
@@ -481,7 +490,7 @@ def take_action(self, parsed_args):
481490 headers += ('Project' , 'DHCP' , 'Name Servers' ,
482491 'Allocation Pools' , 'Host Routes' , 'IP Version' ,
483492 'Gateway' , 'Service Types' )
484- columns += ('tenant_id ' , 'enable_dhcp ' , 'dns_nameservers' ,
493+ columns += ('project_id ' , 'is_dhcp_enabled ' , 'dns_nameservers' ,
485494 'allocation_pools' , 'host_routes' , 'ip_version' ,
486495 'gateway_ip' , 'service_types' )
487496
@@ -492,6 +501,8 @@ def take_action(self, parsed_args):
492501 ) for s in data ))
493502
494503
504+ # TODO(abhiraut): Use the SDK resource mapped attribute names once the
505+ # OSC minimum requirements include SDK 1.0.
495506class SetSubnet (command .Command ):
496507 _description = _ ("Set subnet properties" )
497508
@@ -576,9 +587,9 @@ def get_parser(self, prog_name):
576587 def take_action (self , parsed_args ):
577588 obj = self .app .client_manager .network .find_subnet (parsed_args .subnet ,
578589 ignore_missing = False )
579- columns = _get_columns (obj )
590+ display_columns , columns = _get_columns (obj )
580591 data = utils .get_item_properties (obj , columns , formatters = _formatters )
581- return (columns , data )
592+ return (display_columns , data )
582593
583594
584595class UnsetSubnet (command .Command ):
0 commit comments