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


Python troposphere.Template方法代码示例

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


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

示例1: __init__

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def __init__(self, template_name):
        """
        Init method for environmentbase.Template class
        @param template_name [string] - name of this template, used to identify this template when uploading, deploying, etc.
        """
        t.Template.__init__(self)
        self.name = template_name
        self.AWSTemplateFormatVersion = ''

        self._vpc_cidr = None
        self._vpc_id = None
        self._common_security_group = None
        self._utility_bucket = None
        self._child_templates = []
        self._child_template_references = []
        self.manual_parameter_bindings = {}

        self._subnets = {} 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:20,代码来源:template.py

示例2: construct_user_data

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def construct_user_data(env_vars={}, user_data=''):
        """
        Wrapper method to encapsulate process of constructing userdata for a launch configuration
        @param env_vars [dict] A dictionary containining key value pairs to set as environment variables in the userdata
        @param user_data [string] Contents of the user data script as a string
        Returns user_data_payload [string[]] Userdata payload ready to be dropped into a launch configuration
        """
        # At least one of env_vars or user_data must exist
        if not (env_vars or user_data):
            return []

        # If the variable value is not a string, use the Join function
        # This handles Refs, Parameters, etc. which are evaluated at runtime
        variable_declarations = []
        for k,v in env_vars.iteritems():
            if isinstance(v, basestring):
                variable_declarations.append('%s=%s' % (k, v))
            else:
                variable_declarations.append(Join('=', [k, v]))

        return Template.build_bootstrap(
            bootstrap_files=[user_data],
            variable_declarations=variable_declarations
        ) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:26,代码来源:template.py

示例3: _build_template

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def _build_template(github_owner: str, github_branch: str) -> Template:
    """Build and return the pipeline template."""
    template = Template(Description="CI/CD pipeline for Decrypt Oracle powered by the AWS Encryption SDK for Python")
    github_access_token = template.add_parameter(
        troposphere.Parameter(
            "GithubPersonalToken", Type="String", Description="Personal access token for the github repo.", NoEcho=True
        )
    )
    application_bucket = template.add_resource(s3.Bucket("ApplicationBucket"))
    artifact_bucket = template.add_resource(s3.Bucket("ArtifactBucketStore"))
    builder_role = template.add_resource(_codebuild_role())
    builder = template.add_resource(_codebuild_builder(builder_role, application_bucket))
    # add codepipeline role
    pipeline_role = template.add_resource(_pipeline_role(buckets=[application_bucket, artifact_bucket]))
    # add cloudformation deploy role
    cfn_role = template.add_resource(_cloudformation_role())
    # add codepipeline
    template.add_resource(
        _pipeline(
            pipeline_role=pipeline_role,
            cfn_role=cfn_role,
            codebuild_builder=builder,
            artifact_bucket=artifact_bucket,
            github_owner=github_owner,
            github_branch=github_branch,
            github_access_token=github_access_token,
        )
    )
    return template 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:31,代码来源:pipeline.py

示例4: _update_existing_stack

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def _update_existing_stack(cloudformation, template: Template, github_token: str) -> None:
    """Update a stack."""
    _LOGGER.info("Updating existing stack")

    # 3. update stack
    cloudformation.update_stack(
        StackName=PIPELINE_STACK_NAME,
        TemplateBody=template.to_json(),
        Parameters=[dict(ParameterKey="GithubPersonalToken", ParameterValue=github_token)],
        Capabilities=["CAPABILITY_IAM"],
    )
    _LOGGER.info("Waiting for stack update to complete...")
    waiter = cloudformation.get_waiter("stack_update_complete")
    waiter.wait(StackName=PIPELINE_STACK_NAME, WaiterConfig=WAITER_CONFIG)
    _LOGGER.info("Stack update complete!") 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:17,代码来源:pipeline.py

示例5: _deploy_new_stack

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def _deploy_new_stack(cloudformation, template: Template, github_token: str) -> None:
    """Deploy a new stack."""
    _LOGGER.info("Bootstrapping new stack")

    # 2. deploy template
    cloudformation.create_stack(
        StackName=PIPELINE_STACK_NAME,
        TemplateBody=template.to_json(),
        Parameters=[dict(ParameterKey="GithubPersonalToken", ParameterValue=github_token)],
        Capabilities=["CAPABILITY_IAM"],
    )
    _LOGGER.info("Waiting for stack to deploy...")
    waiter = cloudformation.get_waiter("stack_create_complete")
    waiter.wait(StackName=PIPELINE_STACK_NAME, WaiterConfig=WAITER_CONFIG)
    _LOGGER.info("Stack deployment complete!") 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:17,代码来源:pipeline.py

