summaryrefslogtreecommitdiff
path: root/neutronclient/v2_0
diff options
context:
space:
mode:
authorJakub Libosvar <libosvar@redhat.com>2014-04-24 16:58:50 +0200
committerJakub Libosvar <libosvar@redhat.com>2014-07-29 10:41:35 +0200
commit65883ba4eb6fe4cd41faaf7557c63ccf802b09cf (patch)
tree0b2b90c45bcc831b84836c1106d292ea71375346 /neutronclient/v2_0
parentb4f4544eaa3519243e41f55bf89473fb6f1ce9c8 (diff)
downloadpython-neutronclient-65883ba4eb6fe4cd41faaf7557c63ccf802b09cf.tar.gz
Add option for retry number of connection attempts
This patch adds a new option (-r | --retries) to specify how many times the client should attempt to connect to the Neutron server when using idempotent methods (GET, PUT and DELETE). The patch also provides more user-friendly message when it's impossible to connect to Neutron server from CLI and ensures that connection-related exceptions are raised to the caller by default when neutronclient is used as a library. DocImpact Closes-Bug: #1312225 Change-Id: Id74d7cf9a0e8c5d2cd3ee4851c883d5286bea19d
Diffstat (limited to 'neutronclient/v2_0')
-rw-r--r--neutronclient/v2_0/client.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py
index a102781..630d413 100644
--- a/neutronclient/v2_0/client.py
+++ b/neutronclient/v2_0/client.py
@@ -129,6 +129,12 @@ class Client(object):
http requests. (optional)
:param bool insecure: SSL certificate validation. (optional)
:param string ca_cert: SSL CA bundle file to use. (optional)
+ :param integer retries: How many times idempotent (GET, PUT, DELETE)
+ requests to Neutron server should be retried if
+ they fail (default: 0).
+ :param bool raise_errors: If True then exceptions caused by connection
+ failure are propagated to the caller.
+ (default: True)
Example::
@@ -1194,7 +1200,8 @@ class Client(object):
self.version = '2.0'
self.format = 'json'
self.action_prefix = "/v%s" % (self.version)
- self.retries = 0
+ self.retries = kwargs.get('retries', 0)
+ self.raise_errors = kwargs.get('raise_errors', True)
self.retry_interval = 1
def _handle_fault_response(self, status_code, response_body):
@@ -1303,8 +1310,16 @@ class Client(object):
if i < self.retries:
_logger.debug('Retrying connection to Neutron service')
time.sleep(self.retry_interval)
+ elif self.raise_errors:
+ raise
- raise exceptions.ConnectionFailed(reason=_("Maximum attempts reached"))
+ if self.retries:
+ msg = (_("Failed to connect to Neutron server after %d attempts")
+ % max_attempts)
+ else:
+ msg = _("Failed to connect Neutron server")
+
+ raise exceptions.ConnectionFailed(reason=msg)
def delete(self, action, body=None, headers=None, params=None):
return self.retry_request("DELETE", action, body=body,