本文整理汇总了Python中troposphere.Template.add_condition方法的典型用法代码示例。如果您正苦于以下问题:Python Template.add_condition方法的具体用法?Python Template.add_condition怎么用?Python Template.add_condition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类troposphere.Template
的用法示例。
在下文中一共展示了Template.add_condition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def template():
t = Template()
for p in parameters.values():
t.add_parameter(p)
for k in conditions:
t.add_condition(k, conditions[k])
for r in resources.values():
t.add_resource(r)
return t
示例2: main
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def main(argv):
FILE = None
try:
opts, args = getopt.getopt(argv,"hf:",["FILE="])
except getopt.GetoptError:
print sys.argv[0], ' -f <metric-csv-file>'
sys.exit(2)
# An array to contain any parameters for the template.
parameters = []
# An array to contain any conditions for the template.
conditions = {}
# An array to contain any key value maps for the template.
maps = []
# An array to contain any resource objects for the template.
resources = []
# An array to contain any output objects for the template.
outputs = []
with open(FILE, 'rbU') as f:
reader = csv.reader(f)
try:
for row in islice(reader, 1, None):
resources.append(Alarm(
"QueueDepthAlarm",
AlarmDescription="Alarm if queue depth grows beyond 10 messages",
Namespace="AWS/SQS",
MetricName="ApproximateNumberOfMessagesVisible",
Dimensions=[
MetricDimension(
Name="QueueName",
Value=GetAtt(myqueue, "QueueName")
),
],
Statistic="Sum",
Period="300",
EvaluationPeriods="1",
Threshold="10",
ComparisonOperator="GreaterThanThreshold",
AlarmActions=[Ref(alarmtopic), ],
InsufficientDataActions=[Ref(alarmtopic), ],
))
except csv.Error as e:
sys.exit('file %s, line %d: %s' % (VPC_ID, reader.line_num, e))
t = Template()
t.add_version('2010-09-09')
t.add_description(
"This is an AWS CloudFormation template that provisions metric filters "
"based on a spreadsheet of applicable metric filters. ***WARNING*** This "
"template creates many Amazon CloudWatch alarms based on a Amazon "
"CloudWatch Logs Log Group. You will be billed for the AWS resources used "
"if you create a stack from this template."
)
for p in parameters:
t.add_parameter(p)
for k in conditions:
t.add_condition(k, conditions[k])
for r in resources:
t.add_resource(r)
for o in outputs:
t.add_output(o)
# Print the template to JSON
print(t.to_json())
示例3: main
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def main(args):
t = Template()
# ================= Parameters =================
# 0 1 2 3 4 5 6 7
# [shared_dir,fsx_fs_id,storage_capacity,fsx_kms_key_id,imported_file_chunk_size,export_path,import_path,weekly_maintenance_start_time]
fsx_options = t.add_parameter(
Parameter(
"FSXOptions",
Type="CommaDelimitedList",
Description="Comma separated list of fsx related options, 8 parameters in total, [shared_dir,fsx_fs_id,storage_capacity,fsx_kms_key_id,imported_file_chunk_size,export_path,import_path,weekly_maintenance_start_time]",
)
)
compute_security_group = t.add_parameter(
Parameter("ComputeSecurityGroup", Type="String", Description="SecurityGroup for FSx filesystem")
)
subnet_id = t.add_parameter(Parameter("SubnetId", Type="String", Description="SubnetId for FSx filesystem"))
# ================= Conditions =================
create_fsx = t.add_condition(
"CreateFSX",
And(Not(Equals(Select(str(0), Ref(fsx_options)), "NONE")), Equals(Select(str(1), Ref(fsx_options)), "NONE")),
)
use_storage_capacity = t.add_condition("UseStorageCap", Not(Equals(Select(str(2), Ref(fsx_options)), "NONE")))
use_fsx_kms_key = t.add_condition("UseFSXKMSKey", Not(Equals(Select(str(3), Ref(fsx_options)), "NONE")))
use_imported_file_chunk_size = t.add_condition(
"UseImportedFileChunkSize", Not(Equals(Select(str(4), Ref(fsx_options)), "NONE"))
)
use_export_path = t.add_condition("UseExportPath", Not(Equals(Select(str(5), Ref(fsx_options)), "NONE")))
use_import_path = t.add_condition("UseImportPath", Not(Equals(Select(str(6), Ref(fsx_options)), "NONE")))
use_weekly_mainenance_start_time = t.add_condition(
"UseWeeklyMaintenanceStartTime", Not(Equals(Select(str(7), Ref(fsx_options)), "NONE"))
)
# ================= Resources =================
fs = t.add_resource(
FileSystem(
"FileSystem",
FileSystemType="LUSTRE",
SubnetIds=[Ref(subnet_id)],
SecurityGroupIds=[Ref(compute_security_group)],
KmsKeyId=If(use_fsx_kms_key, Select(str(3), Ref(fsx_options)), NoValue),
StorageCapacity=If(use_storage_capacity, Select(str(2), Ref(fsx_options)), NoValue),
LustreConfiguration=LustreConfiguration(
ImportedFileChunkSize=If(use_imported_file_chunk_size, Select(str(4), Ref(fsx_options)), NoValue),
ExportPath=If(use_export_path, Select(str(5), Ref(fsx_options)), NoValue),
ImportPath=If(use_import_path, Select(str(6), Ref(fsx_options)), NoValue),
WeeklyMaintenanceStartTime=If(
use_weekly_mainenance_start_time, Select(str(7), Ref(fsx_options)), NoValue
),
),
Condition=create_fsx,
)
)
# ================= Outputs =================
t.add_output(
Output(
"FileSystemId",
Description="ID of the FileSystem",
Value=If(create_fsx, Ref(fs), Select("1", Ref(fsx_options))),
)
)
# Specify output file path
json_file_path = args.target_path
output_file = open(json_file_path, "w")
output_file.write(t.to_json())
output_file.close()
示例4: price
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
subnet = template.add_parameter(Parameter(
"Subnet",
Description="Subnet ID for creating the EMR cluster",
Type=SUBNET_ID
))
spot = template.add_parameter(Parameter(
"SpotPrice",
Description="Spot price (or use 0 for 'on demand' instance)",
Type=NUMBER,
Default="0.1"
))
withSpotPrice = "WithSpotPrice"
template.add_condition(withSpotPrice, Not(Equals(Ref(spot), "0")))
gcTimeRatio = template.add_parameter(Parameter(
"GcTimeRatioValue",
Description="Hadoop name node garbage collector time ratio",
Type=NUMBER,
Default="19"
))
# IAM roles required by EMR
emr_service_role = template.add_resource(iam.Role(
'EMRServiceRole',
AssumeRolePolicyDocument={
"Statement": [{
"Effect": "Allow",
示例5: Parameter
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
Parameter(
'DataIops',
Description='Number of provisioned data IOPS',
Type='Number',
Default='0',
),
Parameter(
'DataSize',
Description='Size of data device in GB',
Type='Number',
Default='500',
),
])
template.add_condition('EnableDataIops', {
'Fn::Not': [{'Fn::Equals': [Ref('DataIops'), 0]}]
})
atlas.infra_params(template) ## ssh_key, Env, Silo
atlas.conf_params(template) ## Conf Name, Conf Version, Conf tarball bucket
atlas.instance_params(
template,
roles_default=['log', ],
iam_default='log',
)
atlas.scaling_params(template)
atlas.mappings(
示例6: Equals
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
s3_bucket_parameter = template.add_parameter(Parameter(
"S3BucketParameter",
Type="String",
Description="Name of the S3 bucket where you uploaded the source code zip",
))
source_zip_parameter = template.add_parameter(Parameter(
"SourceZipParameter",
Type="String",
Default="backup-rds.zip",
Description="Name of the zip file inside the S3 bucket",
))
template.add_condition("UseAllDatabases", Equals(Join("", Ref(databases_to_use_parameter)), ""))
template.add_condition("UseEncryption", Equals(Ref(kms_key_parameter), ""), )
template.add_condition("IncludeAurora", Equals(Ref(include_aurora_clusters_parameter), "Yes"))
template.add_metadata({
"AWS::CloudFormation::Interface": {
"ParameterGroups": [
{
"Label": {
"default": "Basic configuration"
},
"Parameters": [
"TargetRegionParameter",
"S3BucketParameter",
"SourceZipParameter",
]
示例7: main
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def main(args):
t = Template()
# [0 shared_dir, 1 efs_fs_id, 2 performance_mode, 3 efs_kms_key_id,
# 4 provisioned_throughput, 5 encrypted, 6 throughput_mode, 7 exists_valid_mt]
efs_options = t.add_parameter(
Parameter(
"EFSOptions",
Type="CommaDelimitedList",
Description="Comma separated list of efs related options, " "8 parameters in total",
)
)
compute_security_group = t.add_parameter(
Parameter("ComputeSecurityGroup", Type="String", Description="SecurityGroup for Mount Target")
)
subnet_id = t.add_parameter(Parameter("SubnetId", Type="String", Description="SubnetId for Mount Target"))
create_efs = t.add_condition(
"CreateEFS",
And(Not(Equals(Select(str(0), Ref(efs_options)), "NONE")), Equals(Select(str(1), Ref(efs_options)), "NONE")),
)
create_mt = t.add_condition(
"CreateMT",
And(Not(Equals(Select(str(0), Ref(efs_options)), "NONE")), Equals(Select(str(7), Ref(efs_options)), "NONE")),
)
use_performance_mode = t.add_condition("UsePerformanceMode", Not(Equals(Select(str(2), Ref(efs_options)), "NONE")))
use_efs_encryption = t.add_condition("UseEFSEncryption", Equals(Select(str(5), Ref(efs_options)), "true"))
use_efs_kms_key = t.add_condition(
"UseEFSKMSKey", And(Condition(use_efs_encryption), Not(Equals(Select(str(3), Ref(efs_options)), "NONE")))
)
use_throughput_mode = t.add_condition("UseThroughputMode", Not(Equals(Select(str(6), Ref(efs_options)), "NONE")))
use_provisioned = t.add_condition("UseProvisioned", Equals(Select(str(6), Ref(efs_options)), "provisioned"))
use_provisioned_throughput = t.add_condition(
"UseProvisionedThroughput",
And(Condition(use_provisioned), Not(Equals(Select(str(4), Ref(efs_options)), "NONE"))),
)
fs = t.add_resource(
FileSystem(
"EFSFS",
PerformanceMode=If(use_performance_mode, Select(str(2), Ref(efs_options)), NoValue),
ProvisionedThroughputInMibps=If(use_provisioned_throughput, Select(str(4), Ref(efs_options)), NoValue),
ThroughputMode=If(use_throughput_mode, Select(str(6), Ref(efs_options)), NoValue),
Encrypted=If(use_efs_encryption, Select(str(5), Ref(efs_options)), NoValue),
KmsKeyId=If(use_efs_kms_key, Select(str(3), Ref(efs_options)), NoValue),
Condition=create_efs,
)
)
mt = t.add_resource(
MountTarget(
"EFSMT",
FileSystemId=If(create_efs, Ref(fs), Select(str(1), Ref(efs_options))),
SecurityGroups=[Ref(compute_security_group)],
SubnetId=Ref(subnet_id),
Condition=create_mt,
)
)
t.add_output(
Output(
"FileSystemId",
Description="ID of the FileSystem",
Value=If(create_efs, Ref(fs), Select("1", Ref(efs_options))),
)
)
# Specify output file path
json_file_path = args.target_path
output_file = open(json_file_path, "w")
output_file.write(t.to_json())
output_file.close()
示例8: main
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def main(args):
number_of_vol = 5
t = Template()
availability_zone = t.add_parameter(
Parameter(
"AvailabilityZone",
Type="String",
Description="Availability Zone the cluster will launch into. THIS IS REQUIRED",
)
)
volume_size = t.add_parameter(
Parameter(
"VolumeSize", Type="CommaDelimitedList", Description="Size of EBS volume in GB, if creating a new one"
)
)
volume_type = t.add_parameter(
Parameter(
"VolumeType", Type="CommaDelimitedList", Description="Type of volume to create either new or from snapshot"
)
)
volume_iops = t.add_parameter(
Parameter(
"VolumeIOPS",
Type="CommaDelimitedList",
Description="Number of IOPS for volume type io1. Not used for other volume types.",
)
)
ebs_encryption = t.add_parameter(
Parameter(
"EBSEncryption",
Type="CommaDelimitedList",
Description="Boolean flag to use EBS encryption for /shared volume. " "(Not to be used for snapshots)",
)
)
ebs_kms_id = t.add_parameter(
Parameter(
"EBSKMSKeyId",
Type="CommaDelimitedList",
Description="KMS ARN for customer created master key, will be used for EBS encryption",
)
)
ebs_volume_id = t.add_parameter(
Parameter("EBSVolumeId", Type="CommaDelimitedList", Description="Existing EBS volume Id")
)
ebs_snapshot_id = t.add_parameter(
Parameter(
"EBSSnapshotId",
Type="CommaDelimitedList",
Description="Id of EBS snapshot if using snapshot as source for volume",
)
)
ebs_vol_num = t.add_parameter(
Parameter(
"NumberOfEBSVol",
Type="Number",
Description="Number of EBS Volumes the user requested, up to %s" % number_of_vol,
)
)
use_vol = [None] * number_of_vol
use_existing_ebs_volume = [None] * number_of_vol
v = [None] * number_of_vol
for i in range(number_of_vol):
if i == 0:
create_vol = t.add_condition(
"Vol%s_CreateEBSVolume" % (i + 1), Equals(Select(str(i), Ref(ebs_volume_id)), "NONE")
)
elif i == 1:
use_vol[i] = t.add_condition("UseVol%s" % (i + 1), Not(Equals(Ref(ebs_vol_num), str(i))))
create_vol = t.add_condition(
"Vol%s_CreateEBSVolume" % (i + 1),
And(Condition(use_vol[i]), Equals(Select(str(i), Ref(ebs_volume_id)), "NONE")),
)
else:
use_vol[i] = t.add_condition(
"UseVol%s" % (i + 1), And(Not(Equals(Ref(ebs_vol_num), str(i))), Condition(use_vol[i - 1]))
)
create_vol = t.add_condition(
"Vol%s_CreateEBSVolume" % (i + 1),
And(Condition(use_vol[i]), Equals(Select(str(i), Ref(ebs_volume_id)), "NONE")),
)
use_ebs_iops = t.add_condition("Vol%s_UseEBSPIOPS" % (i + 1), Equals(Select(str(i), Ref(volume_type)), "io1"))
use_vol_size = t.add_condition(
"Vol%s_UseVolumeSize" % (i + 1), Not(Equals(Select(str(i), Ref(volume_size)), "NONE"))
)
use_vol_type = t.add_condition(
"Vol%s_UseVolumeType" % (i + 1), Not(Equals(Select(str(i), Ref(volume_type)), "NONE"))
)
use_ebs_encryption = t.add_condition(
"Vol%s_UseEBSEncryption" % (i + 1), Equals(Select(str(i), Ref(ebs_encryption)), "true")
)
use_ebs_kms_key = t.add_condition(
"Vol%s_UseEBSKMSKey" % (i + 1),
And(Condition(use_ebs_encryption), Not(Equals(Select(str(i), Ref(ebs_kms_id)), "NONE"))),
)
use_ebs_snapshot = t.add_condition(
"Vol%s_UseEBSSnapshot" % (i + 1), Not(Equals(Select(str(i), Ref(ebs_snapshot_id)), "NONE"))
#.........这里部分代码省略.........
示例9: main
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def main(args):
number_of_vol = 5
t = Template()
availability_zone = t.add_parameter(
Parameter(
"AvailabilityZone",
Type="String",
Description="Availability Zone the cluster will launch into. " "THIS IS REQUIRED",
)
)
raid_options = t.add_parameter(
Parameter(
"RAIDOptions",
Type="CommaDelimitedList",
Description="Comma separated list of RAID related options, "
"8 parameters in total, "
"["
"0 shared_dir,"
"1 raid_type,"
"2 num_of_vols,"
"3 vol_type,"
"4 vol_size,"
"5 vol_IOPS,"
"6 encrypted, "
"7 ebs_kms_key]",
)
)
use_vol = [None] * number_of_vol
v = [None] * number_of_vol
for i in range(number_of_vol):
if i == 0:
use_vol[i] = t.add_condition("UseVol%s" % (i + 1), Not(Equals(Select("0", Ref(raid_options)), "NONE")))
else:
use_vol[i] = t.add_condition(
"UseVol%s" % (i + 1),
And(Not(Equals(Select("2", Ref(raid_options)), str(i))), Condition(use_vol[i - 1])),
)
use_ebs_iops = t.add_condition("Vol%s_UseEBSPIOPS" % (i + 1), Equals(Select("3", Ref(raid_options)), "io1"))
use_volume_size = t.add_condition(
"Vol%s_UseVolumeSize" % (i + 1), Not(Equals(Select("4", Ref(raid_options)), "NONE"))
)
use_volume_type = t.add_condition(
"Vol%s_UseVolumeType" % (i + 1), Not(Equals(Select("3", Ref(raid_options)), "NONE"))
)
use_ebs_encryption = t.add_condition(
"Vol%s_UseEBSEncryption" % (i + 1), Equals(Select("6", Ref(raid_options)), "true")
)
use_ebs_kms_key = t.add_condition(
"Vol%s_UseEBSKMSKey" % (i + 1),
And(Condition(use_ebs_encryption), Not(Equals(Select("7", Ref(raid_options)), "NONE"))),
)
v[i] = t.add_resource(
ec2.Volume(
"Volume%s" % (i + 1),
AvailabilityZone=Ref(availability_zone),
VolumeType=If(use_volume_type, Select("3", Ref(raid_options)), "gp2"),
Size=If(use_volume_size, Select("4", Ref(raid_options)), 20),
Iops=If(use_ebs_iops, Select("5", Ref(raid_options)), NoValue),
Encrypted=If(use_ebs_encryption, Select("6", Ref(raid_options)), NoValue),
KmsKeyId=If(use_ebs_kms_key, Select("7", Ref(raid_options)), NoValue),
Condition=use_vol[i],
)
)
outputs = [None] * number_of_vol
vol_to_return = [None] * number_of_vol
for i in range(number_of_vol):
vol_to_return[i] = Ref(v[i])
if i == 0:
outputs[i] = If(use_vol[i], vol_to_return[i], "NONE")
else:
outputs[i] = If(use_vol[i], Join(",", vol_to_return[: (i + 1)]), outputs[i - 1])
t.add_output(
Output("Volumeids", Description="Volume IDs of the resulted RAID EBS volumes", Value=outputs[number_of_vol - 1])
)
json_file_path = args.target_path
output_file = open(json_file_path, "w")
output_file.write(t.to_json())
output_file.close()
示例10: Equals
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
"KeyName",
ConstraintDescription="Can contain only ASCII characters.",
Type="AWS::EC2::KeyPair::KeyName",
Description="Name of an existing EC2 KeyPair to enable SSH access to the instance",
))
UseEBS = t.add_parameter(Parameter(
"UseEBS",
Default="no",
ConstraintDescription="Must be yes or no only.",
Type="String",
Description="Use EBS Volumes for the Worker Node",
AllowedValues=["yes", "no"],
))
UseEBSBool = t.add_condition("UseEBSBool", Equals(Ref(UseEBS),"yes"))
t.add_mapping("SubnetConfig",
{'Public': {'CIDR': '10.0.0.0/24'}, 'VPC': {'CIDR': '10.0.0.0/16'}}
)
t.add_mapping("RHEL66",
{'ap-northeast-1': {'AMI': 'ami-a15666a0'},
'ap-southeast-1': {'AMI': 'ami-3813326a'},
'ap-southeast-2': {'AMI': 'ami-55e38e6f'},
'eu-west-1': {'AMI': 'ami-9cfd53eb'},
'sa-east-1': {'AMI': 'ami-995ce884'},
'us-east-1': {'AMI': 'ami-aed06ac6'},
'us-west-1': {'AMI': 'ami-69ccd92c'},
'us-west-2': {'AMI': 'ami-5fbcf36f'}}
)
示例11: generate_cloudformation_template
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
def generate_cloudformation_template():
enable_elb = sys.argv[1]
input_scaling_policies = ast.literal_eval(sys.argv[2])
input_alarms = ast.literal_eval(sys.argv[3])
enable_elb = enable_elb == 'True'
elb_listeners = ast.literal_eval(sys.argv[4])
template = Template()
template.add_description("""\
Configures Auto Scaling Group for the app""")
project_name = template.add_parameter(Parameter(
"Name",
Type="String",
Description="Instances will be tagged with this name",
))
scalecapacity = template.add_parameter(Parameter(
"ScaleCapacity",
Default="1",
Type="String",
Description="Number of api servers to run",
))
minsize = template.add_parameter(Parameter(
"MinScale",
Type="String",
Description="Minimum number of servers to keep in the ASG",
))
maxsize = template.add_parameter(Parameter(
"MaxScale",
Type="String",
Description="Maximum number of servers to keep in the ASG",
))
signalcount = template.add_parameter(Parameter(
"SignalCount",
Default="1",
Type="String",
Description="No. of signals CF must receive before it sets the status as CREATE_COMPLETE",
))
signaltimeout = template.add_parameter(Parameter(
"SignalTimeout",
Default="PT5M",
Type="String",
Description="Time that CF waits for the number of signals that was specified in Count ",
))
minsuccessfulinstancespercent = template.add_parameter(Parameter(
"MinSuccessfulInstancesPercent",
Default="100",
Type="String",
Description="% instances in a rolling update that must signal success for CF to succeed",
))
environment = template.add_parameter(Parameter(
"Environment",
Type="String",
Description="The environment being deployed into",
))
subnet = template.add_parameter(Parameter(
"Subnets",
Type="CommaDelimitedList",
))
launchconfigurationname = template.add_parameter(Parameter(
"LaunchConfigurationName",
Type="String",
))
health_check_grace_period = template.add_parameter(Parameter(
"HealthCheckGracePeriod",
Type="String",
Default="300",
))
if enable_elb:
elb_subnets = template.add_parameter(Parameter(
"LoadBalancerSubnets",
Type="CommaDelimitedList",
))
elb_bucket_name = template.add_parameter(Parameter(
"LoadBalancerBucketName",
Type="String",
Description="S3 Bucket for the ELB access logs"
))
template.add_condition("ElbLoggingCondition", Not(Equals(Ref(elb_bucket_name), "")))
elb_schema = template.add_parameter(Parameter(
"LoadBalancerSchema",
Type="String",
))
#.........这里部分代码省略.........
示例12: Equals
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
ConstraintDescription="Must be yes or no only.",
Type="String",
Description="Use EBS Volumes for the Master Node",
AllowedValues=["yes", "no"],
))
WorkerUseEBS = t.add_parameter(Parameter(
"WorkerUseEBS",
Default="no",
ConstraintDescription="Must be yes or no only.",
Type="String",
Description="Use EBS Volumes for the Worker Node",
AllowedValues=["yes", "no"],
))
MasterUseEBSBool = t.add_condition("MasterUseEBSBool", Equals(Ref("MasterUseEBS"),"yes"))
WorkerUseEBSBool = t.add_condition("WorkerUseEBSBool", Equals(Ref("WorkerUseEBS"),"yes"))
t.add_mapping("SubnetConfig",
{'Public': {'CIDR': '10.0.0.0/24'}, 'VPC': {'CIDR': '10.0.0.0/16'}}
)
t.add_mapping("RHEL66",
{'ap-northeast-1': {'AMI': 'ami-a15666a0'},
'ap-southeast-1': {'AMI': 'ami-3813326a'},
'ap-southeast-2': {'AMI': 'ami-55e38e6f'},
'eu-west-1': {'AMI': 'ami-9cfd53eb'},
'sa-east-1': {'AMI': 'ami-995ce884'},
'us-east-1': {'AMI': 'ami-aed06ac6'},
'us-west-1': {'AMI': 'ami-69ccd92c'},
'us-west-2': {'AMI': 'ami-5fbcf36f'}}
示例13: BaseTemplate
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
class BaseTemplate(object):
def __init__(self):
self._template = Template()
def add_description(self):
self._template.add_description(
self.description
)
def add_parameters(self):
for key, values in self.parameters.items():
self._template.add_parameter(
Parameter(key, **values)
)
def add_conditions(self):
for key, condition in self.conditions.items():
self._template.add_condition(
key, condition
)
def add_mappings(self):
for key, mapping in self.mappings.items():
self._template.add_mapping(
key, mapping
)
def add_outputs(self):
for logical_id, keys in self.outputs.items():
self._template.add_output(
Output(logical_id, **keys)
)
def add_resource(self, attr_name):
attr = getattr(self, attr_name)
if isinstance(attr, list):
if self.verify_list_of_resources(attr):
for item in attr:
self._template.add_resource(item)
elif isinstance(attr, BaseAWSObject):
self._template.add_resource(attr)
def verify_list_of_resources(self, attr):
for item in attr:
if not isinstance(item, BaseAWSObject):
return False
return True
def render(self, mappings):
if not mappings:
mappings = {}
self.mappings = mappings
self.add_mappings()
valid_attributes = get_class_attrs(self.__class__)
for attr in valid_attributes:
add_method = getattr(
self, 'add_%s' % attr, None
)
if add_method:
add_method()
else:
self.add_resource(attr)
return self._template.to_json()
示例14: Equals
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
ConstraintDescription="Can contain only ASCII characters.",
Type="AWS::EC2::KeyPair::KeyName",
Description="Name of an existing EC2 KeyPair to enable SSH access to the instance",
))
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"}
示例15: Not
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import add_condition [as 别名]
Description="EC2 instance type",
Default="m3.medium",
AllowedValues=[
"m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge",
"c1.medium", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge", "cg1.4xlarge"
],
ConstraintDescription="Must be a valid, EC2 classic "
"compatible instance type.",
))
# Conditions
template.add_condition(
"EIPProvided",
Not(
Equals(
Ref("EIP"),
"0.0.0.0"
)
)
)
# Define the instance security group
instance_sg = template.add_resource(
ec2.SecurityGroup(
"InstanceSecurityGroup",
GroupDescription="Enable SSH access to the world",
SecurityGroupIngress=[
ec2.SecurityGroupRule(
IpProtocol="tcp",
FromPort="22",
ToPort="22",