本文整理汇总了Python中troposphere.Template.set_description方法的典型用法代码示例。如果您正苦于以下问题:Python Template.set_description方法的具体用法?Python Template.set_description怎么用?Python Template.set_description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类troposphere.Template
的用法示例。
在下文中一共展示了Template.set_description方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from troposphere import Template [as 别名]
# 或者: from troposphere.Template import set_description [as 别名]
class VPCTemplateBuilder:
"""Build troposphere CFN templates for VPC creation."""
def __init__(self, vpc_config, description="VPC built by VPCBuilder"):
self.__template = Template()
self.__template.set_version("2010-09-09")
self.__template.set_description(description)
self.__vpc_config = vpc_config
def build(self):
"""Build the template."""
self.__build_template()
return self.__template
def __build_template(self):
vpc = self.__build_vpc()
internet_gateway = self.__build_internet_gateway(vpc)
nat_gateway = None
subnet_refs = []
for subnet in self.__vpc_config.subnets:
subnet_ref = self.__build_subnet(subnet, vpc)
subnet_refs.append(subnet_ref)
if subnet.has_nat_gateway:
nat_gateway = self.__build_nat_gateway(subnet, subnet_ref)
for subnet, subnet_ref in zip(self.__vpc_config.subnets, subnet_refs):
self.__build_route_table(subnet, subnet_ref, vpc, internet_gateway, nat_gateway)
def __build_vpc(self):
vpc_config = self.__vpc_config
vpc = self.__template.add_resource(
VPC(
vpc_config.name,
CidrBlock=vpc_config.cidr,
EnableDnsSupport=vpc_config.enable_dns_support,
EnableDnsHostnames=vpc_config.enable_dns_hostnames,
Tags=vpc_config.tags,
)
)
self.__template.add_output(Output("VpcId", Value=Ref(vpc), Description="VPC Id"))
return vpc
def __build_internet_gateway(self, vpc: VPC):
internet_gateway = self.__template.add_resource(
InternetGateway("InternetGateway", Tags=Tags(Name=Ref("AWS::StackName"), Stack=Ref("AWS::StackId")))
)
self.__template.add_resource(
VPCGatewayAttachment("VPCGatewayAttachment", VpcId=Ref(vpc), InternetGatewayId=Ref(internet_gateway))
)
return internet_gateway
def __build_subnet(self, subnet_config: SubnetConfig, vpc: VPC):
subnet = Subnet(
subnet_config.name,
CidrBlock=subnet_config.cidr,
VpcId=Ref(vpc),
MapPublicIpOnLaunch=subnet_config.map_public_ip_on_launch,
Tags=subnet_config.tags(),
)
if subnet_config.availability_zone:
subnet.AvailabilityZone = subnet_config.availability_zone
self.__template.add_resource(subnet)
self.__template.add_output(Output(subnet_config.name + "Id", Value=Ref(subnet)))
return subnet
def __build_nat_gateway(self, subnet_config: SubnetConfig, subnet_ref: Subnet):
nat_eip = self.__template.add_resource(EIP("NatEIP" + subnet_config.name, Domain="vpc"))
return self.__template.add_resource(
NatGateway(
"NatGateway" + subnet_config.name,
AllocationId=GetAtt(nat_eip, "AllocationId"),
SubnetId=Ref(subnet_ref),
)
)
def __build_route_table(
self,
subnet_config: SubnetConfig,
subnet_ref: Subnet,
vpc: VPC,
internet_gateway: InternetGateway,
nat_gateway: NatGateway,
):
route_table = self.__template.add_resource(
RouteTable(
"RouteTable" + subnet_config.name,
VpcId=Ref(vpc),
Tags=Tags(Name=Sub("${AWS::StackName}_route_table_" + subnet_config.name), Stack=Ref("AWS::StackId")),
)
)
self.__template.add_resource(
SubnetRouteTableAssociation(
"RouteAssociation" + subnet_config.name, SubnetId=Ref(subnet_ref), RouteTableId=Ref(route_table)
)
)
if subnet_config.default_gateway == Gateways.INTERNET_GATEWAY:
self.__template.add_resource(
Route(
"DefaultRoute" + subnet_config.name,
RouteTableId=Ref(route_table),
#.........这里部分代码省略.........