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


Python troposphere.Base64方法代码示例

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


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

示例1: parameterized_codec

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def parameterized_codec(raw, b64):
    """Parameterize a string, possibly encoding it as Base64 afterwards.

    Args:
        raw (Union[bytes, str]): String to be processed. Byte strings will be
            interpreted as UTF-8.
        b64 (bool): Whether to wrap the output in a Base64 CloudFormation
            call.

    Returns:
        :class:`troposphere.AWSHelperFn`: Output to be included in a
        CloudFormation template.

    """
    if isinstance(raw, bytes):
        raw = raw.decode('utf-8')

    result = _parameterize_string(raw)

    # Note, since we want a raw JSON object (not a string) output in the
    # template, we wrap the result in GenericHelperFn (not needed if we're
    # using Base64)
    return Base64(result.data) if b64 else result 
开发者ID:onicagroup,项目名称:runway,代码行数:25,代码来源:file.py

示例2: test_resolve_variables_lookup_returns_troposphere_obj

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def test_resolve_variables_lookup_returns_troposphere_obj(self):
        """Test resolve variables lookup returns troposphere obj."""
        class TestBlueprint(Blueprint):
            """Test blueprint."""

            VARIABLES = {
                "Param1": {"type": Base64},
            }

        def return_obj(*_args, **_kwargs):
            """Return object."""
            return Base64("test")

        register_lookup_handler("custom", return_obj)
        blueprint = TestBlueprint(name="test", context=MagicMock())
        variables = [Variable("Param1", "${custom non-string-return-val}",
                              'cfngin')]
        for var in variables:
            var._value.resolve({}, {})

        blueprint.resolve_variables(variables)
        self.assertEqual(blueprint.resolved_variables["Param1"].data,
                         Base64("test").data) 
开发者ID:onicagroup,项目名称:runway,代码行数:25,代码来源:test_base.py

示例3: parameterized_codec

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def parameterized_codec(raw, b64):
    """Parameterize a string, possibly encoding it as Base64 afterwards

    Args:
        raw (`str` | `bytes`): String to be processed. Byte strings will be
            interpreted as UTF-8.
        b64 (`bool`): Whether to wrap the output in a Base64 CloudFormation
            call

    Returns:
        :class:`troposphere.AWSHelperFn`: output to be included in a
        CloudFormation template.
    """

    if isinstance(raw, bytes):
        raw = raw.decode('utf-8')

    result = _parameterize_string(raw)

    # Note, since we want a raw JSON object (not a string) output in the
    # template, we wrap the result in GenericHelperFn (not needed if we're
    # using Base64)
    return Base64(result.data) if b64 else result 
开发者ID:cloudtools,项目名称:stacker,代码行数:25,代码来源:file.py

示例4: build_bootstrap

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [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

示例5: test_tropo_to_string

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [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

示例6: test_build_bootstrap

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [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

示例7: test_parameterized_codec_b64

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def test_parameterized_codec_b64(self):
        """Test parameterized codec b64."""
        expected = Base64(
            Join(u'', [u'Test ', {u'Ref': u'Interpolation'}, u' Here'])
        )

        out = parameterized_codec(u'Test {{Interpolation}} Here', True)
        self.assertEqual(Base64, out.__class__)
        self.assertTemplateEqual(expected, out) 
开发者ID:onicagroup,项目名称:runway,代码行数:11,代码来源:test_file.py

示例8: generate_user_data

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def generate_user_data(self):
        contents = Join("", self.generate_seed_contents())
        stanza = Base64(Join(
            "",
            [
                "#cloud-config\n",
                "write_files:\n",
                "  - encoding: b64\n",
                "    content: ", Base64(contents), "\n",
                "    owner: root:root\n",
                "    path: /etc/empire/seed\n",
                "    permissions: 0640\n"
            ]
        ))
        return stanza 
开发者ID:remind101,项目名称:stacker_blueprints,代码行数:17,代码来源:base.py

示例9: test_parameterized_codec_b64

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def test_parameterized_codec_b64(self):
        expected = Base64(
            Join(u'', [u'Test ', {u'Ref': u'Interpolation'}, u' Here'])
        )

        out = parameterized_codec(u'Test {{Interpolation}} Here', True)
        self.assertEqual(Base64, out.__class__)
        self.assertTemplateEqual(expected, out) 
开发者ID:cloudtools,项目名称:stacker,代码行数:10,代码来源:test_file.py

示例10: add_nat_asg

# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Base64 [as 别名]
def add_nat_asg(self):

        user_data = [resources.get_resource('nat_takeover.sh')]

        if self.enable_ntp:
            user_data.append(resources.get_resource('ntp_takeover.sh'))
        if self.extra_user_data:
            user_data.append(open(self.extra_user_data).read())

        nat_asg_name = "Nat%sASG" % str(self.subnet_index)

        user_data.extend([
            "\n",
            "cfn-signal -s true",
            " --resource ", nat_asg_name,
            " --stack ", {"Ref": "AWS::StackName"},
            " --region ", {"Ref": "AWS::Region"}
        ])
 
        nat_launch_config = self.add_resource(LaunchConfiguration(
            "Nat%sLaunchConfig" % str(self.subnet_index),
            UserData=Base64(Join('', user_data)),
            ImageId=FindInMap('RegionMap', Ref('AWS::Region'), 'natAmiId'),
            KeyName=Ref('ec2Key'),
            SecurityGroups=[Ref(self.sg)],
            EbsOptimized=False,
            IamInstanceProfile=Ref(self.instance_profile),
            InstanceType=self.instance_type,
            AssociatePublicIpAddress=True
        ))

        # Create the NAT in a public subnet
        subnet_layer = self._subnets['public'].keys()[0]

        nat_asg = self.add_resource(AutoScalingGroup(
            nat_asg_name,
            DesiredCapacity=1,
            Tags=[
                Tag("Name", Join("-", ["NAT", self.subnet_index,]), True),
                Tag("isNat", "true", True)
            ],
            MinSize=1,
            MaxSize=1,
            Cooldown="30",
            LaunchConfigurationName=Ref(nat_launch_config),
            HealthCheckGracePeriod=30,
            HealthCheckType="EC2",
            VPCZoneIdentifier=[self._subnets['public'][subnet_layer][self.subnet_index]],
            CreationPolicy=CreationPolicy(
                ResourceSignal=ResourceSignal(
                    Count=1,
                    Timeout='PT15M'
                )
            )
        ))

        return nat_asg 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:59,代码来源:ha_nat.py


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