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 16:38:15 UTC

[1/3] git commit: Simplify code, remove outdated comments.

Repository: libcloud
Updated Branches:
  refs/heads/trunk 30bc00944 -> 45d8a3441


Simplify code, remove outdated comments.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/087da806
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/087da806
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/087da806

Branch: refs/heads/trunk
Commit: 087da806768a1f950c888a416256b2f6489b76a6
Parents: 30bc009
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Aug 13 15:03:56 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Aug 13 16:34:03 2014 +0200

----------------------------------------------------------------------
 libcloud/storage/drivers/cloudfiles.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/087da806/libcloud/storage/drivers/cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/cloudfiles.py b/libcloud/storage/drivers/cloudfiles.py
index d1f88a3..b0694ac 100644
--- a/libcloud/storage/drivers/cloudfiles.py
+++ b/libcloud/storage/drivers/cloudfiles.py
@@ -210,10 +210,7 @@ class CloudFilesConnection(OpenStackSwiftConnection):
         if self.cdn_request:
             ep = cdn_ep
 
-        if not ep:
-            raise LibcloudError('Could not find specified endpoint')
-
-        if not ep.url:
+        if not ep or not ep.url:
             raise LibcloudError('Could not find specified endpoint')
 
         return ep.url


[3/3] git commit: Remove now unused and not needed OpenStackAuthConnection class.

Posted by to...@apache.org.
Remove now unused and not needed OpenStackAuthConnection class.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/45d8a344
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/45d8a344
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/45d8a344

Branch: refs/heads/trunk
Commit: 45d8a344146eded2c7fa652e250a724eb921e795
Parents: 44945ed
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Aug 13 16:30:20 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Aug 13 16:34:11 2014 +0200

----------------------------------------------------------------------
 libcloud/common/openstack_identity.py | 81 ------------------------------
 1 file changed, 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/45d8a344/libcloud/common/openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack_identity.py b/libcloud/common/openstack_identity.py
index 0e11a0b..52e17e0 100644
--- a/libcloud/common/openstack_identity.py
+++ b/libcloud/common/openstack_identity.py
@@ -683,87 +683,6 @@ class OpenStackIdentityConnection(ConnectionUserAndKey):
         return True
 
 
