diff options
Diffstat (limited to 'openstackclient/network')
| -rw-r--r-- | openstackclient/network/v2/router.py | 26 | ||||
| -rw-r--r-- | openstackclient/network/v2/subnet_pool.py | 8 |
2 files changed, 27 insertions, 7 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index 56630a23..a32ab5ea 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -34,11 +34,20 @@ def _format_external_gateway_info(info): return '' +def _format_routes(routes): + # Map the route keys to match --route option. + for route in routes: + if 'nexthop' in route: + route['gateway'] = route.pop('nexthop') + return utils.format_list_of_dicts(routes) + + _formatters = { 'admin_state_up': _format_admin_state, 'external_gateway_info': _format_external_gateway_info, 'availability_zones': utils.format_list, 'availability_zone_hints': utils.format_list, + 'routes': _format_routes, } @@ -67,11 +76,6 @@ def _get_attrs(client_manager, parsed_args): and parsed_args.availability_zone_hints is not None): attrs['availability_zone_hints'] = parsed_args.availability_zone_hints - if 'clear_routes' in parsed_args and parsed_args.clear_routes: - attrs['routes'] = [] - elif 'routes' in parsed_args and parsed_args.routes is not None: - attrs['routes'] = parsed_args.routes - # "router set" command doesn't support setting project. if 'project' in parsed_args and parsed_args.project is not None: identity_client = client_manager.identity @@ -393,7 +397,19 @@ class SetRouter(command.Command): client = self.app.client_manager.network obj = client.find_router(parsed_args.router, ignore_missing=False) + # Get the common attributes. attrs = _get_attrs(self.app.client_manager, parsed_args) + + # Get the route attributes. + if parsed_args.clear_routes: + attrs['routes'] = [] + elif parsed_args.routes is not None: + # Map the route keys and append to the current routes. + # The REST API will handle route validation and duplicates. + for route in parsed_args.routes: + route['nexthop'] = route.pop('gateway') + attrs['routes'] = obj.routes + parsed_args.routes + if attrs == {}: msg = "Nothing specified to be set" raise exceptions.CommandError(msg) diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 688dd2ca..f1174dda 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -78,18 +78,20 @@ def _get_attrs(client_manager, parsed_args): return attrs -def _add_prefix_options(parser): +def _add_prefix_options(parser, for_create=False): parser.add_argument( '--pool-prefix', metavar='<pool-prefix>', dest='prefixes', action='append', + required=for_create, help=_("Set subnet pool prefixes (in CIDR notation) " "(repeat option to set multiple prefixes)") ) parser.add_argument( '--default-prefix-length', metavar='<default-prefix-length>', + type=int, action=parseractions.NonNegativeAction, help=_("Set subnet pool default prefix length") ) @@ -97,11 +99,13 @@ def _add_prefix_options(parser): '--min-prefix-length', metavar='<min-prefix-length>', action=parseractions.NonNegativeAction, + type=int, help=_("Set subnet pool minimum prefix length") ) parser.add_argument( '--max-prefix-length', metavar='<max-prefix-length>', + type=int, action=parseractions.NonNegativeAction, help=_("Set subnet pool maximum prefix length") ) @@ -131,7 +135,7 @@ class CreateSubnetPool(command.ShowOne): metavar='<name>', help=_("Name of the new subnet pool") ) - _add_prefix_options(parser) + _add_prefix_options(parser, for_create=True) parser.add_argument( '--project', metavar='<project>', |
