当前位置: 首页>>代码示例>>Python>>正文


Python errorfactory.ClientError方法代码示例

本文整理汇总了Python中botocore.errorfactory.ClientError方法的典型用法代码示例。如果您正苦于以下问题:Python errorfactory.ClientError方法的具体用法?Python errorfactory.ClientError怎么用?Python errorfactory.ClientError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在botocore.errorfactory的用法示例。


在下文中一共展示了errorfactory.ClientError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Calls the describe rule boto call and returns the

        Returns:
            current definition
        """
        try:
            current_definition = self.client.describe_rule(Name=self.rule_name)
        except ClientError as e:
            if e.response['Error']['Code'] == 'ResourceNotFoundException':
                logger.info("Rule {} was not found. State is terminated".format(self.rule_name))
                return {"status": "missing"}
            else:
                raise e
        return current_definition 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:18,代码来源:cloudwatch_event.py

示例2: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Calls the get function configuration boto call and returns status missing if the function does not exist.
        Otherwise will return the current definition.

        Returns:
            current definition
        """
        try:
            current_definition = self.client.get_function_configuration(FunctionName=self.function_name)
        except ClientError as e:
            if e.response['Error']['Code'] == 'ResourceNotFoundException':
                logger.info("Function {} was not found. State is terminated".format(self.function_name))
                return {"status": "missing"}
            else:
                raise e

        return current_definition 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:20,代码来源:lambda_function.py

示例3: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Get the current status of your load balancer. Calls boto3 describe_load_balancers using LoadBalancerNames

        Returns:
            dict with the load balancer that matches the LoadBalancerName provided
        """

        try:
            elb_status = self.client.describe_load_balancers(LoadBalancerNames=[self.elb_name])
        except ClientError as e:
            error_code = e.response.get('ResponseMetadata', {}).get('HTTPStatusCode')
            if error_code == 404 or error_code == 400:
                return {}
            else:
                raise e
        else:
            return elb_status['LoadBalancerDescriptions'][0] 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:20,代码来源:elb.py

示例4: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Get the current status of your load balancer. Calls boto3 describe_load_balancers using Names

        Returns:
            dict with the load balancer that matches the Name provided
        """

        try:
            alb_status = self.client.describe_load_balancers(Names=[self.alb_name])
        except ClientError as e:
            error_code = e.response.get('ResponseMetadata', {}).get('HTTPStatusCode')
            if error_code == 404 or error_code == 400:
                return {}
            else:
                raise e
        else:
            return alb_status['LoadBalancers'][0] 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:20,代码来源:alb.py

示例5: get_listener_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_listener_status(self):
        """
        Get the current status of your load balancer's listener(s). Calls boto3 describe_listeners using LoadBalancerArn

        Returns:
            dict with the load balancer's listeners that matches the LoadBalancerArn provided
        """

        try:
            alb_listener_status = self.client.describe_listeners(LoadBalancerArn=self.arn)
        except ClientError as e:
            error_code = e.response.get('ResponseMetadata', {}).get('HTTPStatusCode')
            if error_code == 404 or error_code == 400:
                return {}
            else:
                raise e
        else:
            return alb_listener_status['Listeners'] 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:20,代码来源:alb.py

示例6: _start

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def _start(self):
        """
        Creates the IAM Role

        Returns:
             response of boto3 create_role
        """

        create_definition = pcf_util.param_filter(self.get_desired_state_definition(), IAMRole.START_PARAMS_FILTER)
        
        try:
            self.client.create_role(**create_definition)
        except ClientError as e:
            raise e

        if self.custom_config.get('IsInstanceProfile', False):
            try:
                self.client.create_instance_profile(InstanceProfileName=self.role_name)
            except ClientError as e:
                logger.info(e)

            try:
                self.client.add_role_to_instance_profile(InstanceProfileName=self.role_name, RoleName=self.role_name)
            except ClientError as e:
                logger.info(e) 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:27,代码来源:iam_role.py

示例7: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Determines if the IAM Policy exists
        Returns:
             status (dict)
        """

        try:
            policy_status = self.client.list_policies(Scope="Local")
        except ClientError as e:
            if e.response['Error']['Code'] == 'PolicyNotFoundException':
                logger.warning("Policy {} was not found. Defaulting state for {} to terminated".format(self.policy_name, self.policy_name))
                return {"status": "missing"}
            else:
                raise e

        policy = [x for x in policy_status.get('Policies') if x.get("PolicyName") == self.policy_name]

        if policy:
            if policy[0].get('Arn'):
                self.policy_arn = policy[0].get('Arn')
            return {"status":"active"}
        else:
            return {"status": "missing"} 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:26,代码来源:iam_policy.py

示例8: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Get the current status of your rds instance.

        :return: status of rds instance.
        """
        try:
            rds_statuses = self.client.describe_db_instances(DBInstanceIdentifier=self.db_instance_identifier)['DBInstances']
        except ClientError as e:
            error_code = e.response.get('ResponseMetadata', {}).get('HTTPStatusCode')

            if error_code == 404 or error_code == 400:
                return {"DBInstanceStatus":"missing"}
            else:
                raise e
        else:
            return rds_statuses[0] 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:19,代码来源:rds_instance.py

