Skip to content

Commit ac5b8d4

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add QoS policy object and CRUD commands."
2 parents d10a80c + c1230de commit ac5b8d4

7 files changed

Lines changed: 277 additions & 0 deletions

File tree

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_policy
2223
v2/quota
2324
v2/rbac_policy
2425
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_policy
2+
===============================
3+
4+
.. automodule:: openstack.network.v2.qos_policy
5+
6+
The QoSPolicy Class
7+
-------------------
8+
9+
The ``QoSPolicy`` class inherits from :class:`~openstack.resource.Resource`.
10+
11+
.. autoclass:: openstack.network.v2.qos_policy.QoSPolicy
12+
:members:

openstack/network/v2/_proxy.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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_policy as _qos_policy
2829
from openstack.network.v2 import quota as _quota
2930
from openstack.network.v2 import rbac_policy as _rbac_policy
3031
from openstack.network.v2 import router as _router
@@ -1890,3 +1891,86 @@ def update_vpn_service(self, vpn_service, **attrs):
18901891
:rtype: :class:`~openstack.network.v2.vpn_service.VPNService`
18911892
"""
18921893
return self._update(_vpn_service.VPNService, vpn_service, **attrs)
1894+
1895+
def create_qos_policy(self, **attrs):
1896+
"""Create a new QoS policy from attributes
1897+
1898+
:param dict attrs: Keyword arguments which will be used to create
1899+
a :class:`~openstack.network.v2.qos_policy.
1900+
QoSPolicy`, comprised of the properties on the
1901+
QoSPolicy class.
1902+
1903+
:returns: The results of QoS policy creation
1904+
:rtype: :class:`~openstack.network.v2.qos_policy.QoSPolicy`
1905+
"""
1906+
return self._create(_qos_policy.QoSPolicy, **attrs)
1907+
1908+
def delete_qos_policy(self, qos_policy, ignore_missing=True):
1909+
"""Delete a QoS policy
1910+
1911+
:param qos_policy: The value can be either the ID of a QoS policy or a
1912+
:class:`~openstack.network.v2.qos_policy.QoSPolicy`
1913+
instance.
1914+
:param bool ignore_missing: When set to ``False``
1915+
:class:`~openstack.exceptions.ResourceNotFound` will be
1916+
raised when the QoS policy does not exist.
1917+
When set to ``True``, no exception will be set when
1918+
attempting to delete a nonexistent QoS policy.
1919+
1920+
:returns: ``None``
1921+
"""
1922+
self._delete(_qos_policy.QoSPolicy, qos_policy,
1923+
ignore_missing=ignore_missing)
1924+
1925+
def find_qos_policy(self, name_or_id, ignore_missing=True):
1926+
"""Find a single QoS policy
1927+
1928+
:param name_or_id: The name or ID of a QoS policy.
1929+
:param bool ignore_missing: When set to ``False``
1930+
:class:`~openstack.exceptions.ResourceNotFound` will be
1931+
raised when the resource does not exist.
1932+
When set to ``True``, None will be returned when
1933+
attempting to find a nonexistent resource.
1934+
:returns: One :class:`~openstack.network.v2.qos_policy.QoSPolicy` or
1935+
None
1936+
"""
1937+
return self._find(_qos_policy.QoSPolicy, name_or_id,
1938+
ignore_missing=ignore_missing)
1939+
1940+
def get_qos_policy(self, qos_policy):
1941+
"""Get a single QoS policy
1942+
1943+
:param qos_policy: The value can be the ID of a QoS policy or a
1944+
:class:`~openstack.network.v2.qos_policy.QoSPolicy`
1945+
instance.
1946+
1947+
:returns: One :class:`~openstack.network.v2.qos_policy.QoSPolicy`
1948+
:raises: :class:`~openstack.exceptions.ResourceNotFound`
1949+
when no resource can be found.
1950+
"""
1951+
return self._get(_qos_policy.QoSPolicy, qos_policy)
1952+
1953+
def qos_policies(self, **query):
1954+
"""Return a generator of QoS policies
1955+
1956+
:param kwargs \*\*query: Optional query parameters to be sent to limit
1957+
the resources being returned.
1958+
1959+
:returns: A generator of QoS policy objects
1960+
:rtype: :class:`~openstack.network.v2.qos_policy.QoSPolicy`
1961+
"""
1962+
return self._list(_qos_policy.QoSPolicy, paginated=False, **query)
1963+
1964+
def update_qos_policy(self, qos_policy, **attrs):
1965+
"""Update a QoS policy
1966+
1967+
:param qos_policy: Either the id of a QoS policy or a
1968+
:class:`~openstack.network.v2.qos_policy.QoSPolicy`
1969+
instance.
1970+
:attrs kwargs: The attributes to update on the QoS policy represented
1971+
by ``value``.
1972+
1973+
:returns: The updated QoS policy
1974+
:rtype: :class:`~openstack.network.v2.qos_policy.QoSPolicy`
1975+
"""
1976+
return self._update(_qos_policy.QoSPolicy, qos_policy, **attrs)

openstack/network/v2/qos_policy.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 QoSPolicy(resource.Resource):
18+
resource_key = 'policy'
19+
resources_key = 'policies'
20+
base_path = '/qos/policies'
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 policy name.
32+
name = resource.prop('name')
33+
#: The ID of the project who owns the network. Only administrative
34+
#: users can specify a project ID other than their own.
35+
project_id = resource.prop('tenant_id')
36+
#: The QoS policy description.
37+
description = resource.prop('description')
38+
#: Indicates whether this QoS policy is shared across all projects.
39+
#: *Type: bool*
40+
is_shared = resource.prop('shared', type=bool)
41+
#: List of QoS rules applied to this QoS policy.
42+
rules = resource.prop('rules')
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_policy as _qos_policy
16+
from openstack.tests.functional import base
17+
18+
19+
class TestQoSPolicy(base.BaseFunctionalTest):
20+
21+
QOS_POLICY_ID = None
22+
QOS_POLICY_NAME = uuid.uuid4().hex
23+
QOS_POLICY_NAME_UPDATED = uuid.uuid4().hex
24+
IS_SHARED = False
25+
RULES = []
26+
QOS_POLICY_DESCRIPTION = "QoS policy description"
27+
28+
@classmethod
29+
def setUpClass(cls):
30+
super(TestQoSPolicy, cls).setUpClass()
31+
qos = cls.conn.network.create_qos_policy(
32+
description=cls.QOS_POLICY_DESCRIPTION,
33+
name=cls.QOS_POLICY_NAME,
34+
shared=cls.IS_SHARED,
35+
)
36+
assert isinstance(qos, _qos_policy.QoSPolicy)
37+
cls.assertIs(cls.QOS_POLICY_NAME, qos.name)
38+
cls.QOS_POLICY_ID = qos.id
39+
40+
@classmethod
41+
def tearDownClass(cls):
42+
sot = cls.conn.network.delete_qos_policy(cls.QOS_POLICY_ID)
43+
cls.assertIs(None, sot)
44+
45+
def test_find(self):
46+
sot = self.conn.network.find_qos_policy(self.QOS_POLICY_NAME)
47+
self.assertEqual(self.QOS_POLICY_ID, sot.id)
48+
49+
def test_get(self):
50+
sot = self.conn.network.get_qos_policy(self.QOS_POLICY_ID)
51+
self.assertEqual(self.QOS_POLICY_NAME, sot.name)
52+
self.assertEqual(self.IS_SHARED, sot.is_shared)
53+
self.assertEqual(self.RULES, sot.rules)
54+
self.assertEqual(self.QOS_POLICY_DESCRIPTION, sot.description)
55+
56+
def test_list(self):
57+
names = [o.name for o in self.conn.network.qos_policies()]
58+
self.assertIn(self.QOS_POLICY_NAME, names)
59+
60+
def test_update(self):
61+
sot = self.conn.network.update_qos_policy(
62+
self.QOS_POLICY_ID,
63+
name=self.QOS_POLICY_NAME_UPDATED)
64+
self.assertEqual(self.QOS_POLICY_NAME_UPDATED, sot.name)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from openstack.network.v2 import pool
2929
from openstack.network.v2 import pool_member
3030
from openstack.network.v2 import port
31+
from openstack.network.v2 import qos_policy
3132
from openstack.network.v2 import quota
3233
from openstack.network.v2 import rbac_policy
3334
from openstack.network.v2 import router
@@ -382,6 +383,30 @@ def test_ports(self):
382383
def test_port_update(self):
383384
self.verify_update(self.proxy.update_port, port.Port)
384385

386+
def test_qos_policy_create_attrs(self):
387+
self.verify_create(self.proxy.create_qos_policy, qos_policy.QoSPolicy)
388+
389+
def test_qos_policy_delete(self):
390+
self.verify_delete(self.proxy.delete_qos_policy, qos_policy.QoSPolicy,
391+
False)
392+
393+
def test_qos_policy_delete_ignore(self):
394+
self.verify_delete(self.proxy.delete_qos_policy, qos_policy.QoSPolicy,
395+
True)
396+
397+
def test_qos_policy_find(self):
398+
self.verify_find(self.proxy.find_qos_policy, qos_policy.QoSPolicy)
399+
400+
def test_qos_policy_get(self):
401+
self.verify_get(self.proxy.get_qos_policy, qos_policy.QoSPolicy)
402+
403+
def test_qos_policies(self):
404+
self.verify_list(self.proxy.qos_policies, qos_policy.QoSPolicy,
405+
paginated=False)
406+
407+
def test_qos_policy_update(self):
408+
self.verify_update(self.proxy.update_qos_policy, qos_policy.QoSPolicy)
409+
385410
def test_quota_delete(self):
386411
self.verify_delete(self.proxy.delete_quota, quota.Quota, False)
387412

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+
import testtools
14+
import uuid
15+
16+
from openstack.network.v2 import qos_policy
17+
18+
EXAMPLE = {
19+
'id': 'IDENTIFIER',
20+
'description': 'QoS policy description',
21+
'name': 'qos-policy-name',
22+
'shared': True,
23+
'tenant_id': '2',
24+
'rules': [uuid.uuid4().hex]
25+
}
26+
27+
28+
class TestQoSPolicy(testtools.TestCase):
29+
30+
def test_basic(self):
31+
sot = qos_policy.QoSPolicy()
32+
self.assertEqual('policy', sot.resource_key)
33+
self.assertEqual('policies', sot.resources_key)
34+
self.assertEqual('/qos/policies', sot.base_path)
35+
self.assertEqual('network', sot.service.service_type)
36+
self.assertTrue(sot.allow_create)
37+
self.assertTrue(sot.allow_retrieve)
38+
self.assertTrue(sot.allow_update)
39+
self.assertTrue(sot.allow_delete)
40+
self.assertTrue(sot.allow_list)
41+
42+
def test_make_it(self):
43+
sot = qos_policy.QoSPolicy(EXAMPLE)
44+
self.assertEqual(EXAMPLE['id'], sot.id)
45+
self.assertEqual(EXAMPLE['description'], sot.description)
46+
self.assertEqual(EXAMPLE['name'], sot.name)
47+
self.assertTrue(sot.is_shared)
48+
self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
49+
self.assertEqual(EXAMPLE['rules'], sot.rules)

0 commit comments

Comments
 (0)