-class OpenStackAuthConnection(OpenStackIdentityConnection):
-    """
-    Note: This class is only here for backward compatibility reasons.
-    """
-    responseCls = OpenStackAuthResponse
-    name = 'OpenStack Auth'
-    timeout = None
-
-    def __init__(self, parent_conn, auth_url, auth_version, user_id, key,
-                 tenant_name=None, timeout=None):
-        super(OpenStackAuthConnection, self).__init__(auth_url=auth_url,
-                                                      user_id=user_id,
-                                                      key=key,
-                                                      tenant_name=tenant_name,
-                                                      timeout=timeout,
-                                                      parent_conn=parent_conn)
-        self.auth_version = auth_version
-        self._instance_cache = {}
-
-    def _get_cls_for_auth_version(self, auth_version):
-        if auth_version == '1.0':
-            cls = OpenStackIdentity_1_0_Connection
-        elif auth_version == '1.1':
-            cls = OpenStackIdentity_1_1_Connection
-        elif auth_version == '2.0' or auth_version == '2.0_apikey':
-            cls = OpenStackIdentity_2_0_Connection
-        elif auth_version == '2.0_password':
-            cls = OpenStackIdentity_2_0_Connection
-        elif auth_version == '3.x_password':
-            cls = OpenStackIdentity_3_0_Connection
-        else:
-            raise LibcloudError('Unsupported Auth Version requested')
-
-        return cls
-
-    def _get_instance_for_auth_version(self, auth_version):
-        """
-        Retrieve instance for the provided auth version for the local cache (if
-        exists).
-        """
-        # TODO: Just delegate to the new classes
-        kwargs = {'auth_url': self.auth_url, 'user_id': self.user_id,
-                  'key': self.key, 'tenant_name': self.tenant_name,
-                  'timeout': self.timeout, 'parent_conn': self.parent_conn}
-
-        cls = self._get_cls_for_auth_version(auth_version=auth_version)
-
-        if auth_version not in self._instance_cache:
-            obj = cls(**kwargs)
-            self._instance_cache[auth_version] = obj
-
-        return self._instance_cache[auth_version]
-
-    def authenticate(self, force=False):
-        """
-        Authenticate against the keystone api.
-
-        :param force: Forcefully update the token even if it's already cached
-                      and still valid.
-        :type force: ``bool``
-        """
-        if not self._is_authentication_needed(force=force):
-            return self
-
-        obj = self._get_instance_for_auth_version(
-            auth_version=self.auth_version)
-
-        try:
-            obj.authenticate()
-        finally:
-            self.action = obj.action
-
-        # For backward compatibility, re-assign attributes to this class
-        self.auth_token = obj.auth_token
-        self.auth_token_expires = obj.auth_token_expires
-        self.urls = obj.urls
-        self.auth_user_info = obj.auth_user_info
-
-        return self
-
-
 class OpenStackIdentity_1_0_Connection(OpenStackIdentityConnection):
     """
     Connection class for Keystone API v1.0.


[2/3] git commit: Add list_supported_versions to base OpenStackIdentityConnection class and parse roles which are assigned to the user which is used to authenticate.

Posted by to...@apache.org.
Add list_supported_versions to base OpenStackIdentityConnection class and parse
roles which are assigned to the user which is used to authenticate.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/44945ed4
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/44945ed4
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/44945ed4

Branch: refs/heads/trunk
Commit: 44945ed403530af5df20dec9e43698db036153d8
Parents: 087da80
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Aug 13 16:22:50 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Aug 13 16:34:11 2014 +0200

----------------------------------------------------------------------
 libcloud/common/openstack.py                    |  3 +-
 libcloud/common/openstack_identity.py           | 59 ++++++++++++++++++++
 libcloud/test/common/test_openstack_identity.py | 19 +++++++
 .../openstack_identity/v3_versions.json         | 58 +++++++++++++++++++
 4 files changed, 137 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/44945ed4/libcloud/common/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py
index 80ca08f..0a11d44 100644
--- a/libcloud/common/openstack.py
+++ b/libcloud/common/openstack.py
@@ -28,9 +28,9 @@ from libcloud.common.base import ConnectionUserAndKey, Response
 from libcloud.common.types import ProviderError
 from libcloud.compute.types import (LibcloudError, MalformedResponseError)
 from libcloud.compute.types import KeyPairDoesNotExistError
+from libcloud.common.openstack_identity import get_class_for_auth_version
 
 # Imports for backward compatibility reasons
-from libcloud.common.openstack_identity import get_class_for_auth_version
 from libcloud.common.openstack_identity import OpenStackServiceCatalog
 
 
@@ -246,7 +246,6 @@ class OpenStackBaseConnection(ConnectionUserAndKey):
                                                      name=service_name,
                                                      region=service_region)
 
-        # TODO: Normalize keys for different auth versions and use an object
         url = endpoint.url
 
         if not url:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44945ed4/libcloud/common/openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack_identity.py b/libcloud/common/openstack_identity.py
index 5fdd186..0e11a0b 100644
--- a/libcloud/common/openstack_identity.py
+++ b/libcloud/common/openstack_identity.py
@@ -53,6 +53,7 @@ AUTH_TOKEN_EXPIRES_GRACE_SECONDS = 5
 
 
 __all__ = [
+    'OpenStackIdentityVersion',
     'OpenStackIdentityDomain',
     'OpenStackIdentityProject',
     'OpenStackIdentityUser',
@@ -72,6 +73,19 @@ __all__ = [
 ]
 
 
+class OpenStackIdentityVersion(object):
+    def __init__(self, version, status, updated, url):
+        self.version = version
+        self.status = status
+        self.updated = updated
+        self.url = url
+
+    def __repr__(self):
+        return (('<OpenStackIdentityVersion version=%s, status=%s, '
+                 'updated=%s, url=%s' %
+                 (self.version, self.status, self.updated, self.url)))
+
+
 class OpenStackIdentityDomain(object):
     def __init__(self, id, name, enabled):
         self.id = id
@@ -479,6 +493,7 @@ class OpenStackAuthResponse(Response):
     def success(self):
         return self.status in [httplib.OK, httplib.CREATED,
                                httplib.ACCEPTED, httplib.NO_CONTENT,
+                               httplib.MULTIPLE_CHOICES,
                                httplib.UNAUTHORIZED,
                                httplib.INTERNAL_SERVER_ERROR]
 
@@ -614,6 +629,43 @@ class OpenStackIdentityConnection(ConnectionUserAndKey):
         """
         raise NotImplementedError('authenticate not implemented')
 
