Skip to content

Commit dce3313

Browse files
author
Rodolfo Alonso Hernandez
committed
Add QoS rule type object and CRUD commands.
Closes-Bug: 1612194 Depends-On: Idf319cd182304952071bc976a2e56c42fbcb8468 Change-Id: Iecf7bc7acd244a842aae963993f37a64a26b43b9
1 parent a7fd675 commit dce3313

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Network Resources
2323
v2/qos_dscp_marking_rule
2424
v2/qos_minimum_bandwidth_rule
2525
v2/qos_policy
26+
v2/qos_rule_type
2627
v2/quota
2728
v2/rbac_policy
2829
v2/router
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openstack.network.v2.qos_rule_type
2+
==================================
3+
4+
.. automodule:: openstack.network.v2.qos_rule_type
5+
6+
The QoSRuleType Class
7+
---------------------
8+
9+
The ``QoSRuleType`` class inherits from :class:`~openstack.resource.Resource`.
10+
11+
.. autoclass:: openstack.network.v2.qos_rule_type.QoSRuleType
12+
:members:

openstack/network/v2/_proxy.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from openstack.network.v2 import qos_minimum_bandwidth_rule as \
3333
_qos_minimum_bandwidth_rule
3434
from openstack.network.v2 import qos_policy as _qos_policy
35+
from openstack.network.v2 import qos_rule_type as _qos_rule_type
3536
from openstack.network.v2 import quota as _quota
3637
from openstack.network.v2 import rbac_policy as _rbac_policy
3738
from openstack.network.v2 import router as _router
@@ -1608,6 +1609,16 @@ def update_qos_policy(self, qos_policy, **attrs):
16081609
"""
16091610
return self._update(_qos_policy.QoSPolicy, qos_policy, **attrs)
16101611

1612+
def qos_rule_types(self, **query):
1613+
"""Return a generator of QoS rule types
1614+
1615+
:param kwargs \*\*query: Optional query parameters to be sent to limit
1616+
the resources being returned.
1617+
:returns: A generator of QoS rule type objects
1618+
:rtype: :class:`~openstack.network.v2.qos_rule_type.QoSRuleType`
1619+
"""
1620+
return self._list(_qos_rule_type.QoSRuleType, paginated=False, **query)
1621+
16111622
def delete_quota(self, quota, ignore_missing=True):
16121623
"""Delete a quota (i.e. reset to the default quota)
16131624
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 QoSRuleType(resource.Resource):
18+
resource_key = 'rule_type'
19+
resources_key = 'rule_types'
20+
base_path = '/qos/rule-types'
21+
service = network_service.NetworkService()
22+
23+
# capabilities
24+
allow_create = False
25+
allow_retrieve = False
26+
allow_update = False
27+
allow_delete = False
28+
allow_list = True
29+
30+
# Properties
31+
#: QoS rule type name.
32+
type = resource.prop('type')
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 six
14+
15+
from openstack.tests.functional import base
16+
17+
18+
class TestQoSRuleType(base.BaseFunctionalTest):
19+
20+
def test_list(self):
21+
rule_types = list(self.conn.network.qos_rule_types())
22+
self.assertGreater(len(rule_types), 0)
23+
24+
for rule_type in rule_types:
25+
self.assertIsInstance(rule_type.type, six.string_types)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from openstack.network.v2 import qos_dscp_marking_rule
3434
from openstack.network.v2 import qos_minimum_bandwidth_rule
3535
from openstack.network.v2 import qos_policy
36+
from openstack.network.v2 import qos_rule_type
3637
from openstack.network.v2 import quota
3738
from openstack.network.v2 import rbac_policy
3839
from openstack.network.v2 import router
@@ -556,6 +557,10 @@ def test_qos_policies(self):
556557
def test_qos_policy_update(self):
557558
self.verify_update(self.proxy.update_qos_policy, qos_policy.QoSPolicy)
558559

560+
def test_qos_rule_types(self):
561+
self.verify_list(self.proxy.qos_rule_types, qos_rule_type.QoSRuleType,
562+
paginated=False)
563+
559564
def test_quota_delete(self):
560565
self.verify_delete(self.proxy.delete_quota, quota.Quota, False)
561566

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 testtools
14+
15+
from openstack.network.v2 import qos_rule_type
16+
17+
EXAMPLE = {
18+
'type': 'bandwidth_limit',
19+
}
20+
21+
22+
class TestQoSRuleType(testtools.TestCase):
23+
24+
def test_basic(self):
25+
sot = qos_rule_type.QoSRuleType()
26+
self.assertEqual('rule_type', sot.resource_key)
27+
self.assertEqual('rule_types', sot.resources_key)
28+
self.assertEqual('/qos/rule-types', sot.base_path)
29+
self.assertEqual('network', sot.service.service_type)
30+
self.assertFalse(sot.allow_create)
31+
self.assertFalse(sot.allow_retrieve)
32+
self.assertFalse(sot.allow_update)
33+
self.assertFalse(sot.allow_delete)
34+
self.assertTrue(sot.allow_list)
35+
36+
def test_make_it(self):
37+
sot = qos_rule_type.QoSRuleType(EXAMPLE)
38+
self.assertEqual(EXAMPLE['type'], sot.type)

0 commit comments

Comments
 (0)