Skip to content

Commit c646788

Browse files
author
Anindita Das
committed
Add support for network Service Flavor Profile
This patch set adds the support for the retrieve, update, create and delete for the network Flavor Profile Change-Id: I653ea0ba041e286941841701ea0c6e0f70e9e568 Partially-Implements: blueprint neutron-client-flavors
1 parent bdf2e68 commit c646788

7 files changed

Lines changed: 291 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
@@ -31,6 +31,7 @@ Network Resources
3131
v2/security_group
3232
v2/security_group_rule
3333
v2/segment
34+
v2/service_profile
3435
v2/service_provider
3536
v2/subnet
3637
v2/subnet_pool
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openstack.network.v2.service_profile
2+
====================================
3+
4+
.. automodule:: openstack.network.v2.service_profile
5+
6+
The ServiceProfile Class
7+
------------------------
8+
9+
The ``ServiceProfile`` class inherits from :class:`~openstack.resource.Resource`.
10+
11+
.. autoclass:: openstack.network.v2.service_profile.ServiceProfile
12+
:members:

openstack/network/v2/_proxy.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from openstack.network.v2 import security_group as _security_group
4141
from openstack.network.v2 import security_group_rule as _security_group_rule
4242
from openstack.network.v2 import segment as _segment
43+
from openstack.network.v2 import service_profile as _service_profile
4344
from openstack.network.v2 import service_provider as _service_provider
4445
from openstack.network.v2 import subnet as _subnet
4546
from openstack.network.v2 import subnet_pool as _subnet_pool
@@ -2307,6 +2308,95 @@ def service_providers(self, **query):
23072308
return self._list(_service_provider.ServiceProvider,
23082309
paginated=False, **query)
23092310

