當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。