def make_api_call()

in ebcli/lib/aws.py [0:0]


def make_api_call(service_name, operation_name, **operation_options):
    operation = _set_operation(service_name, operation_name)
    aggregated_error_message = []
    max_attempts = 10

    region = _region_name
    if not region:
        region = 'default'
    if region == 'placeholder':
        set_region(fileoperations.get_config_setting('global', 'default_region'))

    attempt = 0
    while True:
        attempt += 1
        if attempt > 1:
            LOG.debug('Retrying -- attempt #' + str(attempt))
        _sleep(_get_delay(attempt))
        try:
            LOG.debug('Making api call: (' +
                      service_name + ', ' + operation_name +
                      ') to region: ' + region + ' with args:' + str(operation_options))
            response_data = operation(**operation_options)
            status = response_data['ResponseMetadata']['HTTPStatusCode']
            LOG.debug('API call finished, status = ' + str(status))
            if response_data:
                LOG.debug('Response: ' + str(response_data))

            return response_data

        except botocore.exceptions.ClientError as e:
            _handle_response_code(e.response, attempt, aggregated_error_message)
        except botocore.parsers.ResponseParserError as e:
            LOG.debug('Botocore could not parse response received')
            if attempt > max_attempts:
                raise MaxRetriesError(
                    'Max retries exceeded for ResponseParserErrors'
                    + os.linesep.join(aggregated_error_message)
                )

            aggregated_error_message.insert(attempt, str(e))
        except botocore.exceptions.NoCredentialsError:
            LOG.debug('No credentials found')
            raise CredentialsError('Operation Denied. You appear to have no'
                                   ' credentials')
        except botocore.exceptions.PartialCredentialsError as e:
            LOG.debug('Credentials incomplete')
            raise CredentialsError(str(e))

        except (botocore.exceptions.ValidationError,
                botocore.exceptions.ParamValidationError) as e:
            raise ValidationError(str(e))

        except botocore.exceptions.EndpointConnectionError as e:
            LOG.debug(e)
            raise

        except botocore.exceptions.BotoCoreError:
            LOG.error('Botocore Error')
            raise

        except IOError as error:
            if hasattr(error.args[0], 'reason') and str(error.args[0].reason) == \
                    '[Errno -2] Name or service not known':
                raise ConnectionError()

            LOG.error('Error while contacting Elastic Beanstalk Service')
            LOG.debug('error:' + str(error))
            raise ServiceError(error)