Tagging module NodeManager - NodeManager-1.7-37
[nodemanager.git] / safexmlrpc.py
1 # $Id$
2
3 """Leverage curl to make XMLRPC requests that check the server's credentials."""
4
5 import xmlrpclib
6
7 import curlwrapper
8
9
10 class CertificateCheckingSafeTransport (xmlrpclib.Transport):
11
12     def __init__(self, cacert, timeout):
13         self.cacert = cacert
14         self.timeout = timeout
15
16     def request(self, host, handler, request_body, verbose=0):
17         self.verbose = verbose
18         url='https://%s%s' % (host, handler)
19         # this might raise an xmlrpclib.Protocolerror exception
20         contents = curlwrapper.retrieve(url,
21                                         cacert = self.cacert,
22                                         postdata = request_body,
23                                         timeout = self.timeout)
24         return xmlrpclib.loads(contents)[0]
25
26 class ServerProxy(xmlrpclib.ServerProxy):
27
28     def __init__(self, uri, cacert, timeout = 300, **kwds):
29         xmlrpclib.ServerProxy.__init__(self, uri,
30                                        CertificateCheckingSafeTransport(cacert, timeout),
31                                        **kwds)