@@ -34,11 +34,20 @@ def _format_external_gateway_info(info):
3434 return ''
3535
3636
37+ def _format_routes (routes ):
38+ # Map the route keys to match --route option.
39+ for route in routes :
40+ if 'nexthop' in route :
41+ route ['gateway' ] = route .pop ('nexthop' )
42+ return utils .format_list_of_dicts (routes )
43+
44+
3745_formatters = {
3846 'admin_state_up' : _format_admin_state ,
3947 'external_gateway_info' : _format_external_gateway_info ,
4048 'availability_zones' : utils .format_list ,
4149 'availability_zone_hints' : utils .format_list ,
50+ 'routes' : _format_routes ,
4251}
4352
4453
@@ -67,11 +76,6 @@ def _get_attrs(client_manager, parsed_args):
6776 and parsed_args .availability_zone_hints is not None ):
6877 attrs ['availability_zone_hints' ] = parsed_args .availability_zone_hints
6978
70- if 'clear_routes' in parsed_args and parsed_args .clear_routes :
71- attrs ['routes' ] = []
72- elif 'routes' in parsed_args and parsed_args .routes is not None :
73- attrs ['routes' ] = parsed_args .routes
74-
7579 # "router set" command doesn't support setting project.
7680 if 'project' in parsed_args and parsed_args .project is not None :
7781 identity_client = client_manager .identity
@@ -393,7 +397,19 @@ def take_action(self, parsed_args):
393397 client = self .app .client_manager .network
394398 obj = client .find_router (parsed_args .router , ignore_missing = False )
395399
400+ # Get the common attributes.
396401 attrs = _get_attrs (self .app .client_manager , parsed_args )
402+
403+ # Get the route attributes.
404+ if parsed_args .clear_routes :
405+ attrs ['routes' ] = []
406+ elif parsed_args .routes is not None :
407+ # Map the route keys and append to the current routes.
408+ # The REST API will handle route validation and duplicates.
409+ for route in parsed_args .routes :
410+ route ['nexthop' ] = route .pop ('gateway' )
411+ attrs ['routes' ] = obj .routes + parsed_args .routes
412+
397413 if attrs == {}:
398414 msg = "Nothing specified to be set"
399415 raise exceptions .CommandError (msg )
0 commit comments