+    def list_supported_versions(self):
+        """
+        Retrieve a list of all the identity versions which are supported by
+        this installation.
+
+        :rtype: ``list`` of :class:`.OpenStackIdentityVersion`
+        """
+        response = self.request('/', method='GET')
+        result = self._to_versions(data=response.object['versions']['values'])
+        result = sorted(result, key=lambda x: x.version)
+        return result
+
+    def _to_versions(self, data):
+        result = []
+        for item in data:
+            version = self._to_version(data=item)
+            result.append(version)
+
+        return result
+
+    def _to_version(self, data):
+        try:
+            updated = parse_date(data['updated'])
+        except Exception:
+            updated = None
+
+        try:
+            url = data['links'][0]['href']
+        except IndexError:
+            url = None
+
+        version = OpenStackIdentityVersion(version=data['id'],
+                                           status=data['status'],
+                                           updated=updated,
+                                           url=url)
+        return version
+
     def _is_authentication_needed(self, force=False):
         """
         Determine if the authentication is needed or if the existing token (if
@@ -964,12 +1016,19 @@ class OpenStackIdentity_3_0_Connection(OpenStackIdentityConnection):
                 raise MalformedResponseError('Failed to parse JSON', e)
 
             try:
+                roles = self._to_roles(body['token']['roles'])
+            except Exception:
+                e = sys.exc_info()[1]
+                roles = []
+
+            try:
                 expires = body['token']['expires_at']
 
                 self.auth_token = headers['x-subject-token']
                 self.auth_token_expires = parse_date(expires)
                 self.urls = body['token']['catalog']
                 self.auth_user_info = None
+                self.auth_user_roles = roles
             except KeyError:
                 e = sys.exc_info()[1]
                 raise MalformedResponseError('Auth JSON response is \

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44945ed4/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index 0353bc1..e84222b 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -224,6 +224,7 @@ class OpenStackIdentityConnectionTestCase(unittest.TestCase):
 class OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase):
     def setUp(self):
         mock_cls = OpenStackIdentity_3_0_MockHttp
+        mock_cls.type = None
         OpenStackIdentity_3_0_Connection.conn_classes = (mock_cls, mock_cls)
 
         self.auth_instance = OpenStackIdentity_3_0_Connection(auth_url='http://none',
@@ -231,6 +232,18 @@ class OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase):
                                                               key='test')
         self.auth_instance.auth_token = 'mock'
 
+    def test_list_supported_versions(self):
+        OpenStackIdentity_3_0_MockHttp.type = 'v3'
+
+        versions = self.auth_instance.list_supported_versions()
+        self.assertEqual(len(versions), 2)
+        self.assertEqual(versions[0].version, 'v2.0')
+        self.assertEqual(versions[0].url,
+                         'http://192.168.18.100:5000/v2.0/')
+        self.assertEqual(versions[1].version, 'v3.0')
+        self.assertEqual(versions[1].url,
+                         'http://192.168.18.100:5000/v3/')
+
     def test_list_domains(self):
         domains = self.auth_instance.list_domains()
         self.assertEqual(len(domains), 1)
@@ -435,6 +448,12 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp):
     fixtures = ComputeFileFixtures('openstack_identity')
     json_content_headers = {'content-type': 'application/json; charset=UTF-8'}
 
+    def _v3(self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('v3_versions.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        raise NotImplementedError()
+
     def _v3_domains(self, method, url, body, headers):
         if method == 'GET':
             body = self.fixtures.load('v3_domains.json')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/44945ed4/libcloud/test/compute/fixtures/openstack_identity/v3_versions.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_identity/v3_versions.json b/libcloud/test/compute/fixtures/openstack_identity/v3_versions.json
new file mode 100644
index 0000000..c63b938
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_identity/v3_versions.json
@@ -0,0 +1,58 @@
+{
+    "versions": {
+        "values": [
+            {
+                "status": "stable",
+                "updated": "2013-03-06T00:00:00Z",
+                "media-types": [
+                    {
+                        "base": "application/json",
+                        "type": "application/vnd.openstack.identity-v3+json"
+                    },
+                    {
+                        "base": "application/xml",
+                        "type": "application/vnd.openstack.identity-v3+xml"
+                    }
+                ],
+                "id": "v3.0",
+                "links": [
+                    {
+                        "href": "http://192.168.18.100:5000/v3/",
+                        "rel": "self"
+                    }
+                ]
+            },
+            {
+                "status": "stable",
+                "updated": "2014-04-17T00:00:00Z",
+                "media-types": [
+                    {
+                        "base": "application/json",
+                        "type": "application/vnd.openstack.identity-v2.0+json"
+                    },
+                    {
+                        "base": "application/xml",
+                        "type": "application/vnd.openstack.identity-v2.0+xml"
+                    }
+                ],
+                "id": "v2.0",
+                "links": [
+                    {
+                        "href": "http://192.168.18.100:5000/v2.0/",
+                        "rel": "self"
+                    },
+                    {
+                        "href": "http://docs.openstack.org/api/openstack-identity-service/2.0/content/",
+                        "type": "text/html",
+                        "rel": "describedby"
+                    },
+                    {
+                        "href": "http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf",
+                        "type": "application/pdf",
+                        "rel": "describedby"
+                    }
+                ]
+            }
+        ]
+    }
+}