summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-09-15 20:26:16 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-09-15 20:26:16 +0000
commitaf54731f9ae7bb41d6430fac613081798ec11262 (patch)
tree624951c3d829500bbb6f62394a1c632f47560db7
parent874ad0df93b738675effd49c60accbb9cdaa384b (diff)
downloadbcfg2-af54731f9ae7bb41d6430fac613081798ec11262.tar.gz
bcfg2-af54731f9ae7bb41d6430fac613081798ec11262.tar.bz2
bcfg2-af54731f9ae7bb41d6430fac613081798ec11262.zip
Proxy: Implement tunable socket timeouts
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5435 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Proxy.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/lib/Proxy.py b/src/lib/Proxy.py
index 5a52e0af5..fc71d212c 100644
--- a/src/lib/Proxy.py
+++ b/src/lib/Proxy.py
@@ -34,9 +34,9 @@ class CertificateError(Exception):
class RetryMethod(_Method):
"""Method with error handling and retries built in"""
log = logging.getLogger('xmlrpc')
+ max_retries = 4
def __call__(self, *args):
- max_retries = 4
- for retry in range(max_retries):
+ for retry in range(self.max_retries):
try:
return _Method.__call__(self, *args)
except xmlrpclib.ProtocolError, err:
@@ -104,18 +104,19 @@ class SSLHTTPConnection(httplib.HTTPConnection):
class XMLRPCTransport(xmlrpclib.Transport):
- def __init__(self, key=None, cert=None, ca=None, scns=None, use_datetime=0):
+ def __init__(self, key=None, cert=None, ca=None, scns=None, use_datetime=0, timeout=90):
if hasattr(xmlrpclib.Transport, '__init__'):
xmlrpclib.Transport.__init__(self, use_datetime)
self.key = key
self.cert = cert
self.ca = ca
self.scns = scns
+ self.timeout = timeout
def make_connection(self, host):
host = self.get_host_info(host)[0]
http = SSLHTTPConnection(host, key=self.key, cert=self.cert, ca=self.ca,
- scns=self.scns)
+ scns=self.scns, timeout=self.timeout)
https = httplib.HTTP()
https._setup(http)
return https
@@ -160,7 +161,7 @@ class XMLRPCTransport(xmlrpclib.Transport):
return u.close()
def ComponentProxy (url, user=None, password=None, key=None, cert=None, ca=None,
- allowedServerCNs=None):
+ allowedServerCNs=None, timeout=90):
"""Constructs proxies to components.
@@ -175,6 +176,6 @@ def ComponentProxy (url, user=None, password=None, key=None, cert=None, ca=None,
newurl = "%s://%s:%s@%s" % (method, user, password, path)
else:
newurl = url
- ssl_trans = XMLRPCTransport(key, cert, ca, allowedServerCNs)
+ ssl_trans = XMLRPCTransport(key, cert, ca, allowedServerCNs, timeout=timeout)
return xmlrpclib.ServerProxy(newurl, allow_none=True, transport=ssl_trans)