Skip to content

Commit f67c392

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add resources for Service Provider"
2 parents 3946edb + 05c1963 commit f67c392

7 files changed

Lines changed: 135 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,5 +31,6 @@ Network Resources
3131
v2/security_group
3232
v2/security_group_rule
3333
v2/segment
34+
v2/service_provider
3435
v2/subnet
3536
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_provider
2+
=====================================
3+
4+
.. automodule:: openstack.network.v2.service_provider
5+
6+
The Service Provider Class
7+
--------------------------
8+
9+
The ``Service Provider`` class inherits from :class:`~openstack.resource.Resource`.
10+
11+
.. autoclass:: openstack.network.v2.service_provider.ServiceProvider
12+
:members:

openstack/network/v2/_proxy.py

Lines changed: 14 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_provider as _service_provider
4344
from openstack.network.v2 import subnet as _subnet
4445
from openstack.network.v2 import subnet_pool as _subnet_pool
4546
from openstack.network.v2 import vpn_service as _vpn_service
@@ -2293,6 +2294,19 @@ def update_segment(self, segment, **attrs):
22932294
"""
22942295
return self._update(_segment.Segment, segment, **attrs)
22952296

2297+
def service_providers(self, **query):
2298+
"""Return a generator of service providers
2299+
2300+
:param kwargs \*\* query: Optional query parameters to be sent to limit
2301+
the resources being returned.
2302+
2303+
:returns: A generator of service provider objects
2304+
:rtype: :class:`~openstack.network.v2.service_provider.ServiceProvider`
2305+
"""
2306+
2307+
return self._list(_service_provider.ServiceProvider,
2308+
paginated=False, **query)
2309+
22962310
def create_subnet(self, **attrs):
22972311
"""Create a new subnet from attributes
22982312
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ServiceProvider(resource.Resource):
18+
resources_key = 'service_providers'
19+
base_path = '/service-providers'
20+
service = network_service.NetworkService()
21+
22+
# Capabilities
23+
allow_create = False
24+
allow_retrieve = False
25+
allow_update = False
26+
allow_delete = False
27+
allow_list = True
28+
29+
# Properties
30+
#: Service type (FIREWALL, FLAVORS, METERING, QOS, etc..)
31+
service_type = resource.prop('service_type')
32+
#: Name of the service type
33+
name = resource.prop('name')
34+
#: The default value of service type
35+
is_default = resource.prop('default', type=bool)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 TestServiceProvider(base.BaseFunctionalTest):
19+
def test_list(self):
20+
providers = list(self.conn.network.service_providers())
21+
22+
for provide in providers:
23+
self.assertIsInstance(provide.name, six.string_type)
24+
self.assertIsInstance(provide.service_type, six.string_types)

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

Lines changed: 6 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_provider
4445
from openstack.network.v2 import subnet
4546
from openstack.network.v2 import subnet_pool
4647
from openstack.network.v2 import vpn_service
@@ -842,3 +843,8 @@ def test_vpn_services(self):
842843
def test_vpn_service_update(self):
843844
self.verify_update(self.proxy.update_vpn_service,
844845
vpn_service.VPNService)
846+
847+
def test_service_provider(self):
848+
self.verify_list(self.proxy.service_providers,
849+
service_provider.ServiceProvider,
850+
paginated=False)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_provider
16+
17+
IDENTIFIER = 'IDENTIFIER'
18+
EXAMPLE = {
19+
'service_type': 'L3_ROUTER_NAT',
20+
'name': '4',
21+
'default': False,
22+
}
23+
24+
25+
class TestServiceProvider(testtools.TestCase):
26+
27+
def test_basic(self):
28+
sot = service_provider.ServiceProvider()
29+
30+
self.assertEqual('service_providers', sot.resources_key)
31+
self.assertEqual('/service-providers', sot.base_path)
32+
self.assertEqual('network', sot.service.service_type)
33+
self.assertFalse(sot.allow_create)
34+
self.assertFalse(sot.allow_retrieve)
35+
self.assertFalse(sot.allow_update)
36+
self.assertFalse(sot.allow_delete)
37+
self.assertTrue(sot.allow_list)
38+
39+
def test_make_it(self):
40+
sot = service_provider.ServiceProvider(EXAMPLE)
41+
self.assertEqual(EXAMPLE['service_type'], sot.service_type)
42+
self.assertEqual(EXAMPLE['name'], sot.name)
43+
self.assertEqual(EXAMPLE['default'], sot.is_default)

0 commit comments

Comments
 (0)