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 2012/02/18 01:49:53 UTC

svn commit: r1245823 - in /libcloud/trunk: CHANGES libcloud/common/openstack.py libcloud/compute/drivers/openstack.py libcloud/loadbalancer/drivers/rackspace.py test/compute/test_openstack.py

Author: tomaz
Date: Sat Feb 18 00:49:53 2012
New Revision: 1245823

URL: http://svn.apache.org/viewvc?rev=1245823&view=rev
Log:
Alow users to use a list of tuples for the query string parameters inside
the OpenStack connection classes. This way same the key can be specified
multiple times. This patch has been submitted by Dave King and is part of
LIBCLOUD-153.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/common/openstack.py
    libcloud/trunk/libcloud/compute/drivers/openstack.py
    libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
    libcloud/trunk/test/compute/test_openstack.py

Modified: libcloud/trunk/CHANGES
URL: http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1245823&r1=1245822&r2=1245823&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Sat Feb 18 00:49:53 2012
@@ -13,18 +13,24 @@ Changes with Apache Libcloud in developm
 
       Note: The openstack.py base driver no longer works by default with
       Rackspace nova. The default endpoint parsed from the service catalog
-      is the default compute endpoint for devstack.
+      is the default compute endpoint for devstack. ; LIBCLOUD-151
       [Brad Morgan]
 
   *) Compute:
 
     - Add new RackspaceNovaBeta and RackspaveNovaDfw driver based on the
-      OpenStack.
+      OpenStack. ; LIBCLOUD-151
       [Brad Morgan]
 
     - Include 'created' and 'updated' attribute in the OpenStack 1.1 driver.
+      ; LIBCLOUD-155
       [Chris Gilmer]
 
+    - Alow users to use a list of tuples for the query string parameters inside
+      the OpenStack connection classes. This way same key can be specified
+      multiple times ; LIBCLOUD-153
+      [Dave King]
+
   *) Storage:
 
     - Don't lowercase special header names in the Amazon S3 storage driver. ;
@@ -39,6 +45,7 @@ Changes with Apache Libcloud in developm
 
     - Add an extension method (ex_balancer_attach_members) for attaching 
       multiple members to a load balancer in the Rackspace driver.
+      LIBCLOUD-152  
       [Adam Pickeral]
 
 Changes with Apache Libcloud 0.8.0:

Modified: libcloud/trunk/libcloud/common/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/openstack.py?rev=1245823&r1=1245822&r2=1245823&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/openstack.py (original)
+++ libcloud/trunk/libcloud/common/openstack.py Sat Feb 18 00:49:53 2012
@@ -17,6 +17,8 @@
 Common utilities for OpenStack
 """
 import sys
+import binascii
+import os
 
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlparse
@@ -354,3 +356,11 @@ class OpenStackBaseConnection(Connection
 
             # Set up connection info
             (self.host, self.port, self.secure, self.request_path) = self._tuple_from_url(self._ex_force_base_url or self.get_endpoint())
+
+    def _add_cache_busting_to_params(self, params):
+        cache_busting_number = binascii.hexlify(os.urandom(8))
+
+        if isinstance(params, dict):
+            params['cache-busting'] = cache_busting_number
+        else:
+            params.append(('cache-busting', cache_busting_number))

Modified: libcloud/trunk/libcloud/compute/drivers/openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/drivers/openstack.py?rev=1245823&r1=1245822&r2=1245823&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/drivers/openstack.py (original)
+++ libcloud/trunk/libcloud/compute/drivers/openstack.py Sat Feb 18 00:49:53 2012
@@ -143,7 +143,7 @@ class OpenStackComputeConnection(OpenSta
             headers = {'Content-Type': self.default_content_type}
 
         if method == "GET":
-            params['cache-busting'] = binascii.hexlify(os.urandom(8))
+            self._add_cache_busting_to_params(params)
 
         return super(OpenStackComputeConnection, self).request(
             action=action,

Modified: libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py?rev=1245823&r1=1245822&r2=1245823&view=diff
==============================================================================
--- libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py (original)
+++ libcloud/trunk/libcloud/loadbalancer/drivers/rackspace.py Sat Feb 18 00:49:53 2012
@@ -245,7 +245,7 @@ class RackspaceConnection(OpenStackBaseC
         if method in ('POST', 'PUT'):
             headers['Content-Type'] = 'application/json'
         if method == 'GET':
-            params['cache-busing'] = binascii.hexlify(os.urandom(8))
+            self._add_cache_busting_to_params(params)
 
         return super(RackspaceConnection, self).request(action=action,
                 params=params, data=data, method=method, headers=headers)

Modified: libcloud/trunk/test/compute/test_openstack.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_openstack.py?rev=1245823&r1=1245822&r2=1245823&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_openstack.py (original)
+++ libcloud/trunk/test/compute/test_openstack.py Sat Feb 18 00:49:53 2012
@@ -716,6 +716,13 @@ class OpenStack_1_1_Tests(unittest.TestC
         self.assertEqual(image_id, '1d4a8ea9-aae7-4242-a42d-5ff4702f2f14')
         self.assertEqual(image_id_two, '13')
 
+    def test_cache_busts(self):
+        self.driver.connection.request("/servers/12066", params={"key": "value"})
+
+    def test_cache_busts_with_list_of_tuples(self):
+        params = [("key", "value1"), ("key", "value2") ]
+        self.driver.connection.request("/servers/12067", params=params)
+
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False
@@ -794,6 +801,28 @@ class OpenStack_1_1_MockHttp(MockHttpTes
         else:
             raise NotImplementedError()
 
+    # Cache Busting Test -- parameters as a dictionary
+    def _v1_1_slug_servers_12066(self, method, url, body, headers):
+        if method == "GET":
+            self.assertTrue("cache-busting=" in url, msg="Did not add cache-busting query string")
+            self.assertTrue("key=value" in url, msg="Did not add parameters")
+            body = self.fixtures.load('_servers_12064.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+        raise NotImplementedError()
+
+    # Cache Busting Test -- parameters as a list of tuples
+    def _v1_1_slug_servers_12067(self, method, url, body, headers):
+        if method == "GET":
+            self.assertTrue("cache-busting=" in url, msg="Did not add cache-busting query string")
+            self.assertTrue("key=value1" in url, msg="Did not add parameters")
+            self.assertTrue("key=value2" in url, msg="Did not add parameters")
+            body = self.fixtures.load('_servers_12064.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+        raise NotImplementedError()
+
+
     def _v1_1_slug_servers_12064(self, method, url, body, headers):
         if method == "GET":
             body = self.fixtures.load('_servers_12064.json')