本文整理汇总了Python中troposphere.Template.add_mapping方法的典型用法代码示例。如果您正苦于以下问题:Python Template.add_mapping方法的具体用法?Python Template.add_mapping怎么用?Python Template.add_mapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类troposphere.Template
的用法示例。
在下文中一共展示了Template.add_mapping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_json
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def generate_json():
r = {}
t = Template()
# t.add_description(Join('', ["DOMjudge Cluster - ", Ref('AWS::StackName')]))
t.add_description("DOMjudge Cluster")
r['notify_topic'] = Select(0, Ref("AWS::NotificationARNs"))
t.add_mapping('SizeMap', {
'nano': {
'RDSInstanceType': 'db.t2.micro',
'WebInstanceType': 't2.micro',
'WebASGMinSize': 1,
'WebASGMaxSize': 4,
'JudgeASGMinSize': 1,
'JudgeASGMaxSize': 4,
},
'small': {
'RDSInstanceType': 'db.t2.micro',
'WebInstanceType': 't2.micro',
'WebASGMinSize': 1,
'WebASGMaxSize': 4,
'JudgeASGMinSize': 1,
'JudgeASGMaxSize': 4,
},
'medium': {
'RDSInstanceType': 'db.t2.micro',
'WebInstanceType': 't2.micro',
'WebASGMinSize': 1,
'WebASGMaxSize': 4,
'JudgeASGMinSize': 1,
'JudgeASGMaxSize': 4,
},
'large': {
'RDSInstanceType': 'db.t2.micro',
'WebInstanceType': 't2.micro',
'WebASGMinSize': 1,
'WebASGMaxSize': 4,
'JudgeASGMinSize': 1,
'JudgeASGMaxSize': 4,
},
})
parameters.init(t, r)
dynamodb.init(t, r)
iam.init(t, r)
securitygroups.init(t, r)
rds.init(t, r)
webserver.init(t, r)
judgehost.init(t, r)
return t.to_json()
示例2: output_template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def output_template(self):
template = Template()
for parameter in self.parameters:
template.add_parameter(parameter)
for mapping in self.mappings:
template.add_mapping(mapping[0], mapping[1])
for resource in self.resources:
template.add_resource(resource)
for output in self.outputs:
template.add_output(output)
print template.to_json()
return
示例3: InstanceVolumeTemplate
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def InstanceVolumeTemplate(self):
self.stack_name = "volumeTest{0}".format(int(time.time()))
template = Template()
keyname_param = template.add_parameter(Parameter("KeyName", Description="Name of an existing EC2 KeyPair "
"to enable SSH access to the instance",
Type="String",))
template.add_mapping('RegionMap', {"": {"AMI": self.tester.get_emi().id}})
for i in xrange(2):
ec2_instance = template.add_resource(ec2.Instance("Instance{0}".format(i),
ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
InstanceType="t1.micro", KeyName=Ref(keyname_param),
SecurityGroups=[self.group.name], UserData=Base64("80")))
vol = template.add_resource(ec2.Volume("Volume{0}".format(i), Size="8",
AvailabilityZone=GetAtt("Instance{0}".format(i), "AvailabilityZone")))
mount = template.add_resource(ec2.VolumeAttachment("MountPt{0}".format(i), InstanceId=Ref("Instance{0}".format(i)),
VolumeId=Ref("Volume{0}".format(i)), Device="/dev/vdc"))
stack = self.tester.create_stack(self.stack_name, template.to_json(), parameters=[("KeyName",self.keypair.name)])
def stack_completed():
return self.tester.cloudformation.describe_stacks(self.stack_name).status == "CREATE_COMPLETE"
self.tester.wait_for_result(stack_completed, True, timeout=600)
self.tester.delete_stack(self.stack_name)
示例4: base_template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def base_template(self):
t = Template()
t.add_mapping("AWSRegion2AMI", {"eu-west-1": {"AMI": "ami-00d88f77"}})
if "vpc" in self.data:
t.add_mapping("SubnetConfig", {"VPC": self.data["vpc"]})
else:
t.add_mapping(
"SubnetConfig",
{
"VPC": {
"CIDR": "10.0.0.0/16",
"SubnetA": "10.0.0.0/20",
"SubnetB": "10.0.16.0/20",
"SubnetC": "10.0.32.0/20",
}
},
)
return t
示例5: generate_stack_template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def generate_stack_template():
template = Template()
generate_description(template)
generate_version(template)
# ---Parameters------------------------------------------------------------
param_vpc_id = Parameter(
'VpcIdentifer',
Description='The identity of the VPC (vpc-abcdwxyz) in which this stack shall be created.',
Type='AWS::EC2::VPC::Id',
)
template.add_parameter(param_vpc_id)
param_vpc_cidr_block = Parameter(
'VpcCidrBlock',
Description='The CIDR block of the VPC (w.x.y.z/n) in which this stack shall be created.',
Type='String',
Default='10.0.0.0/16'
)
template.add_parameter(param_vpc_cidr_block)
param_database_instance_subnet_id = Parameter(
'VpcSubnetIdentifer',
Description='The identity of the private subnet (subnet-abcdwxyz) in which the database server shall be created.',
Type='AWS::EC2::Subnet::Id',
)
template.add_parameter(param_database_instance_subnet_id)
param_keyname = Parameter(
'PemKeyName',
Description='Name of an existing EC2 KeyPair file (.pem) to use to create EC2 instances',
Type='AWS::EC2::KeyPair::KeyName'
)
template.add_parameter(param_keyname)
param_instance_type = Parameter(
'EC2InstanceType',
Description='EC2 instance type, reference this parameter to insure consistency',
Type='String',
Default='t2.medium', # Prices from (2015-12-03) (Windows, us-west (North CA))
AllowedValues=[ # Source : https://aws.amazon.com/ec2/pricing/
't2.small', # $0.044/hour
't2.micro', # $0.022/hour
't2.medium', # $0.088/hour
't2.large', # $0.166/hour
'm3.medium', # $0.140/hour
'm3.large', # $0.28/hour
'c4.large' # $0.221/hour
],
ConstraintDescription='Must be a valid EC2 instance type'
)
template.add_parameter(param_instance_type)
param_s3_bucket = Parameter(
'S3Bucket',
Description='The bucket in which applicable content can be found.',
Type='String',
Default='author-it-deployment-test-us-east-1'
)
template.add_parameter(param_s3_bucket)
param_s3_key = Parameter(
'S3Key',
Description='The key within the bucket in which relevant files are located.',
Type='String',
Default='source/database/postgresql/single'
)
template.add_parameter(param_s3_key)
param_database_admin_password = Parameter(
'PostgresAdminPassword',
Description='The password to be used by user postgres.',
Type='String',
NoEcho=True
)
template.add_parameter(param_database_admin_password)
#---Mappings---------------------------------------------------------------
mapping_environment_attribute_map = template.add_mapping(
'EnvironmentAttributeMap',
{
'ap-southeast-1': {
'DatabaseServerAmi': 'ami-1ddc0b7e'
},
'ap-southeast-2': {
'DatabaseServerAmi': 'ami-0c95b86f'
},
'us-east-1': {
'DatabaseServerAmi': 'ami-a4827dc9'
},
'us-west-1': {
'DatabaseServerAmi': 'ami-f5f41398'
}
}
)
# ---Resources-------------------------------------------------------------
ref_stack_id = Ref('AWS::StackId')
#.........这里部分代码省略.........
示例6: test_max_mappings
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def test_max_mappings(self):
template = Template()
for i in range(0, MAX_MAPPINGS):
template.add_mapping(str(i), {"n": "v"})
with self.assertRaises(ValueError):
template.add_mapping("mapping", {"n": "v"})
示例7: create
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def create():
es = Template()
es.add_description("Stack defining the elasticsearch instance")
# Get latest AMIs
def getAMI(region):
AMIMap = {}
print("Getting latest AMZN linux AMI in %s" % region)
ec2conn = boto.ec2.connect_to_region(region)
images = ec2conn.get_all_images(owners=["amazon"], filters={"name": "amzn-ami-hvm-*.x86_64-gp2"})
latestDate = ""
latestAMI = ""
for image in images:
if image.creationDate > latestDate:
latestDate = image.creationDate
latestAMI = image.id
AMIMap[region] = {"id": latestAMI}
return AMIMap
# Create AMI Map
es.add_mapping("AMIMap",getAMI(region))
# Create es VPC
esVPC = es.add_resource(
VPC(
"esVPC",
CidrBlock="10.0.0.0/16",
Tags=Tags(
Name="esVPC"
)
)
)
# Create es IGW
esIGW = es.add_resource(
InternetGateway(
"esIGW"
)
)
# Attach IGW to VPC
esIGWAttachment = es.add_resource(
VPCGatewayAttachment(
"esIGWAttachment",
VpcId=Ref(esVPC),
InternetGatewayId=Ref(esIGW)
)
)
# Create es Subnet
esSubnet = es.add_resource(
Subnet(
"esSubnet",
CidrBlock="10.0.0.0/24",
VpcId=Ref(esVPC)
)
)
# Create es RTB
esRTB = es.add_resource(
RouteTable(
"esRTB",
VpcId=Ref(esVPC)
)
)
# Create route to IGW
esDefaultRoute = es.add_resource(
Route(
"esDefaultRoute",
DependsOn="esIGWAttachment",
GatewayId=Ref(esIGW),
DestinationCidrBlock="0.0.0.0/0",
RouteTableId=Ref(esRTB)
)
)
# Associate RTB with Subnet
esSubnetRTBAssociation = es.add_resource(
SubnetRouteTableAssociation(
"esSubnetRTBAssociation",
SubnetId=Ref(esSubnet),
RouteTableId=Ref(esRTB)
)
)
# Create es Security Group
esSecurityGroup = es.add_resource(
SecurityGroup(
"esSecurityGroup",
GroupDescription="Allow inbound access on port 9200",
SecurityGroupIngress=[
SecurityGroupRule(
IpProtocol="tcp",
FromPort="9200",
ToPort="9200",
CidrIp="0.0.0.0/0"
)
#.........这里部分代码省略.........
示例8: Equals
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
))
AmbariUseEBS = t.add_parameter(Parameter(
"AmbariUseEBS",
Default="no",
ConstraintDescription="Must be yes or no only.",
Type="String",
Description="Use EBS Volumes for the Ambari Node",
AllowedValues=["yes", "no"],
))
AmbariUseEBSBool = t.add_condition("AmbariUseEBSBool", Equals(Ref(AmbariUseEBS),"yes"))
t.add_mapping("SubnetConfig",
{'Public': {'CIDR': '10.0.0.0/24'}, 'VPC': {'CIDR': '10.0.0.0/16'}}
)
t.add_mapping("CENTOS7", {
"eu-west-1": {"AMI": "ami-33734044"},
"ap-southeast-1": {"AMI": "ami-2a7b6b78"},
"ap-southeast-2": {"AMI": "ami-d38dc6e9"},
"eu-central-1": {"AMI": "ami-e68f82fb"},
"ap-northeast-1": {"AMI": "ami-b80b6db8"},
"us-east-1": {"AMI": "ami-61bbf104"},
"sa-east-1": {"AMI": "ami-fd0197e0"},
"us-west-1": {"AMI": "ami-f77fbeb3"},
"us-west-2": {"AMI": "ami-d440a6e7"}
})
VPC = t.add_resource(ec2.VPC(
示例9:
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
instance_type = template.add_parameter(Parameter(
"InstanceType",
Description = "EC2 instance type to launch for Application servers",
Type = "String",
Default = "m1.medium",
AllowedValues = [ "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.xlarge", "m3.2xlarge", "c1.medium", "c1.xlarge", "cg1.4xlarge" ],
ConstraintDescription = "must be a valid EC2 instance type"
))
template.add_mapping('RegionMap', {
"us-east-1": {"AMI": "ami-8f4118e6"},
"us-west-1": {"AMI": "ami-905761d5"},
"us-west-2": {"AMI": "ami-6ebe265e"},
"eu-west-1": {"AMI": "ami-eb0ae99c"},
"sa-east-1": {"AMI": "ami-1b9a3c06"},
"ap-southeast-1": {"AMI": "ami-8e4114dc"},
"ap-southeast-2": {"AMI": "ami-5b5bc761"},
"ap-northeast-1": {"AMI": "ami-91395c90"}
})
# Create a security group
sg = template.add_resource(ec2.SecurityGroup('AsgardSecurityGroup'))
sg.GroupDescription = 'Access to Asgard Instance'
sg.SecurityGroupIngress = [
ec2.SecurityGroupRule(
IpProtocol = 'tcp',
FromPort = '22',
ToPort = '22',
CidrIp = '0.0.0.0/0'
),
示例10: RegionInfo
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
region = RegionInfo()
region.endpoint = "CLC IP"
region.name = "eucalyptus"
stack_name = "test-stack-1"
tester = boto.connect_cloudformation(region=region, port=8773, path="/services/CloudFormation", is_secure=False,
aws_access_key_id="your access key",
aws_secret_access_key="your secret key")
template = Template()
keyname_param = template.add_parameter(Parameter("KeyName",
Description="Name of an existing EC2 KeyPair to enable SSH access to the instance",
Type="String", ))
template.add_mapping('RegionMap', {"": {"AMI": "emi to use"}})
for i in xrange(2):
ec2_instance = template.add_resource(ec2.Instance("Instance{0}".format(i),
ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
InstanceType="t1.micro", KeyName=Ref(keyname_param),
SecurityGroups=["default"], UserData=Base64("80")))
vol = template.add_resource(ec2.Volume("Volume{0}".format(i), Size="1",
AvailabilityZone=GetAtt("Instance{0}".format(i), "AvailabilityZone")))
mount = template.add_resource(ec2.VolumeAttachment("MountPt{0}".format(i), InstanceId=Ref("Instance{0}".format(i)),
VolumeId=Ref("Volume{0}".format(i)), Device="/dev/vdc"))
# tester.delete_stack(stack_name)
stack = tester.create_stack(stack_name, template.to_json(), parameters=[("KeyName", "your key name")])
示例11:
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
t.add_mapping('Profile', {
"prod" : {
"InstanceType": "m3.2xlarge",
"ClusterSize": "4",
"MultiAZ" : True,
"DBAllocatedStorage" : "50",
"DBInstanceType" : "db.m3.2xlarge",
"DBBackupRetentionPeriod": 7
},
"stress" : {
"InstanceType": "m3.xlarge",
"ClusterSize": "4",
"MultiAZ" : False,
"DBAllocatedStorage" : "10",
"DBInstanceType" : "db.m3.xlarge",
"DBBackupRetentionPeriod": 0
},
"preprod" : {
"InstanceType": "m3.large",
"ClusterSize": "3",
"MultiAZ" : False,
"DBAllocatedStorage" : "10",
"DBInstanceType" : "db.m3.large",
"DBBackupRetentionPeriod": 1
},
"test" : {
"InstanceType": "m3.large",
"ClusterSize": "3",
"MultiAZ" : False,
"DBAllocatedStorage" : "5",
"DBInstanceType" : "db.m3.large",
"DBBackupRetentionPeriod": 0
}
})
示例12:
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
),
Type="String",
Description="Public subnet 1 CIDR block.",
ConstraintDescription=(
"Must be a valid IP CIDR range of the form x.x.x.x/x and subnet of "
"VPC."
)
))
t.add_mapping(
"AWSNATAMI",
{
"ap-northeast-1": {"AMI": "ami-03cf3903"},
"ap-southeast-1": {"AMI": "ami-b49dace6"},
"ap-southeast-2": {"AMI": "ami-e7ee9edd"},
"eu-central-1": {"AMI": "ami-46073a5b"},
"eu-west-1": {"AMI": "ami-6975eb1e"},
"sa-east-1": {"AMI": "ami-fbfa41e6"},
"us-east-1": {"AMI": "ami-303b1458"},
"us-west-1": {"AMI": "ami-7da94839"},
"us-west-2": {"AMI": "ami-69ae8259"}
}
)
vpc = t.add_resource(VPC(
"vpc",
InstanceTenancy="default",
EnableDnsSupport="true",
CidrBlock=Ref(vpcCidr),
EnableDnsHostnames="true"
))
示例13:
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
instance_type = template.add_parameter(Parameter(
"InstanceType",
Description = "EC2 instance type to launch for Application servers",
Type = "String",
Default = "m1.medium",
AllowedValues = [ "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.xlarge", "m3.2xlarge", "c1.medium", "c1.xlarge", "cg1.4xlarge" ],
ConstraintDescription = "must be a valid EC2 instance type"
))
template.add_mapping('RegionMap', {
"us-east-1": {"AMI": "ami-99247ff0"},
"us-west-1": {"AMI": "ami-ae0234eb"},
"us-west-2": {"AMI": "ami-f40991c4"},
"eu-west-1": {"AMI": "ami-c1c527b6"},
"sa-east-1": {"AMI": "ami-df45e3c2"},
"ap-southeast-1": {"AMI": "ami-2a9cc978"},
"ap-southeast-2": {"AMI": "ami-1970ec23"},
"ap-northeast-1": {"AMI": "ami-91d3b690"}
})
role = template.add_resource(Role('EurekaRole',
AssumeRolePolicyDocument = {
"Statement": [{
"Effect": "Allow",
"Principal":{
"Service":["ec2.amazonaws.com"]
},
"Action":["sts:AssumeRole"]
}]
},
示例14: Template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
# -*- coding: utf-8 -*-
from troposphere import FindInMap, Ref
from troposphere import Template, Tags
import troposphere.rds as rds
t = Template()
t.add_version("2010-09-09")
t.add_description("rds sample")
t.add_mapping("RDSConfig", {
"Sample": {
"TagName": "RDSSample",
"username": "user",
"password": "password",
"dbname": "sample",
"subnetids": [
"subnet-xxxxxxxa",
"subnet-xxxxxxxc"
]
},
})
# db_subnet_group
subnetgroup = t.add_resource(rds.DBSubnetGroup(
"subnetgroup",
DBSubnetGroupDescription="SubnetGroup sample",
SubnetIds=FindInMap("RDSConfig", "Sample", "subnetids"),
Tags=Tags(
Name=FindInMap("RDSConfig", "Sample", "TagName"),
Application=Ref("AWS::StackName")
)
示例15: generate_stack_template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_mapping [as 别名]
def generate_stack_template():
template = Template()
generate_description(template)
generate_version(template)
# ---Parameters------------------------------------------------------------
param_vpc_id = Parameter(
'VpcIdentifer',
Description='The identity of the VPC (vpc-abcdwxyz) in which this stack shall be created.',
Type='AWS::EC2::VPC::Id',
)
template.add_parameter(param_vpc_id)
param_vpc_security_group = Parameter(
'VpcSecurityGroup',
Description='The security group (sg-abcdwxyz) to apply to the resources created by this stack.',
Type='AWS::EC2::SecurityGroup::Id',
)
template.add_parameter(param_vpc_security_group)
param_webserver_instance_subnet_id = Parameter(
'VpcSubnetIdentifer',
Description='The identity of the public subnet (subnet-abcdwxyz) in which the web server shall be created.',
Type='AWS::EC2::Subnet::Id',
)
template.add_parameter(param_webserver_instance_subnet_id)
param_keyname = Parameter(
'PemKeyName',
Description='Name of an existing EC2 KeyPair file (.pem) to use to create EC2 instances',
Type='AWS::EC2::KeyPair::KeyName'
)
template.add_parameter(param_keyname)
param_instance_type = Parameter(
'EC2InstanceType',
Description='EC2 instance type, reference this parameter to insure consistency',
Type='String',
Default='t2.medium', # Prices from (2015-12-03) (Windows, us-west (North CA))
AllowedValues=[ # Source : https://aws.amazon.com/ec2/pricing/
't2.small', # $0.044/hour
't2.micro', # $0.022/hour
't2.medium', # $0.088/hour
't2.large', # $0.166/hour
'm3.medium', # $0.140/hour
'm3.large', # $0.28/hour
'c4.large' # $0.221/hour
],
ConstraintDescription='Must be a valid EC2 instance type'
)
template.add_parameter(param_instance_type)
#---Mappings---------------------------------------------------------------
mapping_environment_attribute_map = template.add_mapping(
'EnvironmentAttributeMap',
{
'ap-southeast-1': {
'WebServerAmi': 'ami-1ddc0b7e'
},
'ap-southeast-2': {
'WebServerAmi': 'ami-0c95b86f'
},
'us-east-1': {
'WebServerAmi': 'ami-a4827dc9'
},
'us-west-1': {
'WebServerAmi': 'ami-f5f41398'
}
}
)
# ---Resources-------------------------------------------------------------
ref_region = Ref('AWS::Region')
ref_stack_name = Ref('AWS::StackName')
# Create the metadata for the server instance.
name_web_server = 'WebServer'
webserver_instance_metadata = cloudformation.Metadata(
cloudformation.Init({
'config': cloudformation.InitConfig(
packages={
'yum': {
'nginx': [],
'git': []
}
},
files=cloudformation.InitFiles({
# cfn-hup.conf initialization
'/etc/cfn/authorapp.conf': cloudformation.InitFile(
content=Join('',
[
'server {', '\n',
' listen 3030 ssl http2;', '\n',
' root /var/www/authorapp;', '\n',
'\n',
' ssl_certificate /vagrant/ssl/ca.crt;', '\n',
' ssl_certificate_key /vagrant/ssl/ca.key;', '\n',
#.........这里部分代码省略.........