本文整理汇总了Python中cfn_sphere.aws.cfn.CloudFormation.stack_exists方法的典型用法代码示例。如果您正苦于以下问题:Python CloudFormation.stack_exists方法的具体用法?Python CloudFormation.stack_exists怎么用?Python CloudFormation.stack_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfn_sphere.aws.cfn.CloudFormation
的用法示例。
在下文中一共展示了CloudFormation.stack_exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParameterResolver
# 需要导入模块: from cfn_sphere.aws.cfn import CloudFormation [as 别名]
# 或者: from cfn_sphere.aws.cfn.CloudFormation import stack_exists [as 别名]
class ParameterResolver(object):
"""
Resolves a given artifact identifier to the value of a stacks output.
"""
def __init__(self, region="eu-west-1"):
self.logger = get_logger()
self.cfn = CloudFormation(region)
self.ec2 = Ec2Api(region)
self.kms = KMS(region)
@staticmethod
def convert_list_to_string(value):
if not value:
return ""
value_string = ""
for item in value:
if value_string:
value_string += ','
value_string += str(item)
return value_string
def get_output_value(self, stack_outputs, stack, output_key):
"""
Get value for a specific output key in format <stack-name>.<output>.
:param output_key: str <stack-name>.<output>
:return: str
"""
self.logger.debug("Looking up output {0} from stack {1}".format(output_key, stack))
try:
artifact = stack_outputs[stack][output_key]
return artifact
except KeyError:
raise CfnSphereException("Could not get a valid value for {0}.".format(output_key))
@staticmethod
def is_keep_value(value):
return value.lower().startswith('|keeporuse|')
@staticmethod
def is_taupage_ami_reference(value):
return value.lower() == '|latesttaupageami|'
@staticmethod
def is_kms(value):
return value.lower().startswith('|kms|')
@staticmethod
def get_default_from_keep_value(value):
return value.split('|', 2)[2]
@staticmethod
def is_file(value):
return value.lower().startswith('|file|')
def get_latest_value(self, key, value, stack_name):
try:
if self.cfn.stack_exists(stack_name):
latest_stack_parameters = self.cfn.get_stack_parameters_dict(stack_name)
latest_value = latest_stack_parameters.get(key, None)
if latest_value:
self.logger.info("Will keep '{0}' as latest value for {1}".format(latest_value, key))
return latest_value
else:
return self.get_default_from_keep_value(value)
else:
return self.get_default_from_keep_value(value)
except Exception as e:
raise CfnSphereException("Could not get latest value for {0}: {1}".format(key, e))
def resolve_parameter_values(self, stack_name, stack_config):
resolved_parameters = {}
stack_outputs = self.cfn.get_stacks_outputs()
for key, value in stack_config.parameters.items():
if isinstance(value, list):
self.logger.debug("List parameter found for {0}".format(key))
for i, item in enumerate(value):
if DependencyResolver.is_parameter_reference(item):
referenced_stack, output_name = DependencyResolver.parse_stack_reference_value(item)
value[i] = str(self.get_output_value(stack_outputs, referenced_stack, output_name))
value_string = self.convert_list_to_string(value)
resolved_parameters[key] = value_string
elif isinstance(value, str):
if DependencyResolver.is_parameter_reference(value):
referenced_stack, output_name = DependencyResolver.parse_stack_reference_value(value)
resolved_parameters[key] = str(self.get_output_value(stack_outputs, referenced_stack, output_name))
elif self.is_keep_value(value):
resolved_parameters[key] = str(self.get_latest_value(key, value, stack_name))
elif self.is_taupage_ami_reference(value):
resolved_parameters[key] = str(self.ec2.get_latest_taupage_image_id())
#.........这里部分代码省略.........
示例2: ParameterResolver
# 需要导入模块: from cfn_sphere.aws.cfn import CloudFormation [as 别名]
# 或者: from cfn_sphere.aws.cfn.CloudFormation import stack_exists [as 别名]
class ParameterResolver(object):
"""
Resolves a given artifact identifier to the value of a stacks output.
"""
def __init__(self, region="eu-west-1"):
self.logger = get_logger()
self.cfn = CloudFormation(region)
self.ec2 = Ec2Api(region)
self.kms = KMS(region)
@staticmethod
def convert_list_to_string(value):
if not value:
return ""
value_string = ""
for item in value:
if value_string:
value_string += ","
value_string += str(item)
return value_string
def get_stack_outputs(self):
"""
Get a list of all available stack outputs in format <stack-name>.<output>.
:return: dict
"""
artifacts = {}
stacks = self.cfn.get_stacks()
for stack in stacks:
for output in stack.outputs:
key = stack.stack_name + "." + output.key
artifacts[key] = output.value
return artifacts
def get_output_value(self, key):
"""
Get value for a specific output key in format <stack-name>.<output>.
:param key: str <stack-name>.<output>
:return: str
"""
artifacts = self.get_stack_outputs()
self.logger.debug("Looking up key: {0}".format(key))
self.logger.debug("Found artifacts: {0}".format(artifacts))
try:
artifact = artifacts[key]
return artifact
except KeyError:
raise CfnSphereException("Could not get a valid value for {0}.".format(key))
@staticmethod
def is_keep_value(value):
return value.lower().startswith("|keeporuse|")
@staticmethod
def is_taupage_ami_reference(value):
return value.lower() == "|latesttaupageami|"
@staticmethod
def is_kms(value):
return value.lower().startswith("|kms|")
@staticmethod
def get_default_from_keep_value(value):
return value.split("|", 2)[2]
def get_latest_value(self, key, value, stack_name):
try:
if self.cfn.stack_exists(stack_name):
latest_stack_parameters = self.cfn.get_stack_parameters_dict(stack_name)
latest_value = latest_stack_parameters.get(key, None)
if latest_value:
self.logger.info("Will keep '{0}' as latest value for {1}".format(latest_value, key))
return latest_value
else:
return self.get_default_from_keep_value(value)
else:
return self.get_default_from_keep_value(value)
except CfnSphereBotoError as e:
raise CfnSphereException("Could not get latest value for {0}: {1}".format(key, e))
def resolve_parameter_values(self, parameters_dict, stack_name):
parameters = {}
for key, value in parameters_dict.items():
if isinstance(value, list):
self.logger.debug("List parameter found for {0}".format(key))
value_string = self.convert_list_to_string(value)
parameters[key] = value_string
elif isinstance(value, str):
if DependencyResolver.is_parameter_reference(value):
referenced_stack, output_name = DependencyResolver.parse_stack_reference_value(value)
parameters[key] = str(self.get_output_value(referenced_stack + "." + output_name))
elif self.is_keep_value(value):
#.........这里部分代码省略.........