當前位置: 首頁>>代碼示例>>Python>>正文


Python exception.BotoServerError方法代碼示例

本文整理匯總了Python中boto.exception.BotoServerError方法的典型用法代碼示例。如果您正苦於以下問題:Python exception.BotoServerError方法的具體用法?Python exception.BotoServerError怎麽用?Python exception.BotoServerError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在boto.exception的用法示例。


在下文中一共展示了exception.BotoServerError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _mws_send

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def _mws_send(self, mws_send, syncs, sync_values):
        log_template = "about to call MWS send() for product syncs."
        _logger.debug(log_template.format(len(sync_values)))

        try:
            results = mws_send(sync_values)
            sync_result = self._convert_results(results)
            ProductSyncAccess.update_sync_status(syncs, sync_result)
        except BotoServerError as boto_ex:
            _logger.debug("MWS Request error: {}".format(
                boto_ex.error_code))
            if boto_ex.error_code in ["RequestThrottled",
                                      "ServiceUnavailable"]:
                _logger.debug("Continue with throttled or unavailable error.")
            else:
                ProductSyncAccess.update_sync_new_exception(syncs, boto_ex)
        except Exception as ex:
            # we may want to re-try for recoverable exceptions
            # for now, just report error
            _logger.exception("mws send() threw exception.")
            ProductSyncAccess.update_sync_new_exception(syncs, ex) 
開發者ID:amdeb,項目名稱:amdeb-amazon,代碼行數:23,代碼來源:product_sync_new.py

示例2: get_messages_from_queue

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def get_messages_from_queue(self):
        """ Fetches messages from the sqs queue of name passed in during this
        object's construction.
        Does not handle exceptions from Boto.

        :rtype: a list of SQS message or None
        """
        try:
            msgs = self._queue.get_messages(
                num_messages=self._num_messages_to_fetch,
                wait_time_seconds=self._wait_time_secs)
            return msgs
        except (BotoClientError, BotoServerError):
            log_exception(
                "Boto exception in fetching messages from SQS, for queue name:"
                + self._queue.id)
            raise 
開發者ID:Yelp,項目名稱:mycroft,代碼行數:19,代碼來源:sqs_wrapper.py

示例3: throttling_retry

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def throttling_retry(func):
    """Retry when AWS is throttling API calls"""

    def retry_call(*args, **kwargs):
        retries = 0
        while True:
            try:
                retval = func(*args)
                return retval
            except BotoServerError as err:
                if (err.code == 'Throttling' or err.code == 'RequestLimitExceeded') and retries <= 3:
                    sleep = 3 * (2 ** retries)
                    print('Being throttled. Retrying after {} seconds..'.format(sleep))
                    time.sleep(sleep)
                    retries += 1
                else:
                    raise err

    return retry_call 
開發者ID:cfstacks,項目名稱:stacks,代碼行數:21,代碼來源:aws.py

示例4: stack_resources

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def stack_resources(conn, stack_name, logical_resource_id=None):
    """List stack resources"""
    try:
        result = conn.describe_stack_resources(stack_name_or_id=stack_name,
                                               logical_resource_id=logical_resource_id)
    except BotoServerError as err:
        print(err.message)
        sys.exit(1)
    resources = []
    if logical_resource_id:
        resources.append([r.physical_resource_id for r in result])
    else:
        for r in result:
            columns = [
                r.logical_resource_id,
                r.physical_resource_id,
                r.resource_type,
                r.resource_status,
            ]
            resources.append(columns)

    if len(result) >= 1:
        return tabulate(resources, tablefmt='plain')
    return None 
開發者ID:cfstacks,項目名稱:stacks,代碼行數:26,代碼來源:cf.py

示例5: stack_outputs

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def stack_outputs(conn, stack_name, output_name):
    """List stacks outputs"""
    try:
        result = conn.describe_stacks(stack_name)
    except BotoServerError as err:
        print(err.message)
        sys.exit(1)

    outputs = []
    outs = [s.outputs for s in result][0]
    for o in outs:
        if not output_name:
            columns = [o.key, o.value]
            outputs.append(columns)
        elif output_name and o.key == output_name:
            outputs.append([o.value])

    if len(result) >= 1:
        return tabulate(outputs, tablefmt='plain')
    return None 
開發者ID:cfstacks,項目名稱:stacks,代碼行數:22,代碼來源:cf.py

示例6: delete_stack

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def delete_stack(conn, stack_name, region, profile, confirm):
    """Deletes stack given its name"""
    msg = ('You are about to delete the following stack:\n'
           'Name: {}\n'
           'Region: {}\n'
           'Profile: {}\n').format(stack_name, region, profile)
    if not confirm:
        print(msg)
        response = input('Are you sure? [y/N] ')
    else:
        response = 'yes'

    if response in YES:
        try:
            conn.delete_stack(stack_name)
        except BotoServerError as err:
            if 'does not exist' in err.message:
                print(err.message)
                sys.exit(0)
            else:
                print(err.message)
                sys.exit(1)
    else:
        sys.exit(0) 
開發者ID:cfstacks,項目名稱:stacks,代碼行數:26,代碼來源:cf.py

示例7: setup_iam_ec2_role

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def setup_iam_ec2_role(self, role_name, policies):
        aws_role_name = self.to_aws_name(role_name)
        try:
            self.iam.create_role(aws_role_name, assume_role_policy_document=json.dumps({
                "Version": "2012-10-17",
                "Statement": [{
                    "Effect": "Allow",
                    "Principal": {"Service": ["ec2.amazonaws.com"]},
                    "Action": ["sts:AssumeRole"]}
                ]}))
        except BotoServerError as e:
            if e.status == 409 and e.error_code == 'EntityAlreadyExists':
                pass
            else:
                raise

        self.__setup_entity_policies(aws_role_name, policies,
                                     list_policies=self.iam.list_role_policies,
                                     delete_policy=self.iam.delete_role_policy,
                                     get_policy=self.iam.get_role_policy,
                                     put_policy=self.iam.put_role_policy)

        return aws_role_name 
