@@ -57,7 +57,7 @@ def _format_host_routes(data):
5757}
5858
5959
60- def _get_common_parse_arguments (parser ):
60+ def _get_common_parse_arguments (parser , is_create = True ):
6161 parser .add_argument (
6262 '--allocation-pool' ,
6363 metavar = 'start=<ip-address>,end=<ip-address>' ,
@@ -68,6 +68,14 @@ def _get_common_parse_arguments(parser):
6868 "e.g.: start=192.168.199.2,end=192.168.199.254 "
6969 "(repeat option to add multiple IP addresses)" )
7070 )
71+ if not is_create :
72+ parser .add_argument (
73+ '--no-allocation-pool' ,
74+ action = 'store_true' ,
75+ help = _ ("Clear associated allocation-pools from the subnet. "
76+ "Specify both --allocation-pool and --no-allocation-pool "
77+ "to overwrite the current allocation pool information." )
78+ )
7179 parser .add_argument (
7280 '--dns-nameserver' ,
7381 metavar = '<dns-nameserver>' ,
@@ -88,6 +96,14 @@ def _get_common_parse_arguments(parser):
8896 "gateway: nexthop IP address "
8997 "(repeat option to add multiple routes)" )
9098 )
99+ if not is_create :
100+ parser .add_argument (
101+ '--no-host-route' ,
102+ action = 'store_true' ,
103+ help = _ ("Clear associated host-routes from the subnet. "
104+ "Specify both --host-route and --no-host-route "
105+ "to overwrite the current host route information." )
106+ )
91107 parser .add_argument (
92108 '--service-type' ,
93109 metavar = '<service-type>' ,
@@ -508,7 +524,7 @@ def get_parser(self, prog_name):
508524 metavar = '<description>' ,
509525 help = _ ("Set subnet description" )
510526 )
511- _get_common_parse_arguments (parser )
527+ _get_common_parse_arguments (parser , is_create = False )
512528 return parser
513529
514530 def take_action (self , parsed_args ):
@@ -519,9 +535,15 @@ def take_action(self, parsed_args):
519535 if 'dns_nameservers' in attrs :
520536 attrs ['dns_nameservers' ] += obj .dns_nameservers
521537 if 'host_routes' in attrs :
522- attrs ['host_routes' ] += obj .host_routes
538+ if not parsed_args .no_host_route :
539+ attrs ['host_routes' ] += obj .host_routes
540+ elif parsed_args .no_host_route :
541+ attrs ['host_routes' ] = ''
523542 if 'allocation_pools' in attrs :
524- attrs ['allocation_pools' ] += obj .allocation_pools
543+ if not parsed_args .no_allocation_pool :
544+ attrs ['allocation_pools' ] += obj .allocation_pools
545+ elif parsed_args .no_allocation_pool :
546+ attrs ['allocation_pools' ] = ''
525547 if 'service_types' in attrs :
526548 attrs ['service_types' ] += obj .service_types
527549 client .update_subnet (obj , ** attrs )
0 commit comments