Merge branch 'master' into eucalyptus-devel
[sfa.git] / sfa / util / xmlrpcprotocol.py
index 67d6d62..61e16fe 100644 (file)
@@ -1,5 +1,6 @@
 # XMLRPC-specific code for SFA Client
 
+import httplib
 import xmlrpclib
 
 from sfa.util.sfalogging import sfa_logger
@@ -25,26 +26,25 @@ class ExceptionUnmarshaller(xmlrpclib.Unmarshaller):
 #
 # A transport for XMLRPC that works on top of HTTPS
 
+# python 2.7 xmlrpclib has changed its internal code
+# it now calls 'getresponse' on the obj returned by make_connection
+# while it used to call 'getreply'
+# regardless of the version, httplib.HTTPS does implement getreply, 
+# while httplib.HTTPSConnection has getresponse
+# so we create a dummy instance to check what's expected
+need_HTTPSConnection=hasattr(xmlrpclib.Transport().make_connection('localhost'),'getresponse')
+
 class XMLRPCTransport(xmlrpclib.Transport):
     key_file = None
     cert_file = None
     def make_connection(self, host):
         # create a HTTPS connection object from a host descriptor
         # host may be a string, or a (host, x509-dict) tuple
-        import httplib
         host, extra_headers, x509 = self.get_host_info(host)
-        try:
-            HTTPS = httplib.HTTPS()
-# xxx sfa-1.0-10-broken - non-working attempt for python-2.7
-#            HTTPS = httplib.HTTPSConnection(host, None)
-        except AttributeError:
-            raise NotImplementedError(
-                "your version of httplib doesn't support HTTPS"
-                )
+        if need_HTTPSConnection:
+            return httplib.HTTPSConnection(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {}))
         else:
             return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {}))
-# xxx sfa-1.0-10-broken - non-working attempt for python-2.7
-#            return httplib.HTTPSConnection(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {}))
 
     def getparser(self):
         unmarshaller = ExceptionUnmarshaller()
@@ -53,14 +53,16 @@ class XMLRPCTransport(xmlrpclib.Transport):
 
 class XMLRPCServerProxy(xmlrpclib.ServerProxy):
     def __init__(self, url, transport, allow_none=True, options=None):
+        # remember url for GetVersion
+        self.url=url
         verbose = False
         if options and options.debug:
             verbose = True
-        sfa_logger().info ("Connecting to xmlrpcserver at %s (with verbose=%s)"%(url,verbose))
+#        sfa_logger().debug ("xmlrpcprotocol.XMLRPCServerProxy.__init__ %s (with verbose=%s)"%(url,verbose))
         xmlrpclib.ServerProxy.__init__(self, url, transport, allow_none=allow_none, verbose=verbose)
 
     def __getattr__(self, attr):
-        sfa_logger().info ("Calling xml-rpc method:%s"%attr)
+        sfa_logger().debug ("xml-rpc %s method:%s"%(self.url,attr))
         return xmlrpclib.ServerProxy.__getattr__(self, attr)