def registration_retry(ExceptionToCheck=(EC2ResponseError,), tries=3, delay=1, backoff=1, logger=None):
    """
    a slightly tweaked form of aminator.util.retry for handling retries on image registration
    """
    if logger is None:
        logger = log

    @decorator
    def _retry(f, *args, **kwargs):
        _tries, _delay = tries, delay
        total_tries = _tries
        args, kwargs = args, kwargs
        while _tries > 0:
            try:
                return f(*args, **kwargs)
            except ExceptionToCheck, e:
                if e.error_code == 'InvalidAMIName.Duplicate':
                    log.debug('Duplicate AMI Name {0}, retrying'.format(kwargs['name']))
                    attempt = abs(_tries - (total_tries + 1))
                    kwargs['name'] = kwargs.pop('name') + str(attempt)
                    log.debug('Trying name {0}'.format(kwargs['name']))
                    sleep(_delay)
                    _tries -= 1
                    _delay *= backoff
                else:
                    for (code, msg) in e.errors:
                        log.critical('EC2ResponseError: {0}: {1}.'.format(code, msg))
                        return False
        log.critical('Failed to register AMI')
        return False
    return _retry
dataset/ETHPy150Open Netflix/aminator/aminator/plugins/cloud/ec2.py/registration_retry/original