Python botocore.exceptions 模块,WaiterError() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用botocore.exceptions.WaiterError()

项目:slippin-jimmy    作者:scm-spain    | 项目源码 | 文件源码
def run_cluster(self, cluster_configuration):
        """
        Launch a cluster based on given configuration
        :param cluster_configuration: string
        """
        aws_arguments = self.__job_flow_configuration.convert_to_arguments(cluster_configuration)

        self.__logger.debug('Launching cluster with given configuration')
        response = self.__aws_emr_client.run_job_flow(**aws_arguments)
        self.__logger.info('Cluster launched with ID: {cluster_id}'.format(cluster_id=response['JobFlowId']))
        try:
            waiter = self.__aws_emr_client.get_waiter('cluster_running')
            self.__logger.info('Waiting for cluster to be ready')
            waiter.wait(ClusterId=response['JobFlowId'])
            self.__logger.info('Cluster up and running ID: {cluster_id}'.format(cluster_id=response['JobFlowId']))
        except WaiterError:
            self.__logger.error('Cluster creation failed')
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def key_exists(self, bucket_name, key_name, min_successes=3):
        try:
            self.wait_until_key_exists(
                    bucket_name, key_name, min_successes=min_successes)
            return True
        except (ClientError, WaiterError):
            return False
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def key_not_exists(self, bucket_name, key_name, min_successes=3):
        try:
            self.wait_until_key_not_exists(
                    bucket_name, key_name, min_successes=min_successes)
            return True
        except (ClientError, WaiterError):
            return False
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def validate_and_find_master_dns(session, parsed_globals, cluster_id):
    """
    Utility method for ssh, socks, put and get command.
    Check if the cluster to be connected to is
     terminated or being terminated.
    Check if the cluster is running.
    Find master instance public dns of a given cluster.
    Return the latest created master instance public dns name.
    Throw MasterDNSNotAvailableError or ClusterTerminatedError.
    """
    cluster_state = emrutils.get_cluster_state(
        session, parsed_globals, cluster_id)

    if cluster_state in constants.TERMINATED_STATES:
        raise exceptions.ClusterTerminatedError

    emr = emrutils.get_client(session, parsed_globals)

    try:
        cluster_running_waiter = emr.get_waiter('cluster_running')
        if cluster_state in constants.STARTING_STATES:
            print("Waiting for the cluster to start.")
        cluster_running_waiter.wait(ClusterId=cluster_id)
    except WaiterError:
        raise exceptions.MasterDNSNotAvailableError

    return emrutils.find_master_dns(
        session=session, cluster_id=cluster_id,
        parsed_globals=parsed_globals)
项目:dcos    作者:dcos    | 项目源码 | 文件源码
def is_rate_limit_error(exception):
    if exception in [exceptions.ClientError, exceptions.WaiterError]:
        if isinstance(exception, exceptions.ClientError):
            error_code = exception.response['Error']['Code']
        elif isinstance(exception, exceptions.WaiterError):
            error_code = exception.last_response['Error']['Code']
        if error_code in ['Throttling', 'RequestLimitExceeded']:
            print('AWS rate-limit encountered!')
            return True
    return False
项目:dcos-launch    作者:dcos    | 项目源码 | 文件源码
def retry_boto_rate_limits(boto_fn, wait=2, timeout=60 * 60):
    """Decorator to make boto functions resilient to AWS rate limiting and throttling.
    If one of these errors is encounterd, the function will sleep for a geometrically
    increasing amount of time
    """
    @functools.wraps(boto_fn)
    def ignore_rate_errors(*args, **kwargs):
        local_wait = copy.copy(wait)
        local_timeout = copy.copy(timeout)
        while local_timeout > 0:
            next_time = time.time() + local_wait
            try:
                return boto_fn(*args, **kwargs)
            except (ClientError, WaiterError) as e:
                if isinstance(e, ClientError):
                    error_code = e.response['Error']['Code']
                elif isinstance(e, WaiterError):
                    error_code = e.last_response['Error']['Code']
                else:
                    raise
                if error_code in ['Throttling', 'RequestLimitExceeded']:
                    log.warn('AWS API Limiting error: {}'.format(error_code))
                    log.warn('Sleeping for {} seconds before retrying'.format(local_wait))
                    time_to_next = next_time - time.time()
                    if time_to_next > 0:
                        time.sleep(time_to_next)
                    else:
                        local_timeout += time_to_next
                    local_timeout -= local_wait
                    local_wait *= 2
                    continue
                raise
        raise Exception('Rate-limit timeout encountered waiting for {}'.format(boto_fn.__name__))
    return ignore_rate_errors