@@ -48,6 +48,7 @@ def _format_host_routes(data):
4848 'allocation_pools' : _format_allocation_pools ,
4949 'dns_nameservers' : utils .format_list ,
5050 'host_routes' : _format_host_routes ,
51+ 'service_types' : utils .format_list ,
5152}
5253
5354
@@ -82,6 +83,16 @@ def _get_common_parse_arguments(parser):
8283 "gateway: nexthop IP address "
8384 "(repeat option to add multiple routes)" )
8485 )
86+ parser .add_argument (
87+ '--service-type' ,
88+ metavar = '<service-type>' ,
89+ action = 'append' ,
90+ dest = 'service_types' ,
91+ help = _ ("Service type for this subnet "
92+ "e.g.: network:floatingip_agent_gateway. "
93+ "Must be a valid device owner value for a network port "
94+ "(repeat option to set multiple service types)" )
95+ )
8596
8697
8798def _get_columns (item ):
@@ -177,6 +188,9 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
177188 # Change 'gateway' entry to 'nexthop' to match the API
178189 attrs ['host_routes' ] = convert_entries_to_nexthop (
179190 parsed_args .host_routes )
191+ if ('service_types' in parsed_args and
192+ parsed_args .service_types is not None ):
193+ attrs ['service_types' ] = parsed_args .service_types
180194 return attrs
181195
182196
@@ -352,6 +366,16 @@ def get_parser(self, prog_name):
352366 action = 'store_true' ,
353367 help = _ ("List subnets which have DHCP disabled" )
354368 )
369+ parser .add_argument (
370+ '--service-type' ,
371+ metavar = '<service-type>' ,
372+ action = 'append' ,
373+ dest = 'service_types' ,
374+ help = _ ("List only subnets of a given service type in output "
375+ "e.g.: network:floatingip_agent_gateway. "
376+ "Must be a valid device owner value for a network port "
377+ "(repeat option to list multiple service types)" )
378+ )
355379 return parser
356380
357381 def take_action (self , parsed_args ):
@@ -362,17 +386,19 @@ def take_action(self, parsed_args):
362386 filters ['enable_dhcp' ] = True
363387 elif parsed_args .no_dhcp :
364388 filters ['enable_dhcp' ] = False
389+ if parsed_args .service_types :
390+ filters ['service_types' ] = parsed_args .service_types
365391 data = self .app .client_manager .network .subnets (** filters )
366392
367393 headers = ('ID' , 'Name' , 'Network' , 'Subnet' )
368394 columns = ('id' , 'name' , 'network_id' , 'cidr' )
369395 if parsed_args .long :
370396 headers += ('Project' , 'DHCP' , 'Name Servers' ,
371397 'Allocation Pools' , 'Host Routes' , 'IP Version' ,
372- 'Gateway' )
398+ 'Gateway' , 'Service Types' )
373399 columns += ('tenant_id' , 'enable_dhcp' , 'dns_nameservers' ,
374400 'allocation_pools' , 'host_routes' , 'ip_version' ,
375- 'gateway_ip' )
401+ 'gateway_ip' , 'service_types' )
376402
377403 return (headers ,
378404 (utils .get_item_properties (
@@ -430,6 +456,8 @@ def take_action(self, parsed_args):
430456 attrs ['host_routes' ] += obj .host_routes
431457 if 'allocation_pools' in attrs :
432458 attrs ['allocation_pools' ] += obj .allocation_pools
459+ if 'service_types' in attrs :
460+ attrs ['service_types' ] += obj .service_types
433461 client .update_subnet (obj , ** attrs )
434462 return
435463
@@ -489,6 +517,16 @@ def get_parser(self, prog_name):
489517 'gateway: nexthop IP address '
490518 '(repeat option to unset multiple host routes)' )
491519 )
520+ parser .add_argument (
521+ '--service-type' ,
522+ metavar = '<service-type>' ,
523+ action = 'append' ,
524+ dest = 'service_types' ,
525+ help = _ ('Service type to be removed from this subnet '
526+ 'e.g.: network:floatingip_agent_gateway. '
527+ 'Must be a valid device owner value for a network port '
528+ '(repeat option to unset multiple service types)' )
529+ )
492530 parser .add_argument (
493531 'subnet' ,
494532 metavar = "<subnet>" ,
@@ -528,5 +566,13 @@ def take_action(self, parsed_args):
528566 str (error ))
529567 raise exceptions .CommandError (msg )
530568 attrs ['allocation_pools' ] = tmp_obj .allocation_pools
569+ if parsed_args .service_types :
570+ try :
571+ _update_arguments (tmp_obj .service_types ,
572+ parsed_args .service_types )
573+ except ValueError as error :
574+ msg = (_ ("%s not in service-types" ) % str (error ))
575+ raise exceptions .CommandError (msg )
576+ attrs ['service_types' ] = tmp_obj .service_types
531577 if attrs :
532578 client .update_subnet (obj , ** attrs )
0 commit comments