You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/08/13 19:20:21 UTC
[2/2] git commit: Use an enum class for identity endpoint type.
Use an enum class for identity endpoint type.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5af1bf36
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5af1bf36
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5af1bf36
Branch: refs/heads/trunk
Commit: 5af1bf3635435ea84becc4365d2ceba7d8462939
Parents: 2871ea8
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Aug 13 19:13:08 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Aug 13 19:13:08 2014 +0200
----------------------------------------------------------------------
libcloud/common/openstack_identity.py | 37 ++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/5af1bf36/libcloud/common/openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack_identity.py b/libcloud/common/openstack_identity.py
index ddd1f8d..b9723fc 100644
--- a/libcloud/common/openstack_identity.py
+++ b/libcloud/common/openstack_identity.py
@@ -62,6 +62,7 @@ __all__ = [
'OpenStackServiceCatalog',
'OpenStackServiceCatalogEntry',
'OpenStackServiceCatalogEntryEndpoint',
+ 'OpenStackIdentityEndpointType',
'OpenStackIdentityConnection',
'OpenStackIdentity_1_0_Connection',
@@ -73,6 +74,15 @@ __all__ = [
]
+class OpenStackIdentityEndpointType(object):
+ """
+ Enum class for openstack identity endpoint type.
+ """
+ INTERNAL = 'internal'
+ EXTERNAL = 'external'
+ ADMIN = 'admin'
+
+
class OpenStackIdentityVersion(object):
def __init__(self, version, status, updated, url):
self.version = version
@@ -199,7 +209,8 @@ class OpenStackServiceCatalog(object):
result = []
for endpoint in endpoints:
- if endpoint.endpoint_type == 'external':
+ endpoint_type = endpoint.endpoint_type
+ if endpoint_type == OpenStackIdentityEndpointType.EXTERNAL:
result.append(endpoint.url)
return result
@@ -225,7 +236,7 @@ class OpenStackServiceCatalog(object):
return endpoints
def get_endpoint(self, service_type=None, name=None, region=None,
- endpoint_type='external'):
+ endpoint_type=OpenStackIdentityEndpointType.EXTERNAL):
"""
Retrieve a single endpoint using the provided criteria.
@@ -346,13 +357,13 @@ class OpenStackServiceCatalog(object):
if public_url:
entry_endpoint = OpenStackServiceCatalogEntryEndpoint(
region=region, url=public_url,
- endpoint_type='external')
+ endpoint_type=OpenStackIdentityEndpointType.EXTERNAL)
entry_endpoints.append(entry_endpoint)
if private_url:
entry_endpoint = OpenStackServiceCatalogEntryEndpoint(
region=region, url=private_url,
- endpoint_type='internal')
+ endpoint_type=OpenStackIdentityEndpointType.INTERNAL)
entry_endpoints.append(entry_endpoint)
entry = OpenStackServiceCatalogEntry(service_type=service,
@@ -378,13 +389,13 @@ class OpenStackServiceCatalog(object):
if public_url:
entry_endpoint = OpenStackServiceCatalogEntryEndpoint(
region=region, url=public_url,
- endpoint_type='external')
+ endpoint_type=OpenStackIdentityEndpointType.EXTERNAL)
entry_endpoints.append(entry_endpoint)
if private_url:
entry_endpoint = OpenStackServiceCatalogEntryEndpoint(
region=region, url=private_url,
- endpoint_type='internal')
+ endpoint_type=OpenStackIdentityEndpointType.INTERNAL)
entry_endpoints.append(entry_endpoint)
entry = OpenStackServiceCatalogEntry(service_type=service_type,
@@ -407,11 +418,11 @@ class OpenStackServiceCatalog(object):
endpoint_type = endpoint['interface']
if endpoint_type == 'internal':
- endpoint_type = 'internal'
+ endpoint_type = OpenStackIdentityEndpointType.INTERNAL
elif endpoint_type == 'public':
- endpoint_type = 'external'
+ endpoint_type = OpenStackIdentityEndpointType.EXTERNAL
elif endpoint_type == 'admin':
- endpoint_type = 'admin'
+ endpoint_type = OpenStackIdentityEndpointType.ADMIN
entry_endpoint = OpenStackServiceCatalogEntryEndpoint(
region=region, url=url, endpoint_type=endpoint_type)
@@ -458,6 +469,12 @@ class OpenStackServiceCatalogEntry(object):
class OpenStackServiceCatalogEntryEndpoint(object):
+ VALID_ENDPOINT_TYPES = [
+ OpenStackIdentityEndpointType.INTERNAL,
+ OpenStackIdentityEndpointType.EXTERNAL,
+ OpenStackIdentityEndpointType.ADMIN,
+ ]
+
def __init__(self, region, url, endpoint_type='external'):
"""
:param region: Endpoint region.
@@ -469,7 +486,7 @@ class OpenStackServiceCatalogEntryEndpoint(object):
:param endpoint_type: Endpoint type (external / internal / admin).
:type endpoint_type: ``str``
"""
- if endpoint_type not in ['internal', 'external', 'admin']:
+ if endpoint_type not in self.VALID_ENDPOINT_TYPES:
raise ValueError('Invalid type: %s' % (endpoint_type))
# TODO: Normalize / lowercase all the region names