libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1101236 - /incubator/libcloud/trunk/libcloud/common/rackspace.py
Date Mon, 09 May 2011 21:49:26 GMT
Author: tomaz
Date: Mon May  9 21:49:26 2011
New Revision: 1101236

URL: http://svn.apache.org/viewvc?rev=1101236&view=rev
Log:
Start refactoring Rackspace connection class so we will be able to use a
different hostname for each request (needed when acessing cdn stuff in storage
drivers).

Modified:
    incubator/libcloud/trunk/libcloud/common/rackspace.py

Modified: incubator/libcloud/trunk/libcloud/common/rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/common/rackspace.py?rev=1101236&r1=1101235&r2=1101236&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/common/rackspace.py (original)
+++ incubator/libcloud/trunk/libcloud/common/rackspace.py Mon May  9 21:49:26 2011
@@ -30,12 +30,12 @@ __all__ = [
     "AUTH_HOST_US",
     "AUTH_HOST_UK"
     ]
+
 class RackspaceBaseConnection(ConnectionUserAndKey):
     def __init__(self, user_id, key, secure):
         self.cdn_management_url = None
         self.storage_url = None
         self.auth_token = None
-        self.request_path = None
         self.__host = None
         super(RackspaceBaseConnection, self).__init__(
             user_id, key, secure=secure)
@@ -46,13 +46,41 @@ class RackspaceBaseConnection(Connection
         return headers
 
     @property
+    def request_path(self):
+        return self.get_request_path(url_key=self._url_key)
+
+    @property
     def host(self):
+        # Default to server_host
+        return self.get_host(url_key=self._url_key)
+
+    def get_request_path(self, url_key):
+        value_key = '__request_path_%s' % (url_key)
+        value = getattr(self, value_key, None)
+
+        if not value:
+            self._populate_hosts_and_request_paths()
+            value = getattr(self, value_key, None)
+
+        return value
+
+    def get_host(self, url_key):
+        value_key = '__%s' % (url_key)
+        value = getattr(self, value_key, None)
+
+        if not value:
+            self._populate_hosts_and_request_paths()
+            value = getattr(self, value_key, None)
+
+        return value
+
+    def _populate_hosts_and_request_paths(self):
         """
         Rackspace uses a separate host for API calls which is only provided
         after an initial authentication request. If we haven't made that
         request yet, do it here. Otherwise, just return the management host.
         """
-        if not self.__host:
+        if not self.auth_token:
             # Initial connection used for authentication
             conn = self.conn_classes[self.secure](
                 self.auth_host, self.port[self.secure])
@@ -81,11 +109,12 @@ class RackspaceBaseConnection(Connection
             except KeyError:
                 raise InvalidCredsError()
 
-            scheme, server, self.request_path, param, query, fragment = (
-                urlparse.urlparse(getattr(self, self._url_key)))
+            for key in ['server_url', 'storage_url', 'cdn_management_url',
+                        'lb_url']:
+                scheme, server, request_path, param, query, fragment = (
+                    urlparse.urlparse(getattr(self, key)))
+                # Set host to where we want to make further requests to
+                setattr(self, '__%s' % (key), server)
+                setattr(self, '__request_path_%s' % (key), request_path)
 
-            # Set host to where we want to make further requests to;
-            self.__host = server
             conn.close()
-
-        return self.__host



Mime
View raw message