示例9: get_status

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def get_status(self):
        """
        Calls the describe table boto call and returns status missing if the function does not exist.
        Otherwise will return the current definition

        Returns:
            current definition
        """
        try:
            current_definition = self.client.describe_table(TableName=self.table_name)["Table"]

        except ClientError as e:
            if e.response['Error']['Code'] == 'ResourceNotFoundException':
                logger.info("Table {} was not found. State is terminated".format(self.table_name))
                return {"status": "missing"}
            else:
                raise e

        return current_definition 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:21,代码来源:dynamodb_table.py

示例10: _terminate

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def _terminate(self):
        """
        Deletes the cloudformation stack using its name

        Returns:
            boto3 response
        """
        #Cannot termiante during these inprogress status: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudformation/model/StackStatus.html
        try:
            response = self.client.delete_stack(StackName=self.stack_name)
        except ClientError as e:
            if 'IN_PROGRESS' in e.response['Error']['Message']:
                logger.info(f"Cannot terminate stack {self.stack_name} while update in progress")
                return
            raise e

        return response 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:19,代码来源:cloudformation_stack.py

示例11: _update

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def _update(self):
        """
        Update cloudformation stack based on the new configuration provided
        """

        #Cannot update during these inprogress status: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cloudformation/model/StackStatus.html
        try:
            update_definition = pcf_util.param_filter(self.desired_state_definition, CloudFormationStack.PARAM_FILTER)
            response = self.client.update_stack(**update_definition)
        except ClientError as e:
            if 'IN_PROGRESS' in e.response['Error']['Message']:
                logger.info(f"Cannot update stack {self.stack_name} while creation or deletion in progress")
                return
            raise e

        return response 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:18,代码来源:cloudformation_stack.py

示例12: is_dir

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def is_dir(self):
        if not self.bucket:
            return False

        if not self.key:
            # key empty, return whether bucket exists
            try:
                self._client.head_bucket(Bucket=self.bucket)
                return True
            except ClientError as e:
                if e.response["Error"]["Code"] == "404":
                    return False

        prefix = self.key
        if prefix[-1] != "/":
            prefix = prefix + "/"
        resp = self._client.list_objects(
            Bucket=self.bucket, Delimiter="/", Prefix=prefix
        )
        return "CommonPrefixes" in resp or "Contents" in resp 
开发者ID:poodarchu,项目名称:Det3D,代码行数:22,代码来源:oss.py

示例13: _bucket_exists

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def _bucket_exists(self):
        from botocore.errorfactory import ClientError

        try:
            self.s3.meta.client.head_bucket(Bucket=self.bucket)
        except ClientError as er:
            if er.response["Error"]["Code"] == "404":
                return False
        return True 
开发者ID:IDSIA,项目名称:sacred,代码行数:11,代码来源:s3_observer.py

示例14: _terminate

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def _terminate(self):
        """
        Deletes the IAM Role

        Returns:
             response of boto3 delete_role
        """

        # All policy versions must be deleted before default policy can be deleted. 
        attached_policies = self.client.list_attached_role_policies(RoleName=self.role_name, PathPrefix=self.desired_state_definition.get('Path', '/'))

        if attached_policies:
            for policy in attached_policies.get('AttachedPolicies'):
                self.client.detach_role_policy(RoleName=self.role_name, PolicyArn=policy.get('PolicyArn'))

        if self.custom_config.get('IsInstanceProfile'):
            try:
                self.client.remove_role_from_instance_profile(InstanceProfileName=self.role_name, RoleName=self.role_name)
            except ClientError as e:
                logger.info(e)

            try:
                self.client.delete_instance_profile(InstanceProfileName=self.role_name)
            except ClientError as e:
                logger.info(e)

        try:
            self.client.delete_role(RoleName=self.role_name)
        except ClientError as e:
            raise e 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:32,代码来源:iam_role.py

示例15: is_state_definition_equivalent

# 需要导入模块: from botocore import errorfactory [as 别名]
# 或者: from botocore.errorfactory import ClientError [as 别名]
def is_state_definition_equivalent(self):
        """
        Compared the desired state and current state definition

        Returns:
            bool
        """

        self.current_state_definition = pcf_util.param_filter(self.current_state_definition, IAMRole.START_PARAMS_FILTER)
        self.current_state_definition['custom_config'] = {}
        self.get_iam_policies()
        diff_dict = {}

        if self.desired_state != State.terminated:
            #Comparing currently attached policies to desired policies
            try:
                attached_policy_arns = self.client.list_attached_role_policies(RoleName=self.role_name, PathPrefix=self.desired_state_definition.get('Path', '/'))
            except ClientError as e:
                #No attached policies
                attached_policy_arns = {}

            if attached_policy_arns.get('AttachedPolicies'):
                current_policy_arns = [p.get('PolicyArn') for p in attached_policy_arns.get('AttachedPolicies')]
                self.current_state_definition['custom_config']['policy_arns'] = current_policy_arns
            else:
                self.current_state_definition['custom_config']['policy_arns'] = []

            if isinstance(self.desired_state_definition.get('AssumeRolePolicyDocument'), str):    
                self.desired_state_definition['AssumeRolePolicyDocument'] = json.loads(self.desired_state_definition.get('AssumeRolePolicyDocument'))
            self.current_state_definition['custom_config']['IsInstanceProfile'] = self.custom_config.get('IsInstanceProfile', False)
            diff_dict = pcf_util.diff_dict(self.current_state_definition, self.desired_state_definition)

        return diff_dict == {} 
开发者ID:capitalone,项目名称:Particle-Cloud-Framework,代码行数:35,代码来源:iam_role.py


注:本文中的botocore.errorfactory.ClientError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。