| 1 |
# Copyright (c) 2016 Intel Corporation. |
| 2 |
# All Rights Reserved |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
# |
| 16 |
|
| 17 |
from neutronclient._i18n import _ |
| 18 |
from neutronclient.common import utils |
| 19 |
from neutronclient.neutron import v2_0 as neutronv20 |
| 20 |
from neutronclient.neutron.v2_0.qos import rule as qos_rule |
| 21 |
|
| 22 |
|
| 23 |
MINIMUM_BANDWIDTH_RULE_RESOURCE = 'minimum_bandwidth_rule' |
| 24 |
|
| 25 |
|
| 26 |
def add_minimum_bandwidth_arguments(parser): |
| 27 |
parser.add_argument( |
| 28 |
'--min-kbps', |
| 29 |
required=True, |
| 30 |
type=str, |
| 31 |
help=_('QoS minimum bandwidth assurance, expressed in kilobits ' |
| 32 |
'per second.')) |
| 33 |
# NOTE(ralonsoh): the only direction implemented is "egress". Please, |
| 34 |
# refer to the spec (https://review.opendev.org/#/c/316082/). |
| 35 |
parser.add_argument( |
| 36 |
'--direction', |
| 37 |
# NOTE(ihrachys): though server picks the default for us (egress), it's |
| 38 |
# better to require the argument to make the UI more explicit and the |
| 39 |
# intentions more clear in the future when we add other values for the |
| 40 |
# attribute on server side. |
| 41 |
required=True, |
| 42 |
type=utils.convert_to_lowercase, |
| 43 |
choices=['egress'], |
| 44 |
help=_('Traffic direction.')) |
| 45 |
|
| 46 |
|
| 47 |
def update_minimum_bandwidth_args2body(parsed_args, body): |
| 48 |
neutronv20.update_dict(parsed_args, body, ['min_kbps', 'direction']) |
| 49 |
|
| 50 |
|
| 51 |
class CreateQoSMinimumBandwidthRule(qos_rule.QosRuleMixin, |
| 52 |
neutronv20.CreateCommand): |
| 53 |
"""Create a qos minimum bandwidth rule.""" |
| 54 |
|
| 55 |
resource = MINIMUM_BANDWIDTH_RULE_RESOURCE |
| 56 |
|
| 57 |
def add_known_arguments(self, parser): |
| 58 |
super(CreateQoSMinimumBandwidthRule, self).add_known_arguments( |
| 59 |
parser) |
| 60 |
add_minimum_bandwidth_arguments(parser) |
| 61 |
|
| 62 |
def args2body(self, parsed_args): |
| 63 |
body = {} |
| 64 |
update_minimum_bandwidth_args2body(parsed_args, body) |
| 65 |
return {self.resource: body} |
| 66 |
|
| 67 |
|
| 68 |
class ListQoSMinimumBandwidthRules(qos_rule.QosRuleMixin, |
| 69 |
neutronv20.ListCommand): |
| 70 |
"""List all qos minimum bandwidth rules belonging to the specified policy. |
| 71 |
|
| 72 |
""" |
| 73 |
|
| 74 |
resource = MINIMUM_BANDWIDTH_RULE_RESOURCE |
| 75 |
_formatters = {} |
| 76 |
pagination_support = True |
| 77 |
sorting_support = True |
| 78 |
|
| 79 |
|
| 80 |
class ShowQoSMinimumBandwidthRule(qos_rule.QosRuleMixin, |
| 81 |
neutronv20.ShowCommand): |
| 82 |
"""Show information about the given qos minimum bandwidth rule.""" |
| 83 |
|
| 84 |
resource = MINIMUM_BANDWIDTH_RULE_RESOURCE |
| 85 |
allow_names = False |
| 86 |
|
| 87 |
|
| 88 |
class UpdateQoSMinimumBandwidthRule(qos_rule.QosRuleMixin, |
| 89 |
neutronv20.UpdateCommand): |
| 90 |
"""Update the given qos minimum bandwidth rule.""" |
| 91 |
|
| 92 |
resource = MINIMUM_BANDWIDTH_RULE_RESOURCE |
| 93 |
allow_names = False |
| 94 |
|
| 95 |
def add_known_arguments(self, parser): |
| 96 |
super(UpdateQoSMinimumBandwidthRule, self).add_known_arguments( |
| 97 |
parser) |
| 98 |
add_minimum_bandwidth_arguments(parser) |
| 99 |
|
| 100 |
def args2body(self, parsed_args): |
| 101 |
body = {} |
| 102 |
update_minimum_bandwidth_args2body(parsed_args, body) |
| 103 |
return {self.resource: body} |
| 104 |
|
| 105 |
|
| 106 |
class DeleteQoSMinimumBandwidthRule(qos_rule.QosRuleMixin, |
| 107 |
neutronv20.DeleteCommand): |
| 108 |
"""Delete a given qos minimum bandwidth rule.""" |
| 109 |
|
| 110 |
resource = MINIMUM_BANDWIDTH_RULE_RESOURCE |
| 111 |
allow_names = False |