diff options
| author | LIU Yulong <i@liuyulong.me> | 2018-07-18 15:28:51 +0800 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2018-12-10 17:20:38 +0000 |
| commit | fd23025227a07e879e0b29c67063401b1d392518 (patch) | |
| tree | 3019d1284ea5a51666812d8c62249e39096a1b92 /openstackclient/network/v2 | |
| parent | 8be53a50e5278281640b5023c4d8c4b28da22cb9 (diff) | |
| download | python-openstackclient-fd23025227a07e879e0b29c67063401b1d392518.tar.gz | |
Supports router gateway IP QoS
Adds --qos-policy and --no-qos-policy to `openstack router set`:
--qos-policy <qos-policy> Attach QoS policy to router gateway IPs
--no-qos-policy Remove QoS policy from router gateway IPs
Adds --qos-policy to `openstack router unset`:
--qos-policy Remove QoS policy from router gateway IPs
Partially-Implements blueprint: router-gateway-ip-qos
Closes-Bug: #1757044
Change-Id: Ifec3b2cf9bdb59513c8bcd7bd60305506a071192
Diffstat (limited to 'openstackclient/network/v2')
| -rw-r--r-- | openstackclient/network/v2/router.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index 746452e4..a3a4eb75 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -579,6 +579,17 @@ class SetRouter(command.Command): action='store_true', help=_("Disable Source NAT on external gateway") ) + qos_policy_group = parser.add_mutually_exclusive_group() + qos_policy_group.add_argument( + '--qos-policy', + metavar='<qos-policy>', + help=_("Attach QoS policy to router gateway IPs") + ) + qos_policy_group.add_argument( + '--no-qos-policy', + action='store_true', + help=_("Remove QoS policy from router gateway IPs") + ) _tag.add_tag_option_to_parser_for_set(parser, _('router')) return parser @@ -638,6 +649,27 @@ class SetRouter(command.Command): ips.append(ip_spec) gateway_info['external_fixed_ips'] = ips attrs['external_gateway_info'] = gateway_info + + if ((parsed_args.qos_policy or parsed_args.no_qos_policy) and + not parsed_args.external_gateway): + try: + original_net_id = obj.external_gateway_info['network_id'] + except (KeyError, TypeError): + msg = (_("You must specify '--external-gateway' or the router " + "must already have an external network in order to " + "set router gateway IP QoS")) + raise exceptions.CommandError(msg) + else: + if not attrs.get('external_gateway_info'): + attrs['external_gateway_info'] = {} + attrs['external_gateway_info']['network_id'] = original_net_id + if parsed_args.qos_policy: + check_qos_id = client.find_qos_policy( + parsed_args.qos_policy, ignore_missing=False).id + attrs['external_gateway_info']['qos_policy_id'] = check_qos_id + + if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy: + attrs['external_gateway_info']['qos_policy_id'] = None if attrs: client.update_router(obj, **attrs) # tags is a subresource and it needs to be updated separately. @@ -702,6 +734,12 @@ class UnsetRouter(command.Command): default=False, help=_("Remove external gateway information from the router")) parser.add_argument( + '--qos-policy', + action='store_true', + default=False, + help=_("Remove QoS policy from router gateway IPs") + ) + parser.add_argument( 'router', metavar="<router>", help=_("Router to modify (name or ID)") @@ -713,6 +751,7 @@ class UnsetRouter(command.Command): client = self.app.client_manager.network obj = client.find_router(parsed_args.router, ignore_missing=False) tmp_routes = copy.deepcopy(obj.routes) + tmp_external_gateway_info = copy.deepcopy(obj.external_gateway_info) attrs = {} if parsed_args.routes: try: @@ -723,6 +762,20 @@ class UnsetRouter(command.Command): msg = (_("Router does not contain route %s") % route) raise exceptions.CommandError(msg) attrs['routes'] = tmp_routes + if parsed_args.qos_policy: + try: + if (tmp_external_gateway_info['network_id'] and + tmp_external_gateway_info['qos_policy_id']): + pass + except (KeyError, TypeError): + msg = _("Router does not have external network or qos policy") + raise exceptions.CommandError(msg) + else: + attrs['external_gateway_info'] = { + 'network_id': tmp_external_gateway_info['network_id'], + 'qos_policy_id': None + } + if parsed_args.external_gateway: attrs['external_gateway_info'] = {} if attrs: |