2311+
def create_service_profile(self, **attrs):
2312+
"""Create a new network service flavor profile from attributes
2313+
2314+
:param dict attrs: Keyword arguments which will be used to create
2315+
a :class:`~openstack.network.v2.service_profile
2316+
.ServiceProfile`,
2317+
comprised of the properties on the ServiceProfile
2318+
class.
2319+
2320+
:returns: The results of service profile creation
2321+
:rtype: :class:`~openstack.network.v2.service_profile.ServiceProfile`
2322+
"""
2323+
return self._create(_service_profile.ServiceProfile, **attrs)
2324+
2325+
def delete_service_profile(self, service_profile, ignore_missing=True):
2326+
"""Delete a network service flavor profile
2327+
2328+
:param service_profile: The value can be either the ID of a service
2329+
profile or a
2330+
:class:`~openstack.network.v2.service_profile
2331+
.ServiceProfile` instance.
2332+
:param bool ignore_missing: When set to ``False``
2333+
:class:`~openstack.exceptions.ResourceNotFound` will be
2334+
raised when the service profile does not exist.
2335+
When set to ``True``, no exception will be set when
2336+
attempting to delete a nonexistent service profile.
2337+
2338+
:returns: ``None``
2339+
"""
2340+
self._delete(_service_profile.ServiceProfile, service_profile,
2341+
ignore_missing=ignore_missing)
2342+
2343+
def find_service_profile(self, name_or_id, ignore_missing=True):
2344+
"""Find a single network service flavor profile
2345+
2346+
:param name_or_id: The name or ID of a service profile.
2347+
:param bool ignore_missing: When set to ``False``
2348+
:class:`~openstack.exceptions.ResourceNotFound` will be
2349+
raised when the resource does not exist.
2350+
When set to ``True``, None will be returned when
2351+
attempting to find a nonexistent resource.
2352+
:returns: One :class:`~openstack.network.v2.service_profile
2353+
.ServiceProfile` or None
2354+
"""
2355+
return self._find(_service_profile.ServiceProfile, name_or_id,
2356+
ignore_missing=ignore_missing)
2357+
2358+
def get_service_profile(self, service_profile):
2359+
"""Get a single network service flavor profile
2360+
2361+
:param service_profile: The value can be the ID of a service_profile or
2362+
a
2363+
:class:`~openstack.network.v2.service_profile
2364+
.ServiceProfile` instance.
2365+
2366+
:returns: One :class:`~openstack.network.v2.service_profile
2367+
.ServiceProfile`
2368+
:raises: :class:`~openstack.exceptions.ResourceNotFound`
2369+
when no resource can be found.
2370+
"""
2371+
return self._get(_service_profile.ServiceProfile, service_profile)
2372+
2373+
def service_profiles(self, **query):
2374+
"""Return a generator of network service flavor profiles
2375+
2376+
:param kwargs \*\*query: Optional query parameters to be sent to limit
2377+
the resources being returned.
2378+
2379+
:returns: A generator of service profile objects
2380+
:rtype: :class:`~openstack.network.v2.service_profile.ServiceProfile`
2381+
"""
2382+
return self._list(_service_profile.ServiceProfile, paginated=True,
2383+
**query)
2384+
2385+
def update_service_profile(self, service_profile, **attrs):
2386+
"""Update a network flavor service profile
2387+
2388+
:param service_profile: Either the id of a service profile or a
2389+
:class:`~openstack.network.v2.service_profile
2390+
.ServiceProfile` instance.
2391+
:attrs kwargs: The attributes to update on the service profile
2392+
represented by ``value``.
2393+
2394+
:returns: The updated service profile
2395+
:rtype: :class:`~openstack.network.v2.service_profile.ServiceProfile`
2396+
"""
2397+
return self._update(_service_profile.ServiceProfile, service_profile,
2398+
**attrs)
2399+
23102400
def create_subnet(self, **attrs):
23112401
"""Create a new subnet from attributes
23122402
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 ServiceProfile(resource.Resource):
18+
resource_key = 'service_profile'
19+
resources_key = 'service_profiles'
20+
base_path = '/service_profiles'
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+
#: Description of the service flavor profile.
32+
description = resource.prop('description')
33+
#: Provider Driver for the service flavor profile
34+
driver = resource.prop('driver')
35+
#: Sets enabled flag
36+
is_enabled = resource.prop('enabled', type=bool)
37+
#: Metainformation of the service flavor profile
38+
metainfo = resource.prop('metainfo')
39+
#: The owner project ID
40+
project_id = resource.prop('tenant_id')
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+
from openstack.network.v2 import service_profile as _service_profile
14+
from openstack.tests.functional import base
15+
16+
17+
class TestServiceProfile(base.BaseFunctionalTest):
18+
19+
SERVICE_PROFILE_DESCRIPTION = "DESCRIPTION"
20+
UPDATE_DESCRIPTION = "UPDATED-DESCRIPTION"
21+
METAINFO = "FlAVOR_PROFILE_METAINFO"
22+
ID = None
23+
24+
@classmethod
25+
def setUpClass(cls):
26+
super(TestServiceProfile, cls).setUpClass()
27+
service_profiles = cls.conn.network.create_service_profile(
28+
description=cls.SERVICE_PROFILE_DESCRIPTION,
29+
metainfo=cls.METAINFO,)
30+
assert isinstance(service_profiles, _service_profile.ServiceProfile)
31+
cls.assertIs(cls.SERVICE_PROFILE_DESCRIPTION,
32+
service_profiles.description)
33+
cls.assertIs(cls.METAINFO, service_profiles.metainfo)
34+
35+
cls.ID = service_profiles.id
36+
37+
@classmethod
38+
def tearDownClass(cls):
39+
service_profiles = cls.conn.network.delete_service_profile(
40+
cls.ID,
41+
ignore_missing=True)
42+
cls.assertIs(None, service_profiles)
43+
44+
def test_find(self):
45+
service_profiles = self.conn.network.find_service_profile(
46+
self.ID)
47+
self.assertEqual(self.METAINFO,
48+
service_profiles.metainfo)
49+
50+
def test_get(self):
51+
service_profiles = self.conn.network.get_service_profile(self.ID)
52+
self.assertEqual(self.METAINFO, service_profiles.metainfo)
53+
self.assertEqual(self.SERVICE_PROFILE_DESCRIPTION,
54+
service_profiles.description)
55+
56+
def test_update(self):
57+
service_profiles = self.conn.network.update_service_profile(
58+
self.ID,
59+
description=self.UPDATE_DESCRIPTION)
60+
self.assertEqual(self.UPDATE_DESCRIPTION, service_profiles.description)
61+
62+
def test_list(self):
63+
metainfos = [f.metainfo for f in self.conn.network.service_profiles()]
64+
self.assertIn(self.METAINFO, metainfos)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from openstack.network.v2 import security_group
4242
from openstack.network.v2 import security_group_rule
4343
from openstack.network.v2 import segment
44+
from openstack.network.v2 import service_profile
4445
from openstack.network.v2 import service_provider
4546
from openstack.network.v2 import subnet
4647
from openstack.network.v2 import subnet_pool
@@ -318,6 +319,30 @@ def test_flavors(self):
318319
self.verify_list(self.proxy.flavors, flavor.Flavor,
319320
paginated=True)
320321

322+
def test_service_profile_create_attrs(self):
323+
self.verify_create(self.proxy.create_service_profile,
324+
service_profile.ServiceProfile)
325+
326+
def test_service_profile_delete(self):
327+
self.verify_delete(self.proxy.delete_service_profile,
328+
service_profile.ServiceProfile, True)
329+
330+
def test_service_profile_find(self):
331+
self.verify_find(self.proxy.find_service_profile,
332+
service_profile.ServiceProfile)
333+
334+
def test_service_profile_get(self):
335+
self.verify_get(self.proxy.get_service_profile,
336+
service_profile.ServiceProfile)
337+
338+
def test_service_profiles(self):
339+
self.verify_list(self.proxy.service_profiles,
340+
service_profile.ServiceProfile, paginated=True)
341+
342+
def test_service_profile_update(self):
343+
self.verify_update(self.proxy.update_service_profile,
344+
service_profile.ServiceProfile)
345+
321346
def test_network_ip_availability_find(self):
322347
self.verify_find(self.proxy.find_network_ip_availability,
323348
network_ip_availability.NetworkIPAvailability)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 service_profile
16+
17+
IDENTIFIER = 'IDENTIFIER'
18+
EXAMPLE_WITH_OPTIONAL = {
19+
'description': 'test flavor profile',
20+
'driver': 'neutron_lbaas.drivers.octavia.driver.OctaviaDriver',
21+
'enabled': True,
22+
'metainfo': {'foo': 'bar'},
23+
'tenant_id': '5',
24+
}
25+
26+
EXAMPLE = {
27+
'driver': 'neutron_lbaas.drivers.octavia.driver.OctaviaDriver',
28+
}
29+
30+
31+
class TestServiceProfile(testtools.TestCase):
32+
def test_basic(self):
33+
service_profiles = service_profile.ServiceProfile()
34+
self.assertEqual('service_profile', service_profiles.resource_key)
35+
self.assertEqual('service_profiles', service_profiles.resources_key)
36+
self.assertEqual('/service_profiles', service_profiles.base_path)
37+
self.assertTrue(service_profiles.allow_create)
38+
self.assertTrue(service_profiles.allow_retrieve)
39+
self.assertTrue(service_profiles.allow_update)
40+
self.assertTrue(service_profiles.allow_delete)
41+
self.assertTrue(service_profiles.allow_list)
42+
43+
def test_make_it(self):
44+
service_profiles = service_profile.ServiceProfile(EXAMPLE)
45+
self.assertEqual(EXAMPLE['driver'], service_profiles.driver)
46+
47+
def test_make_it_with_optional(self):
48+
service_profiles = service_profile.ServiceProfile(
49+
EXAMPLE_WITH_OPTIONAL)
50+
self.assertEqual(EXAMPLE_WITH_OPTIONAL['description'],
51+
service_profiles.description)
52+
self.assertEqual(EXAMPLE_WITH_OPTIONAL['driver'],
53+
service_profiles.driver)
54+
self.assertEqual(EXAMPLE_WITH_OPTIONAL['enabled'],
55+
service_profiles.is_enabled)
56+
self.assertEqual(EXAMPLE_WITH_OPTIONAL['metainfo'],
57+
service_profiles.metainfo)
58+
self.assertEqual(EXAMPLE_WITH_OPTIONAL['tenant_id'],
59+
service_profiles.tenant_id)

0 commit comments

Comments
 (0)