本文整理汇总了Python中troposphere.Join方法的典型用法代码示例。如果您正苦于以下问题:Python troposphere.Join方法的具体用法?Python troposphere.Join怎么用?Python troposphere.Join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类troposphere
的用法示例。
在下文中一共展示了troposphere.Join方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_instance_profile
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def add_instance_profile(self, layer_name, iam_policies, path_prefix):
"""
Helper function to add role and instance profile resources to this template
using the provided iam_policies. The instance_profile will be created at:
'/<path_prefix>/<layer_name>/'
"""
iam_role_obj = iam.Role(layer_name + 'IAMRole',
AssumeRolePolicyDocument={
'Statement': [{
'Effect': 'Allow',
'Principal': {'Service': ['ec2.amazonaws.com']},
'Action': ['sts:AssumeRole']
}]},
Path=Join('', ['/' + path_prefix + '/', layer_name , '/']))
if iam_policies != None:
iam_role_obj.Policies = iam_policies
iam_role = self.add_resource(iam_role_obj)
return self.add_resource(iam.InstanceProfile(layer_name + 'InstancePolicy',
Path='/' + path_prefix + '/',
Roles=[Ref(iam_role)]))
示例2: construct_user_data
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [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
)
示例3: prepare_efs_security_groups
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def prepare_efs_security_groups(self):
t = self.template
v = self.get_variables()
created_groups = []
for sg in v['SecurityGroups']:
sg.VpcId = v['VpcId']
sg.Tags = merge_tags(v['Tags'], getattr(sg, 'Tags', {}))
sg = t.add_resource(sg)
created_groups.append(sg)
created_group_ids = list(map(Ref, created_groups))
t.add_output(Output(
'EfsNewSecurityGroupIds',
Value=Join(',', created_group_ids)))
groups_ids = created_group_ids + v['ExtraSecurityGroups']
return groups_ids
示例4: create_efs_mount_targets
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def create_efs_mount_targets(self, fs):
t = self.template
v = self.get_variables()
groups = self.prepare_efs_security_groups()
subnets = v['Subnets']
ips = v['IpAddresses']
mount_targets = []
for i, subnet in enumerate(subnets):
mount_target = efs.MountTarget(
'EfsMountTarget{}'.format(i + 1),
FileSystemId=Ref(fs),
SubnetId=subnet,
SecurityGroups=groups)
if ips:
mount_target.IpAddress = ips[i]
mount_target = t.add_resource(mount_target)
mount_targets.append(mount_target)
t.add_output(Output(
'EfsMountTargetIds',
Value=Join(',', list(map(Ref, mount_targets)))))
示例5: build_hook
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def build_hook(self):
"""
Hook to add tier-specific assets within the build stage of initializing this class.
"""
if not self.dist_config:
self.dist_config = DistributionConfig(
Origins=[Origin(
Id="Origin",
DomainName=self.domain_name,
OriginPath=self.origin_path,
S3OriginConfig=S3Origin(),
)],
DefaultCacheBehavior=DefaultCacheBehavior(
TargetOriginId="Origin",
ForwardedValues=ForwardedValues(
QueryString=False
),
ViewerProtocolPolicy="allow-all"),
Enabled=True
)
if self.utility_bucket:
self.dist_config.Logging = Logging(
Bucket=Join('.', [self.utility_bucket, 's3.amazonaws.com']),
IncludeCookies=True,
Prefix=Join('/', ['AWSLogs', Ref(AWS_ACCOUNT_ID), 'CloudFront'])
)
cf_distribution = self.add_resource(Distribution(
self.resource_name,
DistributionConfig=self.dist_config
))
self.add_output([
Output("DistributionId", Value=Ref(cf_distribution)),
Output("DistributionName", Value=Join("", ["http://", GetAtt(cf_distribution, "DomainName")])),
])
示例6: build_bootstrap
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [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))
示例7: register_elb_to_dns
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def register_elb_to_dns(self,
elb,
tier_name,
tier_args):
"""
Method handles the process of uniformly creating CNAME records for ELBs in a given tier
@param elb [Troposphere.elasticloadbalancing.LoadBalancer]
@param tier_name [str]
@param tier_args [dict]
"""
if 'environmentHostedZone' not in self.parameters:
hostedzone = self.add_parameter(Parameter(
"environmentHostedZone",
Description="The DNS name of an existing Amazon Route 53 hosted zone",
Default=tier_args.get('base_hosted_zone_name', 'devopsdemo.com'),
Type="String"))
else:
hostedzone = self.parameters.get('environmentHostedZone')
if tier_name.lower() + 'HostName' not in self.parameters:
host_name = self.add_parameter(Parameter(
tier_name.lower() + 'HostName',
Description="Friendly host name to append to the environmentHostedZone base DNS record",
Type="String",
Default=tier_args.get('tier_host_name', tier_name.lower())))
else:
host_name = self.parameters.get(tier_name.lower() + 'HostName')
self.add_resource(r53.RecordSetType(
tier_name.lower() + 'DnsRecord',
HostedZoneName=Join('', [Ref(hostedzone), '.']),
Comment='CNAME record for ' + tier_name.capitalize() + ' tier',
Name=Join('', [Ref(host_name), '.', Ref(hostedzone)]),
Type='CNAME',
TTL='300',
ResourceRecords=[GetAtt(elb, 'DNSName')]))
示例8: get_template_s3_url
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [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])
示例9: create_template
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def create_template(self):
"""Create template (main function called by Stacker)."""
template = self.template
variables = self.get_variables()
template.set_version('2010-09-09')
template.set_description('Runway Integration Testing - IAM Role')
# Resources
template.add_resource(
iam.Role(
'CodeBuildRole',
AssumeRolePolicyDocument=PolicyDocument(
Statement=[
Statement(
Effect=Allow,
Action=[awacs.sts.AssumeRole],
Principal=Principal(
'AWS',
TESTING_ACCOUNT_ID
)
)
]
),
Description='Role used for cross account testing in runway',
ManagedPolicyArns=[
'arn:aws:iam::aws:policy/AdministratorAccess'
],
RoleName=Join('-', ['runway-integration-test-role',
variables['EnvironmentName'].ref])
)
)
示例10: test_parameterized_codec_b64
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [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)
示例11: test_parameterized_codec_plain
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def test_parameterized_codec_plain(self):
"""Test parameterized codec plain."""
expected = Join(u'', [u'Test ', {u'Ref': u'Interpolation'}, u' Here'])
out = parameterized_codec(u'Test {{Interpolation}} Here', False)
self.assertEqual(GenericHelperFn, out.__class__)
self.assertTemplateEqual(expected, out)
示例12: test_yaml_codec_parameterized
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def test_yaml_codec_parameterized(self):
"""Test yaml codec parameterized."""
processed = {
u'Test': Join(u'', [u'Test ', {u'Ref': u'Interpolation'},
u' Here'])
}
structured = {
u'Test': u'Test {{Interpolation}} Here'
}
raw = yaml.safe_dump(structured)
out = yaml_codec(raw, parameterized=True)
self.assertTemplateEqual(processed, out)
示例13: test_json_codec_parameterized
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [as 别名]
def test_json_codec_parameterized(self):
"""Test json codec parameterized."""
processed = {
u'Test': Join(u'', [u'Test ', {u'Ref': u'Interpolation'},
u' Here'])
}
structured = {
u'Test': u'Test {{Interpolation}} Here'
}
raw = json.dumps(structured)
out = json_codec(raw, parameterized=True)
self.assertTemplateEqual(processed, out)
示例14: generate_user_data
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [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
示例15: test_parameterized_codec_b64
# 需要导入模块: import troposphere [as 别名]
# 或者: from troposphere import Join [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)