libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r892089 - /incubator/libcloud/trunk/libcloud/base.py
Date Fri, 18 Dec 2009 01:42:43 GMT
Author: pquerna
Date: Fri Dec 18 01:42:43 2009
New Revision: 892089

URL: http://svn.apache.org/viewvc?rev=892089&view=rev
Log:
Add a LoggingHTTPSConnection which writes the `curl` commands you could run to get the same
HTTP results.  Useful for debugging various providers.  This should go somewhere else in the
long term, sticking it here to get us started.

Modified:
    incubator/libcloud/trunk/libcloud/base.py

Modified: incubator/libcloud/trunk/libcloud/base.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/base.py?rev=892089&r1=892088&r2=892089&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/base.py (original)
+++ incubator/libcloud/trunk/libcloud/base.py Fri Dec 18 01:42:43 2009
@@ -23,6 +23,7 @@
 from libcloud.interface import INodeSizeFactory, INodeSize
 from libcloud.interface import INodeImageFactory, INodeImage
 import hashlib
+from pipes import quote as pquote
 
 class Node(object):
     """
@@ -159,6 +160,29 @@
         """
         return self.status == httplib.OK or self.status == httplib.CREATED
 
+#TODO: Move this to a better location/package
+class LoggingHTTPSConnection(httplib.HTTPSConnection):
+  logfile = "/tmp/libcloud.log"
+
+  def _to_curl(self, method, url, body, headers):
+    cmd = ["curl", "--compressed"]
+
+    cmd.extend(["-X", pquote(method)])
+
+    for h in headers:
+      cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])
+
+    if body is not None and len(body) > 0:
+      cmd.extend(["--data-binary", pquote(body)])
+    
+    cmd.extend([pquote("https://%s:%d%s" % (self.host, self.port, url))])
+    return " ".join(cmd)
+
+  def request(self, method, url, body=None, headers=None):
+    fp = open(self.logfile, 'a')
+    fp.write(self._to_curl(method, url, body, headers) + "\n")
+    fp.close()
+    return httplib.HTTPSConnection.request(self, method, url, body, headers)
 
 class ConnectionKey(object):
     """
@@ -167,7 +191,9 @@
     interface.implementsOnly(IConnectionKey)
     interface.classProvides(IConnectionKeyFactory)
 
+    #conn_classes = (httplib.HTTPConnection, LoggingHTTPSConnection)
     conn_classes = (httplib.HTTPConnection, httplib.HTTPSConnection)
+
     responseCls = Response
     connection = None
     host = '127.0.0.1'



Mime
View raw message