Disallow multiple conf_files instances and have conf_files use curl with certificates.
[nodemanager.git] / safexmlrpc.py
index 96865df..f4bd5af 100644 (file)
@@ -1,6 +1,6 @@
 """Leverage curl to make XMLRPC requests that check the server's credentials."""
 
-from subprocess import PIPE, Popen
+import curlwrapper
 import xmlrpclib
 
 
@@ -9,16 +9,10 @@ CURL = '/usr/bin/curl'
 class CertificateCheckingSafeTransport(xmlrpclib.Transport):
     def request(self, host, handler, request_body, verbose=0):
         self.verbose = verbose
-        p = Popen((CURL, '--cacert', '/usr/boot/cacert.pem', '--data', '@-', 'https://%s%s' % (host, handler)), stdin=PIPE, stdout=PIPE, stderr=PIPE)
-        p.stdin.write(request_body)
-        p.stdin.close()
-        contents = p.stdout.read()
-        p.stdout.close()
-        error = p.stderr.read()
-        p.stderr.close()
-        rc = p.wait()
-        if rc != 0: raise xmlrpclib.ProtocolError(host + handler, rc, error, '')
-        return xmlrpclib.loads(contents)[0]
+        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), '')
 
 class ServerProxy(xmlrpclib.ServerProxy):
     def __init__(self, handler, *args, **kw_args): xmlrpclib.ServerProxy.__init__(self, handler, CertificateCheckingSafeTransport())