当前位置: 首页>>代码示例>>Python>>正文


Python ec2.Instance方法代码示例

本文整理汇总了Python中troposphere.ec2.Instance方法的典型用法代码示例。如果您正苦于以下问题:Python ec2.Instance方法的具体用法?Python ec2.Instance怎么用?Python ec2.Instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在troposphere.ec2的用法示例。


在下文中一共展示了ec2.Instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_record_with_given_hostname_target_instance

# 需要导入模块: from troposphere import ec2 [as 别名]
# 或者: from troposphere.ec2 import Instance [as 别名]
def test_create_record_with_given_hostname_target_instance():
    # used in cloudformation!
    instance = Instance('testEC2')

    result_record = route53.create_record(
        awsclient,
        'TESTPREFIX',
        instance,
        host_zone_name='TEST.HOST.ZONE.',
    )

    # Compare HostedZoneName
    assert_equal(result_record.HostedZoneName, 'TEST.HOST.ZONE.')
    # Compare Name : DNS name used as URL later on
    assert_equal(result_record.Name.data, {'Fn::Join': ['', ['TESTPREFIX.', 'TEST.HOST.ZONE.']]})
    # Compare ResourceRecords : The target for the route
    assert_equal(result_record.ResourceRecords[0].data, {'Fn::GetAtt': ['testEC2', 'PrivateIp']})
    # Compare Type
    assert_equal(result_record.Type, 'A')
    # Compare TTL
    assert_equal(result_record.TTL, route53.TTL_DEFAULT) 
开发者ID:glomex,项目名称:gcdt,代码行数:23,代码来源:test_route53_aws.py

示例2: ec2instance

# 需要导入模块: from troposphere import ec2 [as 别名]
# 或者: from troposphere.ec2 import Instance [as 别名]
def ec2instance(context, node):
    lu = partial(utils.lu, context)
    buildvars = build_vars(context, node)
    buildvars_serialization = bvars.encode_bvars(buildvars)

    odd = node % 2 == 1
    if odd:
        subnet_id = lu('project.aws.subnet-id')
    else:
        subnet_id = lu('project.aws.redundant-subnet-id')

    clean_server = _read_script('.clean-server.sh.fragment') # this file duplicates scripts/prep-stack.sh
    project_ec2 = {
        "ImageId": lu('project.aws.ec2.ami'),
        "InstanceType": context['ec2']['type'], # t2.small, m1.medium, etc
        "KeyName": Ref(KEYPAIR),
        "SecurityGroupIds": [Ref(SECURITY_GROUP_TITLE)],
        "SubnetId": subnet_id, # ll: "subnet-1d4eb46a"
        "Tags": instance_tags(context, node),

        # https://alestic.com/2010/12/ec2-user-data-output/
        "UserData": Base64("""#!/bin/bash
set -x
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
echo %s > /etc/build-vars.json.b64

%s""" % (buildvars_serialization, clean_server)),
    }
    return ec2.Instance(EC2_TITLE_NODE % node, **project_ec2) 
开发者ID:elifesciences,项目名称:builder,代码行数:31,代码来源:trop.py

示例3: create_record

# 需要导入模块: from troposphere import ec2 [as 别名]
# 或者: from troposphere.ec2 import Instance [as 别名]
def create_record(awsclient, name_prefix, instance_reference, type="A", host_zone_name=None):
    """
    Builds route53 record entries enabling DNS names for services
    Note: gcdt.route53 create_record(awsclient, ...)
    is used in dataplatform cloudformation.py templates!

    :param name_prefix: The sub domain prefix to use
    :param instance_reference: The EC2 troposphere reference which's private IP should be linked to
    :param type: The type of the record  A or CNAME (default: A)
    :param host_zone_name: The host zone name to use (like preprod.ds.glomex.cloud. - DO NOT FORGET THE DOT!)
    :return: RecordSetType
    """

    # Only fetch the host zone from the COPS stack if nessary
    if host_zone_name is None:
        host_zone_name = _retrieve_stack_host_zone_name(awsclient)

    if not (type == "A" or type == "CNAME"):
        raise Exception("Record set type is not supported!")

    name_of_record = name_prefix \
                         .replace('.', '') \
                         .replace('-', '') \
                         .title() + "HostRecord"

    # Reference EC2 instance automatically to their private IP
    if isinstance(instance_reference, Instance):
        resource_record = troposphere.GetAtt(
                instance_reference,
                "PrivateIp"
        )
    else:
        resource_record = instance_reference

    return RecordSetType(
            name_of_record,
            HostedZoneName=host_zone_name,
            Name=troposphere.Join("", [
                name_prefix + ".",
                host_zone_name,
            ]),
            Type=type,
            TTL=TTL_DEFAULT,
            ResourceRecords=[
                resource_record
            ],
    ) 
开发者ID:glomex,项目名称:gcdt,代码行数:49,代码来源:route53.py


注:本文中的troposphere.ec2.Instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。