本文整理汇总了Python中cfn_sphere.aws.cfn.CloudFormation.get_stacks方法的典型用法代码示例。如果您正苦于以下问题:Python CloudFormation.get_stacks方法的具体用法?Python CloudFormation.get_stacks怎么用?Python CloudFormation.get_stacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfn_sphere.aws.cfn.CloudFormation
的用法示例。
在下文中一共展示了CloudFormation.get_stacks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_stacks_correctly_calls_aws_api
# 需要导入模块: from cfn_sphere.aws.cfn import CloudFormation [as 别名]
# 或者: from cfn_sphere.aws.cfn.CloudFormation import get_stacks [as 别名]
def test_get_stacks_correctly_calls_aws_api(self, cloudformation_mock):
stacks = [Mock(spec=Stack), Mock(spec=Stack)]
result = ResultSet()
result.extend(stacks)
result.next_token = None
cloudformation_mock.connect_to_region.return_value.describe_stacks.return_value = result
cfn = CloudFormation()
self.assertListEqual(stacks, cfn.get_stacks())
示例2: test_get_stacks_correctly_aggregates_paged_results
# 需要导入模块: from cfn_sphere.aws.cfn import CloudFormation [as 别名]
# 或者: from cfn_sphere.aws.cfn.CloudFormation import get_stacks [as 别名]
def test_get_stacks_correctly_aggregates_paged_results(self, cloudformation_mock):
stacks_1 = [Mock(spec=Stack), Mock(spec=Stack)]
stacks_2 = [Mock(spec=Stack), Mock(spec=Stack)]
result_1 = ResultSet()
result_1.extend(stacks_1)
result_1.next_token = "my-next-token"
result_2 = ResultSet()
result_2.extend(stacks_2)
result_2.next_token = None
cloudformation_mock.connect_to_region.return_value.describe_stacks.side_effect = [result_1, result_2]
cfn = CloudFormation()
self.assertListEqual(stacks_1 + stacks_2, cfn.get_stacks())
示例3: ParameterResolver
# 需要导入模块: from cfn_sphere.aws.cfn import CloudFormation [as 别名]
# 或者: from cfn_sphere.aws.cfn.CloudFormation import get_stacks [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))
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(referenced_stack + '.' + output_name))
value_string = self.convert_list_to_string(value)
parameters[key] = value_string
elif isinstance(value, str):
#.........这里部分代码省略.........