summaryrefslogtreecommitdiff
path: root/ironicclient/shell.py
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@redhat.com>2015-04-16 14:43:46 +0200
committerDmitry Tantsur <dtantsur@redhat.com>2015-04-17 16:25:44 +0200
commit28bdd0baebeeb0bc05c12dfe19fcae75e04e9f07 (patch)
tree08acc0b41cca303e688ca8bdb775fe8915c3d966 /ironicclient/shell.py
parent06a62bc60eef42b3dfcecbe923922f49cd17dace (diff)
downloadpython-ironicclient-28bdd0baebeeb0bc05c12dfe19fcae75e04e9f07.tar.gz
Implement and enable retries on Conflict
Getting Conflict errors is pretty annoying, especially when writing automation scripts. Nova and ironic-discoverd already have their own logic for retrying on such errors. This patch adds 'max_retries' and 'retry_interval' arguments to get_client for tuning or disabling retries. Change-Id: Id9720c87ce3846faec61eb40ccf00970ca798ad2
Diffstat (limited to 'ironicclient/shell.py')
-rw-r--r--ironicclient/shell.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/ironicclient/shell.py b/ironicclient/shell.py
index 9ff59a9..2c5855f 100644
--- a/ironicclient/shell.py
+++ b/ironicclient/shell.py
@@ -34,6 +34,7 @@ import six.moves.urllib.parse as urlparse
import ironicclient
from ironicclient import client as iroclient
+from ironicclient.common import http
from ironicclient.common.i18n import _
from ironicclient.common import utils
from ironicclient import exc
@@ -221,6 +222,25 @@ class IronicShell(object):
parser.add_argument('--os_endpoint_type',
help=argparse.SUPPRESS)
+ parser.add_argument('--max-retries', type=int,
+ help='Maximum number of retries in case of '
+ 'conflict error (HTTP 409). '
+ 'Defaults to env[IRONIC_MAX_RETRIES] or %d. '
+ 'Use 0 to disable retrying.'
+ % http.DEFAULT_MAX_RETRIES,
+ default=cliutils.env(
+ 'IRONIC_MAX_RETRIES',
+ default=str(http.DEFAULT_MAX_RETRIES)))
+
+ parser.add_argument('--retry-interval', type=int,
+ help='Amount of time (in seconds) between retries '
+ 'in case of conflict error (HTTP 409). '
+ 'Defaults to env[IRONIC_RETRY_INTERVAL] or %d.'
+ % http.DEFAULT_RETRY_INTERVAL,
+ default=cliutils.env(
+ 'IRONIC_RETRY_INTERVAL',
+ default=str(http.DEFAULT_RETRY_INTERVAL)))
+
# FIXME(gyee): this method should come from python-keystoneclient.
# Will refactor this code once it is available.
# https://bugs.launchpad.net/python-keystoneclient/+bug/1332337
@@ -502,6 +522,14 @@ class IronicShell(object):
'password': args.os_password,
}
kwargs['os_ironic_api_version'] = os_ironic_api_version
+ if args.max_retries < 0:
+ raise exc.CommandError(_("You must provide value >= 0 for "
+ "--max-retries"))
+ if args.retry_interval < 1:
+ raise exc.CommandError(_("You must provide value >= 1 for "
+ "--retry-interval"))
+ kwargs['max_retries'] = args.max_retries
+ kwargs['retry_interval'] = args.retry_interval
client = iroclient.Client(api_major_version, endpoint, **kwargs)
try: