Skip to content

Commit a7fd675

Browse files
author
Rodolfo Alonso Hernandez
committed
Add QoS bandwidth limit rule object and CRUD commands.
Closes-Bug: 1611830 Depends-On: Idf319cd182304952071bc976a2e56c42fbcb8468 Change-Id: I2ad5f09eebd3374f29b3d67887c542ec6ca60c81
1 parent d0c7359 commit a7fd675

File tree

7 files changed

+383
-0
lines changed

7 files changed

+383
-0
lines changed

doc/source/users/resources/network/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Network Resources
1919
v2/pool
2020
v2/pool_member
2121
v2/port
22+
v2/qos_bandwidth_limit_rule
2223
v2/qos_dscp_marking_rule
2324
v2/qos_minimum_bandwidth_rule
2425
v2/qos_policy
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openstack.network.v2.qos_bandwidth_limit_rule
2+
=============================================
3+
4+
.. automodule:: openstack.network.v2.qos_bandwidth_limit_rule
5+
6+
The QoSBandwidthLimitRule Class
7+
-------------------------------
8+
9+
The ``QoSBandwidthLimitRule`` class inherits from :class:`~openstack.resource.Resource`.
10+
11+
.. autoclass:: openstack.network.v2.qos_bandwidth_limit_rule.QoSBandwidthLimitRule
12+
:members:

openstack/network/v2/_proxy.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
from openstack.network.v2 import pool as _pool
2626
from openstack.network.v2 import pool_member as _pool_member
2727
from openstack.network.v2 import port as _port
28+
from openstack.network.v2 import qos_bandwidth_limit_rule as \
29+
_qos_bandwidth_limit_rule
2830
from openstack.network.v2 import qos_dscp_marking_rule as \
2931
_qos_dscp_marking_rule
3032
from openstack.network.v2 import qos_minimum_bandwidth_rule as \
@@ -1148,6 +1150,132 @@ def get_subnet_ports(self, subnet_id):
11481150
result.append(puerta)
11491151
return result
11501152

