patch by Thomas Dreibholz - ovs-vsctl and not ovs-ovsctl
[nodemanager.git] / safexmlrpc.py
index f4bd5af..2392c0d 100644 (file)
@@ -1,18 +1,29 @@
 """Leverage curl to make XMLRPC requests that check the server's credentials."""
 
-import curlwrapper
 import xmlrpclib
 
+import curlwrapper
+
 
-CURL = '/usr/bin/curl'
+class CertificateCheckingSafeTransport (xmlrpclib.Transport):
+
+    def __init__(self, cacert, timeout):
+        self.cacert = cacert
+        self.timeout = timeout
 
-class CertificateCheckingSafeTransport(xmlrpclib.Transport):
     def request(self, host, handler, request_body, verbose=0):
         self.verbose = verbose
-        try:
-            contents = curlwrapper.retrieve('https://%s%s' % (host, handler), request_body)
-            return xmlrpclib.loads(contents)[0]
-        except curlwrapper.CurlException, e: raise xmlrpclib.ProtocolError(host + handler, -1, str(e), '')
+        url='https://%s%s' % (host, handler)
+        # this might raise an xmlrpclib.Protocolerror exception
+        contents = curlwrapper.retrieve(url,
+                                        cacert = self.cacert,
+                                        postdata = request_body,
+                                        timeout = self.timeout)
+        return xmlrpclib.loads(contents)[0]
 
 class ServerProxy(xmlrpclib.ServerProxy):
-    def __init__(self, handler, *args, **kw_args): xmlrpclib.ServerProxy.__init__(self, handler, CertificateCheckingSafeTransport())
+
+    def __init__(self, uri, cacert, timeout = 300, **kwds):
+        xmlrpclib.ServerProxy.__init__(self, uri,
+                                       CertificateCheckingSafeTransport(cacert, timeout),
+                                       **kwds)