diff options
author | Jamie Lennox <jamielennox@redhat.com> | 2014-08-31 11:33:42 +1000 |
---|---|---|
committer | Jamie Lennox <jamielennox@redhat.com> | 2014-09-16 10:59:29 +1000 |
commit | b5a435b9abd6b1275e2b6f1531498fef8194af02 (patch) | |
tree | d4ce7c9e37b2174f3c3214aab52444d7cd66b046 /keystoneclient/adapter.py | |
parent | 3305c7be4b726de4dcc889006d0be30eb46d3ad9 (diff) | |
download | python-keystoneclient-b5a435b9abd6b1275e2b6f1531498fef8194af02.tar.gz |
Allow retrying some failed requests
Connection Errors can be transient and there are many clients (including
auth_token middleware) that allow retrying requests that fail.
We should support this in the session, disabled by default, rather than
have multiple implementations for it.
For the moment I have purposefully not added it as an option to
Session.__init__ though I can see arguments for it. This can be added
later if there becomes a particular need.
I have also purposefully distinguished between Connection Errors (and
connect_retries) and HTTP errors. I don't know a good way to generalize
retrying on HTTP errors and they can be added later if required.
Blueprint: session-retries
Change-Id: Ia219636663980433ddb9c00c6df7c8477df4ef99
Diffstat (limited to 'keystoneclient/adapter.py')
-rw-r--r-- | keystoneclient/adapter.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/keystoneclient/adapter.py b/keystoneclient/adapter.py index 24403f9..3d65d78 100644 --- a/keystoneclient/adapter.py +++ b/keystoneclient/adapter.py @@ -27,7 +27,8 @@ class Adapter(object): @utils.positional() def __init__(self, session, service_type=None, service_name=None, interface=None, region_name=None, endpoint_override=None, - version=None, auth=None, user_agent=None): + version=None, auth=None, user_agent=None, + connect_retries=None): """Create a new adapter. :param Session session: The session object to wrap. @@ -41,6 +42,10 @@ class Adapter(object): :param auth.BaseAuthPlugin auth: An auth plugin to use instead of the session one. :param str user_agent: The User-Agent string to set. + :param int connect_retries: the maximum number of retries that should + be attempted for connection errors. + Default None - use session default which + is don't retry. """ self.session = session self.service_type = service_type @@ -51,6 +56,7 @@ class Adapter(object): self.version = version self.user_agent = user_agent self.auth = auth + self.connect_retries = connect_retries def _set_endpoint_filter_kwargs(self, kwargs): if self.service_type: @@ -75,6 +81,8 @@ class Adapter(object): kwargs.setdefault('auth', self.auth) if self.user_agent: kwargs.setdefault('user_agent', self.user_agent) + if self.connect_retries is not None: + kwargs.setdefault('connect_retries', self.connect_retries) return self.session.request(url, method, **kwargs) |