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 2013/11/15 11:13:24 UTC

[3/5] git commit: Refactor the code to make it easier to follow.

Refactor the code to make it easier to follow.


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

Branch: refs/heads/trunk
Commit: 22caded175986a91cab817b5410fb6d0f1c811c0
Parents: b9f7de8
Author: Tomaz Muraus <to...@apache.org>
Authored: Fri Nov 15 10:39:14 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Fri Nov 15 10:39:14 2013 +0100

----------------------------------------------------------------------
 libcloud/common/openstack.py | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/22caded1/libcloud/common/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py
index 1f13eab..5c4f02b 100644
--- a/libcloud/common/openstack.py
+++ b/libcloud/common/openstack.py
@@ -574,6 +574,10 @@ class OpenStackBaseConnection(ConnectionUserAndKey):
     def request(self, **kwargs):
         return super(OpenStackBaseConnection, self).request(**kwargs)
 
+    def _set_up_connection_info(self, url):
+        result = self._tuple_from_url(url)
+        (self.host, self.port, self.secure, self.request_path) = result
+
     def _populate_hosts_and_request_paths(self):
         """
         OpenStack uses a separate host for API calls which is only provided
@@ -581,10 +585,19 @@ class OpenStackBaseConnection(ConnectionUserAndKey):
         """
         osa = self._osa
 
-        # Token is not available or it has expired. Need to retrieve a new one.
-        if not self._ex_force_auth_token and not osa.is_token_valid():
-            # This call may throw InvalidCreds, etc
-            osa.authenticate()
+        if self._ex_force_auth_token:
+            # If ex_force_auth_token is provided we always hit the api directly
+            # and never try to authenticate.
+            #
+            # Note: When ex_force_auth_token is provided, ex_force_base_url
+            # must be provided as well.
+            self._set_up_connection_info(url=self._ex_force_base_url)
+            return
+
+        if not osa.is_token_valid():
+            # Token is not available or it has expired. Need to retrieve a
+            # new one.
+            osa.authenticate()  # may throw InvalidCreds
 
             self.auth_token = osa.auth_token
             self.auth_token_expires = osa.auth_token_expires
@@ -595,10 +608,8 @@ class OpenStackBaseConnection(ConnectionUserAndKey):
                                           self._auth_version)
             self.service_catalog = osc
 
-        # Set up connection info
         url = self._ex_force_base_url or self.get_endpoint()
-        (self.host, self.port, self.secure, self.request_path) = \
-            self._tuple_from_url(url)
+        self._set_up_connection_info(url=url)
 
 
 class OpenStackDriverMixin(object):