1153+
def create_qos_bandwidth_limit_rule(self, qos_policy, **attrs):
1154+
"""Create a new bandwidth limit rule
1155+
1156+
:param dict attrs: Keyword arguments which will be used to create
1157+
a :class:`~openstack.network.v2.
1158+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule`,
1159+
comprised of the properties on the
1160+
QoSBandwidthLimitRule class.
1161+
:param qos_policy: The value can be the ID of the QoS policy that the
1162+
rule belongs or a :class:`~openstack.network.v2.
1163+
qos_policy.QoSPolicy` instance.
1164+
1165+
:returns: The results of resource creation
1166+
:rtype: :class:`~openstack.network.v2.qos_bandwidth_limit_rule.
1167+
QoSBandwidthLimitRule`
1168+
"""
1169+
qos_policy_id = resource.Resource.get_id(qos_policy)
1170+
return self._create(
1171+
_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
1172+
path_args={'qos_policy_id': qos_policy_id}, **attrs)
1173+
1174+
def delete_qos_bandwidth_limit_rule(self, qos_rule, qos_policy,
1175+
ignore_missing=True):
1176+
"""Delete a bandwidth limit rule
1177+
1178+
:param qos_rule: The value can be either the ID of a bandwidth limit
1179+
rule or a :class:`~openstack.network.v2.
1180+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule`
1181+
instance.
1182+
:param qos_policy: The value can be the ID of the QoS policy that the
1183+
rule belongs or a :class:`~openstack.network.v2.
1184+
qos_policy.QoSPolicy` instance.
1185+
:param bool ignore_missing: When set to ``False``
1186+
:class:`~openstack.exceptions.ResourceNotFound` will be
1187+
raised when the resource does not exist.
1188+
When set to ``True``, no exception will be set when
1189+
attempting to delete a nonexistent bandwidth limit rule.
1190+
1191+
:returns: ``None``
1192+
"""
1193+
qos_policy_id = resource.Resource.get_id(qos_policy)
1194+
self._delete(_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
1195+
qos_rule, ignore_missing=ignore_missing,
1196+
path_args={'qos_policy_id': qos_policy_id})
1197+
1198+
def find_qos_bandwidth_limit_rule(self, qos_rule_id, qos_policy,
1199+
ignore_missing=True):
1200+
"""Find a bandwidth limit rule
1201+
1202+
:param qos_rule_id: The ID of a bandwidth limit rule.
1203+
:param qos_policy: The value can be the ID of the QoS policy that the
1204+
rule belongs or a :class:`~openstack.network.v2.
1205+
qos_policy.QoSPolicy` instance.
1206+
:param bool ignore_missing: When set to ``False``
1207+
:class:`~openstack.exceptions.ResourceNotFound` will be
1208+
raised when the resource does not exist.
1209+
When set to ``True``, None will be returned when
1210+
attempting to find a nonexistent resource.
1211+
:returns: One :class:`~openstack.network.v2.qos_bandwidth_limit_rule.
1212+
QoSBandwidthLimitRule` or None
1213+
"""
1214+
qos_policy_id = resource.Resource.get_id(qos_policy)
1215+
return self._find(_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
1216+
qos_rule_id, ignore_missing=ignore_missing,
1217+
path_args={'qos_policy_id': qos_policy_id})
1218+
1219+
def get_qos_bandwidth_limit_rule(self, qos_rule, qos_policy):
1220+
"""Get a single bandwidth limit rule
1221+
1222+
:param qos_rule: The value can be the ID of a minimum bandwidth rule or
1223+
a :class:`~openstack.network.v2.
1224+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule`
1225+
instance.
1226+
:param qos_policy: The value can be the ID of the QoS policy that the
1227+
rule belongs or a :class:`~openstack.network.v2.
1228+
qos_policy.QoSPolicy` instance.
1229+
:returns: One :class:`~openstack.network.v2.qos_bandwidth_limit_rule.
1230+
QoSBandwidthLimitRule`
1231+
:raises: :class:`~openstack.exceptions.ResourceNotFound`
1232+
when no resource can be found.
1233+
"""
1234+
qos_policy_id = resource.Resource.get_id(qos_policy)
1235+
return self._get(_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
1236+
qos_rule, path_args={'qos_policy_id': qos_policy_id})
1237+
1238+
def qos_bandwidth_limit_rules(self, qos_policy, **query):
1239+
"""Return a generator of bandwidth limit rules
1240+
1241+
:param qos_policy: The value can be the ID of the QoS policy that the
1242+
rule belongs or a :class:`~openstack.network.v2.
1243+
qos_policy.QoSPolicy` instance.
1244+
:param kwargs \*\*query: Optional query parameters to be sent to limit
1245+
the resources being returned.
1246+
:returns: A generator of bandwidth limit rule objects
1247+
:rtype: :class:`~openstack.network.v2.qos_bandwidth_limit_rule.
1248+
QoSBandwidthLimitRule`
1249+
"""
1250+
qos_policy_id = resource.Resource.get_id(qos_policy)
1251+
return self._list(_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
1252+
paginated=False,
1253+
path_args={'qos_policy_id': qos_policy_id}, **query)
1254+
1255+
def update_qos_bandwidth_limit_rule(self, qos_rule, qos_policy,
1256+
**attrs):
1257+
"""Update a bandwidth limit rule
1258+
1259+
:param qos_rule: Either the id of a bandwidth limit rule or a
1260+
:class:`~openstack.network.v2.
1261+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule`
1262+
instance.
1263+
:param qos_policy: The value can be the ID of the QoS policy that the
1264+
rule belongs or a :class:`~openstack.network.v2.
1265+
qos_policy.QoSPolicy` instance.
1266+
:attrs kwargs: The attributes to update on the bandwidth limit rule
1267+
represented by ``value``.
1268+
1269+
:returns: The updated minimum bandwidth rule
1270+
:rtype: :class:`~openstack.network.v2.qos_bandwidth_limit_rule.
1271+
QoSBandwidthLimitRule`
1272+
"""
1273+
qos_policy_id = resource.Resource.get_id(qos_policy)
1274+
return self._update(_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
1275+
qos_rule,
1276+
path_args={'qos_policy_id': qos_policy_id},
1277+
**attrs)
1278+
11511279
def create_qos_dscp_marking_rule(self, qos_policy, **attrs):
11521280
"""Create a new QoS DSCP marking rule
11531281
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack.network import network_service
14+
from openstack import resource
15+
16+
17+
class QoSBandwidthLimitRule(resource.Resource):
18+
resource_key = 'bandwidth_limit_rule'
19+
resources_key = 'bandwidth_limit_rules'
20+
base_path = '/qos/policies/%(qos_policy_id)s/bandwidth_limit_rules'
21+
service = network_service.NetworkService()
22+
23+
# capabilities
24+
allow_create = True
25+
allow_retrieve = True
26+
allow_update = True
27+
allow_delete = True
28+
allow_list = True
29+
30+
# Properties
31+
#: QoS bandwidth limit rule id.
32+
id = resource.prop('id')
33+
#: The ID of the QoS policy who owns rule.
34+
qos_policy_id = resource.prop('qos_policy_id')
35+
#: Maximum bandwidth in kbps.
36+
max_kbps = resource.prop('max_kbps')
37+
#: Maximum burst bandwidth in kbps.
38+
max_burst_kbps = resource.prop('max_burst_kbps')
39+
# NOTE(ralonsoh): to be implemented in bug 1560961
40+
#: Traffic direction from the tenant point of view ('egress', 'ingress').
41+
# direction = resource.prop('direction')
42+
43+
@classmethod
44+
def _get_create_body(cls, attrs):
45+
# Exclude qos_policy_id from attrs since it is not expected by QoS API.
46+
if 'qos_policy_id' in attrs:
47+
attrs.pop('qos_policy_id')
48+
49+
return {cls.resource_key: attrs}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import uuid
14+
15+
from openstack.network.v2 import (qos_bandwidth_limit_rule as
16+
_qos_bandwidth_limit_rule)
17+
from openstack.tests.functional import base
18+
19+
20+
class TestQoSBandwidthLimitRule(base.BaseFunctionalTest):
21+
22+
QOS_POLICY_ID = None
23+
QOS_POLICY_NAME = uuid.uuid4().hex
24+
QOS_IS_SHARED = False
25+
QOS_POLICY_DESCRIPTION = "QoS policy description"
26+
RULE_ID = uuid.uuid4().hex
27+
RULE_MAX_KBPS = 1500
28+
RULE_MAX_KBPS_NEW = 1800
29+
RULE_MAX_BURST_KBPS = 1100
30+
RULE_MAX_BURST_KBPS_NEW = 1300
31+
# NOTE(ralonsoh): to be implemented in bug 1560961.
32+
# New checks must be added.
33+
# RULE_DIRECTION = 'egress'
34+
# RULE_DIRECTION_NEW = 'ingress'
35+
36+
@classmethod
37+
def setUpClass(cls):
38+
super(TestQoSBandwidthLimitRule, cls).setUpClass()
39+
qos_policy = cls.conn.network.create_qos_policy(
40+
description=cls.QOS_POLICY_DESCRIPTION,
41+
name=cls.QOS_POLICY_NAME,
42+
shared=cls.QOS_IS_SHARED,
43+
)
44+
cls.QOS_POLICY_ID = qos_policy.id
45+
qos_rule = cls.conn.network.create_qos_bandwidth_limit_rule(
46+
cls.QOS_POLICY_ID, max_kbps=cls.RULE_MAX_KBPS,
47+
max_burst_kbps=cls.RULE_MAX_BURST_KBPS,
48+
)
49+
assert isinstance(qos_rule,
50+
_qos_bandwidth_limit_rule.QoSBandwidthLimitRule)
51+
cls.assertIs(cls.RULE_MAX_KBPS, qos_rule.max_kbps)
52+
cls.assertIs(cls.RULE_MAX_BURST_KBPS, qos_rule.max_burst_kbps)
53+
cls.RULE_ID = qos_rule.id
54+
55+
@classmethod
56+
def tearDownClass(cls):
57+
rule = cls.conn.network.delete_qos_minimum_bandwidth_rule(
58+
cls.RULE_ID,
59+
cls.QOS_POLICY_ID)
60+
qos_policy = cls.conn.network.delete_qos_policy(cls.QOS_POLICY_ID)
61+
cls.assertIs(None, rule)
62+
cls.assertIs(None, qos_policy)
63+
64+
def test_find(self):
65+
sot = self.conn.network.find_qos_bandwidth_limit_rule(
66+
self.RULE_ID,
67+
self.QOS_POLICY_ID)
68+
self.assertEqual(self.RULE_ID, sot.id)
69+
self.assertEqual(self.RULE_MAX_KBPS, sot.max_kbps)
70+
self.assertEqual(self.RULE_MAX_BURST_KBPS, sot.max_burst_kbps)
71+
72+
def test_get(self):
73+
sot = self.conn.network.get_qos_bandwidth_limit_rule(
74+
self.RULE_ID,
75+
self.QOS_POLICY_ID)
76+
self.assertEqual(self.RULE_ID, sot.id)
77+
self.assertEqual(self.QOS_POLICY_ID, sot.qos_policy_id)
78+
self.assertEqual(self.RULE_MAX_KBPS, sot.max_kbps)
79+
self.assertEqual(self.RULE_MAX_BURST_KBPS, sot.max_burst_kbps)
80+
81+
def test_list(self):
82+
rule_ids = [o.id for o in
83+
self.conn.network.qos_bandwidth_limit_rules(
84+
self.QOS_POLICY_ID)]
85+
self.assertIn(self.RULE_ID, rule_ids)
86+
87+
def test_update(self):
88+
sot = self.conn.network.update_qos_bandwidth_limit_rule(
89+
self.RULE_ID,
90+
self.QOS_POLICY_ID,
91+
max_kbps=self.RULE_MAX_KBPS_NEW,
92+
max_burst_kbps=self.RULE_MAX_BURST_KBPS_NEW)
93+
self.assertEqual(self.RULE_MAX_KBPS_NEW, sot.max_kbps)
94+
self.assertEqual(self.RULE_MAX_BURST_KBPS_NEW, sot.max_burst_kbps)

openstack/tests/unit/network/v2/test_proxy.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from openstack.network.v2 import pool
3030
from openstack.network.v2 import pool_member
3131
from openstack.network.v2 import port
32+
from openstack.network.v2 import qos_bandwidth_limit_rule
3233
from openstack.network.v2 import qos_dscp_marking_rule
3334
from openstack.network.v2 import qos_minimum_bandwidth_rule
3435
from openstack.network.v2 import qos_policy
@@ -390,6 +391,53 @@ def test_ports(self):
390391
def test_port_update(self):
391392
self.verify_update(self.proxy.update_port, port.Port)
392393

394+
def test_qos_bandwidth_limit_rule_create_attrs(self):
395+
self.verify_create(
396+
self.proxy.create_qos_bandwidth_limit_rule,
397+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
398+
method_kwargs={'qos_policy': QOS_POLICY_ID},
399+
expected_kwargs={'path_args': {'qos_policy_id': QOS_POLICY_ID}})
400+
401+
def test_qos_bandwidth_limit_rule_delete(self):
402+
self.verify_delete(
403+
self.proxy.delete_qos_bandwidth_limit_rule,
404+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
405+
False, input_path_args=["resource_or_id", QOS_POLICY_ID],
406+
expected_path_args={'qos_policy_id': QOS_POLICY_ID},)
407+
408+
def test_qos_bandwidth_limit_rule_delete_ignore(self):
409+
self.verify_delete(
410+
self.proxy.delete_qos_bandwidth_limit_rule,
411+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
412+
True, input_path_args=["resource_or_id", QOS_POLICY_ID],
413+
expected_path_args={'qos_policy_id': QOS_POLICY_ID}, )
414+
415+
def test_qos_bandwidth_limit_rule_find(self):
416+
self.verify_find(self.proxy.find_qos_bandwidth_limit_rule,
417+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
418+
path_args={'qos_policy_id': QOS_POLICY_ID})
419+
420+
def test_qos_bandwidth_limit_rule_get(self):
421+
self.verify_get(
422+
self.proxy.get_qos_bandwidth_limit_rule,
423+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
424+
method_kwargs={'qos_policy': QOS_POLICY_ID},
425+
expected_kwargs={'path_args': {'qos_policy_id': QOS_POLICY_ID}})
426+
427+
def test_qos_bandwidth_limit_rules(self):
428+
self.verify_list(
429+
self.proxy.qos_bandwidth_limit_rules,
430+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
431+
paginated=False,
432+
method_kwargs={'qos_policy': QOS_POLICY_ID},
433+
expected_kwargs={'path_args': {'qos_policy_id': QOS_POLICY_ID}})
434+
435+
def test_qos_bandwidth_limit_rule_update(self):
436+
self.verify_update(
437+
self.proxy.update_qos_bandwidth_limit_rule,
438+
qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
439+
path_args={'qos_policy_id': QOS_POLICY_ID})
440+
393441
def test_qos_dscp_marking_rule_create_attrs(self):
394442
self.verify_create(
395443
self.proxy.create_qos_dscp_marking_rule,

0 commit comments

Comments
 (0)