本文整理汇总了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
示例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
示例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]
示例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]
示例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']
示例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)
示例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"}
示例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]
示例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
示例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
示例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
示例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
示例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
示例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
示例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 == {}