示例6: _deploy_or_update_template

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def _deploy_or_update_template(template: Template, github_token: str) -> None:
    """Update a stack, deploying a new stack if nothing exists yet."""
    cloudformation = boto3.client("cloudformation")

    if _stack_exists(cloudformation):
        return _update_existing_stack(cloudformation=cloudformation, template=template, github_token=github_token)

    return _deploy_new_stack(cloudformation=cloudformation, template=template, github_token=github_token) 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:10,代码来源:pipeline.py

示例7: build_bootstrap

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def build_bootstrap(bootstrap_files=None,
                        variable_declarations=None,
                        cleanup_commands=None,
                        prepend_line='#!/bin/bash'):
        """
        Method encapsulates process of building out the bootstrap given a set of variables and a bootstrap file to source from
        Returns base 64-wrapped, joined bootstrap to be applied to an instnace
        @param bootstrap_files [ string[] ] list of paths to the bash script(s) to read as the source for the bootstrap action to created
        @param variable_declaration [ list ] list of lines to add to the head of the file - used to inject bash variables into the script
        @param cleanup_commnds [ string[] ] list of lines to add at the end of the file - used for layer-specific details
        """
        if prepend_line != '':
            ret_val = [prepend_line]
        else:
            ret_val = []

        if variable_declarations is not None:
            for line in variable_declarations:
                ret_val.append(line)
        for file_name_or_content in bootstrap_files:
            for line in Template.get_file_contents(file_name_or_content):
                ret_val.append(line)
        if cleanup_commands is not None:
            for line in cleanup_commands:
                ret_val.append(line)
        return Base64(Join("\n", ret_val)) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:28,代码来源:template.py

示例8: process_child_template

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def process_child_template(self, child_template, merge, depends_on, output_autowire=True, propagate_outputs=True):
        """
        Add the common parameters from this template to the child template
        Execute the child template's build hook function
        Get the matching stack parameter values from this template and add the
        stack reference to this template with those stack parameters
        """

        # This merges all attributes from the two stacks together, so all this parameter binding is unnecessary
        if merge:
            self.merge(child_template)
            return

        # Add parameters from parent stack before executing build_hook
        child_template.add_common_parameters_from_parent(self)
        child_template.build_hook()
        if output_autowire:
            self.add_child_outputs_to_parameter_binding(child_template, propagate_up=propagate_outputs)

        # Match the stack parameters with parent stack parameter values and manual parameter bindings
        stack_params = self.match_stack_parameters(child_template)

        # Construct the resource path based on the prefix + name + timestamp
        child_template.resource_path = utility.get_template_s3_resource_path(
            prefix=Template.s3_path_prefix,
            template_name=child_template.name,
            include_timestamp=Template.include_timestamp)

        # Construct the template url using the bucket name and resource path
        template_s3_url = self.get_template_s3_url(child_template)

        # Create the stack resource in this template and return the reference
        return self.add_stack(
            template_name=child_template.name,
            template_url=template_s3_url,
            stack_params=stack_params,
            depends_on=depends_on) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:39,代码来源:template.py

示例9: get_template_s3_url

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def get_template_s3_url(self, child_template):
        """
        Overridable method for getting the s3 url for child templates.

        By default it uses the `TemplateBucket` Parameter and
            `child_template.resource_path` to build the URL.
        Use `utility.get_template_s3_url(Template.template_bucket_default, child_template.resource_path)`
            if you want a non-parametrized version of this URL.
        """
        return Join('', ['https://', Ref(self.template_bucket_param), '.s3.amazonaws.com/', child_template.resource_path]) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:12,代码来源:template.py

