Debian Codegraph @

neutron_lib/api/definitions/qos.py

raw
1 # Copyright (c) 2015 Red Hat 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 import typing
17
18 from neutron_lib.api import converters
19 from neutron_lib.api.definitions import network
20 from neutron_lib.api.definitions import port
21 from neutron_lib import constants
22 from neutron_lib.db import constants as db_const
23 from neutron_lib.services.qos import constants as qos_const
24
25
26 BANDWIDTH_LIMIT_RULES = "bandwidth_limit_rules"
27 RULE_TYPES = "rule_types"
28 POLICIES = 'policies'
29 POLICY = 'policy'
30 DSCP_MARKING_RULES = 'dscp_marking_rules'
31 MIN_BANDWIDTH_RULES = 'minimum_bandwidth_rules'
32 _QOS_RULE_COMMON_FIELDS = {
33 'id': {
34 'allow_post': False, 'allow_put': False,
35 'validate': {'type:uuid': None},
36 'is_visible': True,
37 'is_filter': True,
38 'is_sort_key': True,
39 'primary_key': True
40 }
41 }
42
43 ALIAS = 'qos'
44 IS_SHIM_EXTENSION = False
45 IS_STANDARD_ATTR_EXTENSION = False
46 NAME = 'Quality of Service'
47 API_PREFIX = '/' + ALIAS
48 DESCRIPTION = 'The Quality of Service extension.'
49 UPDATED_TIMESTAMP = '2015-06-08T10:00:00-00:00'
50 RESOURCE_ATTRIBUTE_MAP = {
51 POLICIES: {
52 'id': {
53 'allow_post': False, 'allow_put': False,
54 'validate': {'type:uuid': None},
55 'is_filter': True, 'is_sort_key': True,
56 'is_visible': True, 'primary_key': True
57 },
58 'name': {
59 'allow_post': True, 'allow_put': True,
60 'is_visible': True, 'default': '',
61 'is_filter': True, 'is_sort_key': True,
62 'validate': {'type:string': db_const.NAME_FIELD_SIZE}},
63 constants.SHARED: {
64 'allow_post': True, 'allow_put': True,
65 'is_visible': True, 'default': False,
66 'is_filter': True,
67 'convert_to': converters.convert_to_boolean
68 },
69 'tenant_id': {
70 'allow_post': True, 'allow_put': False,
71 'required_by_policy': True,
72 'validate': {'type:string': db_const.PROJECT_ID_FIELD_SIZE},
73 'is_filter': True, 'is_sort_key': True,
74 'is_visible': True
75 },
76 'rules': {
77 'allow_post': False,
78 'allow_put': False,
79 'is_visible': True
80 }
81 },
82 RULE_TYPES: {
83 'type': {
84 'allow_post': False, 'allow_put': False,
85 'is_visible': True
86 }
87 },
88 port.COLLECTION_NAME: {
89 qos_const.QOS_POLICY_ID: {
90 'allow_post': True,
91 'allow_put': True,
92 'is_visible': True,
93 'default': None,
94 'enforce_policy': True,
95 'validate': {'type:uuid_or_none': None}
96 }
97 },
98 network.COLLECTION_NAME: {
99 qos_const.QOS_POLICY_ID: {
100 'allow_post': True,
101 'allow_put': True,
102 'is_visible': True,
103 'default': None,
104 'enforce_policy': True,
105 'validate': {'type:uuid_or_none': None}
106 }
107 }
108 }
109 _PARENT = {
110 'collection_name': POLICIES,
111 'member_name': POLICY
112 }
113 SUB_RESOURCE_ATTRIBUTE_MAP: dict[str, typing.Any] = {
114 BANDWIDTH_LIMIT_RULES: {
115 'parent': _PARENT,
116 'parameters': dict(
117 _QOS_RULE_COMMON_FIELDS,
118 **{qos_const.MAX_KBPS: {
119 'allow_post': True, 'allow_put': True,
120 'convert_to': converters.convert_to_int,
121 'is_visible': True,
122 'is_filter': True,
123 'is_sort_key': True,
124 'validate': {
125 'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]}
126 },
127 qos_const.MAX_BURST: {
128 'allow_post': True, 'allow_put': True,
129 'is_visible': True, 'default': 0,
130 'is_filter': True,
131 'is_sort_key': True,
132 'convert_to': converters.convert_to_int,
133 'validate': {
134 'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]}}}),
135 },
136 DSCP_MARKING_RULES: {
137 'parent': _PARENT,
138 'parameters': dict(
139 _QOS_RULE_COMMON_FIELDS,
140 **{qos_const.DSCP_MARK: {
141 'allow_post': True, 'allow_put': True,
142 'convert_to': converters.convert_to_int,
143 'is_visible': True,
144 'is_filter': True,
145 'is_sort_key': True,
146 'validate': {
147 'type:values': constants.VALID_DSCP_MARKS}}})
148 },
149 MIN_BANDWIDTH_RULES: {
150 'parent': _PARENT,
151 'parameters': dict(
152 _QOS_RULE_COMMON_FIELDS,
153 **{qos_const.MIN_KBPS: {
154 'allow_post': True, 'allow_put': True,
155 'is_visible': True,
156 'is_filter': True,
157 'is_sort_key': True,
158 'convert_to': converters.convert_to_int,
159 'validate': {
160 'type:range': [0, db_const.DB_INTEGER_MAX_VALUE]}},
161 qos_const.DIRECTION: {
162 'allow_post': True, 'allow_put': True,
163 'is_visible': True, 'default': constants.EGRESS_DIRECTION,
164 'is_filter': True,
165 'is_sort_key': True,
166 'validate': {
167 'type:values': [constants.EGRESS_DIRECTION]}}})
168 }
169 }
170 ACTION_MAP = {}
171 REQUIRED_EXTENSIONS = []
172 OPTIONAL_EXTENSIONS = []
173 ACTION_STATUS = {}