| 1 |
# Copyright 2016 Comcast, Inc. |
| 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 exceptions |
| 19 |
from neutronclient.neutron import v2_0 as neutronv20 |
| 20 |
from neutronclient.neutron.v2_0.qos import rule as qos_rule |
| 21 |
|
| 22 |
|
| 23 |
DSCP_MARKING_RESOURCE = 'dscp_marking_rule' |
| 24 |
# DSCP DETAILS |
| 25 |
# 0 - none | 8 - cs1 | 10 - af11 | 12 - af12 | 14 - af13 | |
| 26 |
# 16 - cs2 | 18 - af21 | 20 - af22 | 22 - af23 | 24 - cs3 | |
| 27 |
# 26 - af31 | 28 - af32 | 30 - af33 | 32 - cs4 | 34 - af41 | |
| 28 |
# 36 - af42 | 38 - af43 | 40 - cs5 | 46 - ef | 48 - cs6 | |
| 29 |
# 56 - cs7 |
| 30 |
|
| 31 |
DSCP_VALID_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, |
| 32 |
34, 36, 38, 40, 46, 48, 56] |
| 33 |
|
| 34 |
|
| 35 |
def add_dscp_marking_arguments(parser): |
| 36 |
parser.add_argument( |
| 37 |
'--dscp-mark', |
| 38 |
required=True, |
| 39 |
type=str, |
| 40 |
help=_('DSCP mark: value can be 0, even numbers from 8-56, \ |
| 41 |
excluding 42, 44, 50, 52, and 54.')) |
| 42 |
|
| 43 |
|
| 44 |
def update_dscp_args2body(parsed_args, body): |
| 45 |
dscp_mark = parsed_args.dscp_mark |
| 46 |
if int(dscp_mark) not in DSCP_VALID_MARKS: |
| 47 |
raise exceptions.CommandError(_("DSCP mark: %s not supported. " |
| 48 |
"Please note value can either be 0 " |
| 49 |
"or any even number from 8-56 " |
| 50 |
"excluding 42, 44, 50, 52 and " |
| 51 |
"54.") % dscp_mark) |
| 52 |
neutronv20.update_dict(parsed_args, body, |
| 53 |
['dscp_mark']) |
| 54 |
|
| 55 |
|
| 56 |
class CreateQoSDscpMarkingRule(qos_rule.QosRuleMixin, |
| 57 |
neutronv20.CreateCommand): |
| 58 |
"""Create a QoS DSCP marking rule.""" |
| 59 |
|
| 60 |
resource = DSCP_MARKING_RESOURCE |
| 61 |
|
| 62 |
def add_known_arguments(self, parser): |
| 63 |
super(CreateQoSDscpMarkingRule, self).add_known_arguments(parser) |
| 64 |
add_dscp_marking_arguments(parser) |
| 65 |
|
| 66 |
def args2body(self, parsed_args): |
| 67 |
body = {} |
| 68 |
update_dscp_args2body(parsed_args, body) |
| 69 |
return {self.resource: body} |
| 70 |
|
| 71 |
|
| 72 |
class ListQoSDscpMarkingRules(qos_rule.QosRuleMixin, |
| 73 |
neutronv20.ListCommand): |
| 74 |
"""List all QoS DSCP marking rules belonging to the specified policy.""" |
| 75 |
|
| 76 |
_formatters = {} |
| 77 |
pagination_support = True |
| 78 |
sorting_support = True |
| 79 |
resource = DSCP_MARKING_RESOURCE |
| 80 |
|
| 81 |
|
| 82 |
class ShowQoSDscpMarkingRule(qos_rule.QosRuleMixin, |
| 83 |
neutronv20.ShowCommand): |
| 84 |
"""Show information about the given qos dscp marking rule.""" |
| 85 |
|
| 86 |
resource = DSCP_MARKING_RESOURCE |
| 87 |
allow_names = False |
| 88 |
|
| 89 |
|
| 90 |
class UpdateQoSDscpMarkingRule(qos_rule.QosRuleMixin, |
| 91 |
neutronv20.UpdateCommand): |
| 92 |
"""Update the given QoS DSCP marking rule.""" |
| 93 |
|
| 94 |
allow_names = False |
| 95 |
resource = DSCP_MARKING_RESOURCE |
| 96 |
|
| 97 |
def add_known_arguments(self, parser): |
| 98 |
super(UpdateQoSDscpMarkingRule, self).add_known_arguments(parser) |
| 99 |
add_dscp_marking_arguments(parser) |
| 100 |
|
| 101 |
def args2body(self, parsed_args): |
| 102 |
body = {} |
| 103 |
update_dscp_args2body(parsed_args, body) |
| 104 |
return {self.resource: body} |
| 105 |
|
| 106 |
|
| 107 |
class DeleteQoSDscpMarkingRule(qos_rule.QosRuleMixin, |
| 108 |
neutronv20.DeleteCommand): |
| 109 |
"""Delete a given qos dscp marking rule.""" |
| 110 |
|
| 111 |
allow_names = False |
| 112 |
resource = DSCP_MARKING_RESOURCE |