當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。