開發者ID:DataBiosphere,項目名稱:toil,代碼行數:25,代碼來源:context.py

示例8: create_cf_stack

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def create_cf_stack(cf_conn, stack_name, cf_template_path, availability_zone):
    try:
        if len(cf_conn.describe_stacks(stack_name)) > 0:
            print "Stack '{n}' already exists. Reusing.".format(n=stack_name)
            return
    except BotoServerError:
        # stack does not exist
        pass

    print "Creating stack with name '{n}'.".format(n=stack_name)
    with open(cf_template_path, 'r') as template_file:
        template_body = template_file.read()
    cf_conn.create_stack(stack_name, template_body=template_body,
                         parameters=[('KeyPairName', get_ec2_key_pair()),
                                     ('AZ', availability_zone)],
                         tags={'owner': getuser(),
                               'ec2_key_pair': get_ec2_key_pair()})
    wait_for_stack_status(cf_conn, stack_name, 'CREATE_COMPLETE') 
開發者ID:bigdatagenomics,項目名稱:eggo,代碼行數:20,代碼來源:aws.py

示例9: create_session

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def create_session():
    metadata = request.app.config.meta_get('metadata', 'obj')
    token = _get_value(request, 'token')
    profile = _get_value(request, 'profile')

    if not token and not profile:
        response.status = 400
        return {
            'error': {
                'message': 'token and/or profile is required'
            }
        }

    if profile:
        metadata.profile_name = profile

    if token:
        try:
            request.app.config.meta_get('metadata', 'obj').get_session(token)
        except BotoServerError as e:
            response.status = e.status
            return {'error': {'message': e.message}}

    return get_session() 
開發者ID:dump247,項目名稱:aws-mock-metadata,代碼行數:26,代碼來源:routes.py

示例10: main

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def main():
    if len(sys.argv) > 2:
        printUsage()
        raise SystemExit(1)

    try:
        section = sys.argv[1]
    except IndexError:
        section = 'default'

    credentials = CredentialsFile(section)

    iam = IAMConnection(
        aws_access_key_id=credentials.keyId,
        aws_secret_access_key=credentials.secretKey,
    )

    userName = getUserName(iam)
    deleteOldKeys(iam, credentials.keyId, userName)
    newKey = makeNewKey(iam, userName)

    iam = IAMConnection(
        aws_access_key_id=newKey['access_key_id'],
        aws_secret_access_key=newKey['secret_access_key'],
    )

    oldKey = credentials.keyId
    try:
        deactivateKey(iam, oldKey, userName)
    except BotoServerError as e:
        print(e)
        raise SystemExit(dedent('''
        Failed to deactivate the old key (%s) after one minute of
        retrying. Manual remediation will be required.
        %s
        ''' % (oldKey, ACCESS_KEY_DOCS)).strip())

    credentials.updateCredentials(
        newKey['access_key_id'],
        newKey['secret_access_key'],
    ) 
開發者ID:makethunder,項目名稱:awsudo,代碼行數:43,代碼來源:rotate.py

示例11: get_messages

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def get_messages(self, num_messages, wait_time_seconds):
        if self.exception:
            raise BotoServerError(503, "test")
        return [] if self.msgs is None else self.msgs 
開發者ID:Yelp,項目名稱:mycroft,代碼行數:6,代碼來源:test_sqs_wrapper.py

示例12: test_get_messages_exception_thrown_out

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def test_get_messages_exception_thrown_out(get_mock_boto):
    fake_conn = FakeConn()
    fake_queue = FakeQueue()
    fake_conn.set_queue(fake_queue)
    fake_queue.exception = True  # set it to throw boto error
    mock_obj = get_mock_boto
    mock_obj.return_value = fake_conn
    sqs = SQSWrapper("some-queue", None)
    with pytest.raises(BotoServerError):
        sqs.get_messages_from_queue()
    mock_obj.assert_called_once_with('us-west-2', **get_test_creds()) 
開發者ID:Yelp,項目名稱:mycroft,代碼行數:13,代碼來源:test_sqs_wrapper.py

示例13: _does_stack_exist

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def _does_stack_exist(self, conn):
        try:
            if len(conn.describe_stacks(stack_name_or_id=self._stack_name)) > 0:
                return True
        except BotoServerError:
            # Describing will raise a server error if the stack doesn't exist
            pass
        return False 
開發者ID:Yelp,項目名稱:mycroft,代碼行數:10,代碼來源:create_mycroft.py

示例14: get_stack_template

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def get_stack_template(conn, stack_name):
    """Return a template body of live stack"""
    try:
        template = conn.get_template(stack_name)
        return template['GetTemplateResponse']['GetTemplateResult']['TemplateBody'], []
    except BotoServerError as e:
        return None, [e.message] 
開發者ID:cfstacks,項目名稱:stacks,代碼行數:9,代碼來源:aws.py

示例15: __new__

# 需要導入模塊: from boto import exception [as 別名]
# 或者: from boto.exception import BotoServerError [as 別名]
def __new__(cls, *args, **kw):
        error = BotoServerError(*args, **kw)
        newclass = globals().get(error.error_code, ResponseError)
        obj = newclass.__new__(newclass, *args, **kw)
        obj.__dict__.update(error.__dict__)
        return obj 
開發者ID:VirtueSecurity,項目名稱:aws-extender,代碼行數:8,代碼來源:exception.py


注:本文中的boto.exception.BotoServerError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。