本文整理汇总了Python中cfn_sphere.file_loader.FileLoader.get_cloudformation_template方法的典型用法代码示例。如果您正苦于以下问题:Python FileLoader.get_cloudformation_template方法的具体用法?Python FileLoader.get_cloudformation_template怎么用?Python FileLoader.get_cloudformation_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfn_sphere.file_loader.FileLoader
的用法示例。
在下文中一共展示了FileLoader.get_cloudformation_template方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_cfn_to_s3
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def upload_cfn_to_s3(project, logger):
"""
This task is separate since they only work with Python2 >2.6 by
the time being. Python3 support is underway.
This means, when using Python<2.7, this task is not visible
(see __init__.py).
"""
from cfn_sphere.file_loader import FileLoader
from cfn_sphere.template.transformer import CloudFormationTemplateTransformer
for path, filename in project.get_property('template_files'):
template = FileLoader.get_cloudformation_template(filename, path)
transformed = CloudFormationTemplateTransformer.transform_template(
template)
output = transformed.get_template_json()
bucket_name = project.get_property('bucket_name')
key_prefix = project.get_property('template_key_prefix')
filename = filename.replace('.yml', '.json')
filename = filename.replace('.yaml', '.json')
version_path = '{0}v{1}/{2}'.format(
key_prefix, project.version, filename)
# latest_path = '{0}latest/{1}'.format(key_prefix, filename)
acl = project.get_property('template_file_access_control')
check_acl_parameter_validity('template_file_access_control', acl)
upload_helper(logger, bucket_name, version_path, output, acl)
示例2: render_template
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def render_template(template_file, confirm, yes):
confirm = confirm or yes
if not confirm:
check_update_available()
loader = FileLoader()
template = loader.get_cloudformation_template(template_file, None)
template = CloudFormationTemplateTransformer.transform_template(template)
click.echo(template.get_pretty_template_json())
示例3: test_get_cloudformation_template_returns_template
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def test_get_cloudformation_template_returns_template(self, get_yaml_or_json_file_mock):
expected = {
'Conditions': {},
'Mappings': {},
'Resources': 'Foo',
'Parameters': {},
'Outputs': {},
'AWSTemplateFormatVersion': '2010-09-09',
'Description': ''
}
get_yaml_or_json_file_mock.return_value = {"Resources": "Foo"}
response = FileLoader.get_cloudformation_template("s3://my-bucket/template.yml", None)
self.assertEqual(expected, response.get_template_body_dict())
get_yaml_or_json_file_mock.assert_called_once_with('s3://my-bucket/template.yml', None)
示例4: create_or_update_stacks
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def create_or_update_stacks(self):
existing_stacks = self.cfn.get_stack_names()
desired_stacks = self.config.stacks
stack_processing_order = DependencyResolver().get_stack_order(desired_stacks)
if len(stack_processing_order) > 1:
self.logger.info(
"Will process stacks in the following order: {0}".format(", ".join(stack_processing_order)))
for stack_name in stack_processing_order:
stack_config = self.config.stacks.get(stack_name)
template = FileLoader.get_cloudformation_template(stack_config.template_url,stack_config.working_dir)
transformed_template = CloudFormationTemplateTransformer.transform_template(template)
if stack_config.stack_policy_url:
self.logger.info("Using stack policy from {0}".format(stack_config.stack_policy_url))
stack_policy = FileLoader.get_yaml_or_json_file(stack_config.stack_policy_url, stack_config.working_dir)
else:
stack_policy = None
parameters = self.parameter_resolver.resolve_parameter_values(stack_name, stack_config)
merged_parameters = self.parameter_resolver.update_parameters_with_cli_parameters(
parameters=parameters,
cli_parameters=self.cli_parameters,
stack_name=stack_name)
self.logger.debug("Parameters after merging with cli options: {0}".format(merged_parameters))
stack = CloudFormationStack(template=transformed_template,
parameters=merged_parameters,
tags=stack_config.tags,
name=stack_name,
region=self.config.region,
timeout=stack_config.timeout,
service_role=stack_config.service_role,
stack_policy=stack_policy)
if stack_name in existing_stacks:
self.cfn.validate_stack_is_ready_for_action(stack)
self.cfn.update_stack(stack)
else:
self.cfn.create_stack(stack)
CustomResourceHandler.process_post_resources(stack)
示例5: validate_template
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def validate_template(template_file, confirm, yes):
confirm = confirm or yes
if not confirm:
check_update_available()
try:
loader = FileLoader()
template = loader.get_cloudformation_template(template_file, None)
template = CloudFormationTemplateTransformer.transform_template(template)
CloudFormation().validate_template(template)
click.echo("Template is valid")
except CfnSphereException as e:
LOGGER.error(e)
sys.exit(1)
except Exception as e:
LOGGER.error("Failed with unexpected error")
LOGGER.exception(e)
LOGGER.info("Please report at https://github.com/cfn-sphere/cfn-sphere/issues!")
sys.exit(1)
示例6: test_get_cloudformation_template_raises_exception_on_any_error
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def test_get_cloudformation_template_raises_exception_on_any_error(self, get_yaml_or_json_file_mock):
get_yaml_or_json_file_mock.side_effect = Exception
with self.assertRaises(TemplateErrorException):
FileLoader.get_cloudformation_template("s3://my-bucket/template.yml", None)
示例7: get_template
# 需要导入模块: from cfn_sphere.file_loader import FileLoader [as 别名]
# 或者: from cfn_sphere.file_loader.FileLoader import get_cloudformation_template [as 别名]
def get_template(template_url, working_dir):
template = FileLoader.get_cloudformation_template(template_url, working_dir)
additional_stack_description = "Config repo url: {0}".format(get_git_repository_remote_url(working_dir))
return CloudFormationTemplateTransformer.transform_template(template, additional_stack_description)