示例10: test_tropo_to_string

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def test_tropo_to_string(self):
        utility.tropo_to_string(tropo.Template())
        utility.tropo_to_string(tropo.Base64('efsdfsdf'))
        utility.tropo_to_string(tropo.Output('efsdfsdf', Value='dsfsdfs'))
        utility.tropo_to_string(tropo.Parameter('efsdfsdf', Type='dsfsdfs'))

        # These constructors recursively call themselves for some reason
        # Don't instantiate directly
        # utility.tropo_to_string(tropo.AWSProperty())
        # utility.tropo_to_string(tropo.AWSAttribute())

        utility.tropo_to_string(ec2.Instance(
            "ec2instance",
            InstanceType="m3.medium",
            ImageId="ami-951945d0")) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:17,代码来源:test_template.py

示例11: test_build_bootstrap

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def test_build_bootstrap(self):
        file1_name = 'arbitrary_file.txt'
        file1_content = 'line1\nline2\nline3'
        self._create_local_file(file1_name, file1_content)

        # Basic test
        template_snippet = template.Template.build_bootstrap([file1_name], prepend_line='')
        generated_json = yaml.load(utility.tropo_to_string(template_snippet))
        expected_json_1 = {"Fn::Base64": {"Fn::Join": ["\n", ["line1", "line2", "line3"]]}}
        self.assertEqual(generated_json, expected_json_1)

        # Advanced test

        # resources can't be accessed as files directly
        # lines starting with #~ are removed automatically
        file2_content = '#~this_line_should_be_stripped_out\nline4\nline5\nline6'

        # you can provided multiple files or content (mix and match) in the specified order
        # you can set the shabang to whatever you want
        # you can reference variables in the file content and set there values using variable_declarations
        # finally to can do any append cleanup commands to the bottom of the file with cleanup_commands
        template_snippet = template.Template.build_bootstrap(
            [file1_name, file2_content],
            prepend_line='#!/bin/fakesh',
            variable_declarations=['var_dec_line_1', 'var_dec_line_2'],
            cleanup_commands=['cleanup_line_1', 'cleanup_line_2'])

        generated_json = yaml.load(utility.tropo_to_string(template_snippet))
        expected_json_2 = {
            "Fn::Base64": {"Fn::Join": [
                "\n", [
                    "#!/bin/fakesh",
                    'var_dec_line_1', 'var_dec_line_2',
                    "line1", "line2", "line3",
                    "line4", "line5", "line6",
                    'cleanup_line_1', 'cleanup_line_2'
                ]
            ]}}

        self.assertEqual(generated_json, expected_json_2) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:42,代码来源:test_template.py

示例12: create_template

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def create_template():
    template = Template(
        Description='DNS Validated ACM Certificate Example'
    )
    template.set_version()

    certificate = template.add_resource(certificatemanager.Certificate(
        'ExampleCertificate',
        ValidationMethod='DNS',
        DomainName='test.example.com',
        DomainValidationOptions=[
            certificatemanager.DomainValidationOption(
                DomainName='test.example.com',
                HostedZoneId='Z2KZ5YTUFZNC7H'
            )
        ],
        Tags=[{
            'Key': 'Name',
            'Value': 'Example Certificate'
        }]
    ))

    template.add_output(Output(
        'CertificateARN',
        Value=Ref(certificate),
        Description='The ARN of the example certificate'
    ))

    return template 
开发者ID:dflook,项目名称:cloudformation-dns-certificate,代码行数:31,代码来源:cloudformation.py

示例13: cloudformation_template

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def cloudformation_template(definitions):
        """
        Takes in the list of document definitions and combines them into the troposphere CloudFormation template
        that would contain all the documents.
        """
        template = Template()
        for document in definitions:
            template.add_resource(DefinitionTroposphereAdapter(document))
            for resource in document.get_complimentary_cfn_resources():
                template.add_resource(resource)

        return template 
开发者ID:awslabs,项目名称:aws-systems-manager-document-generator,代码行数:14,代码来源:document_manager.py

示例14: reset_template

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def reset_template(self):
        """Reset template."""
        self.template = Template()
        self._rendered = None
        self._version = None 
开发者ID:onicagroup,项目名称:runway,代码行数:7,代码来源:base.py

示例15: set_template_description

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Template [as 别名]
def set_template_description(self, description):
        """Add a description to the Template.

        Args:
            description (str): A description to be added to the resulting
                template.

        """
        self.template.add_description(description) 
开发者ID:onicagroup,项目名称:runway,代码行数:11,代码来源:base.py


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