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


Python moto.mock_ec2方法代码示例

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


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

示例1: boto_patches

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def boto_patches(context):
    mock_sqs_obj = mock_sqs()
    mock_sqs_obj.start()
    mock_ec2_obj = mock_ec2()
    mock_ec2_obj.start()
    mock_autoscaling_obj = mock_autoscaling()
    mock_autoscaling_obj.start()
    vpc_response = ec2.create_vpc(CidrBlock='10.0.0.0/24')
    subnet_response = ec2.create_subnet(
        CidrBlock='10.0.0.0/24',
        VpcId=vpc_response['Vpc']['VpcId'],
        AvailabilityZone='us-west-2a'
    )
    context.subnet_id = subnet_response['Subnet']['SubnetId']
    yield
    mock_sqs_obj.stop()
    mock_ec2_obj.stop()
    mock_autoscaling_obj.stop() 
开发者ID:Yelp,项目名称:clusterman,代码行数:20,代码来源:environment.py

示例2: sh

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def sh(self):
        with moto.mock_ec2(), moto.mock_s3(), moto.mock_iam(), moto.mock_kms():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
开发者ID:servian,项目名称:aws-auto-remediate,代码行数:6,代码来源:test_securityhub_iam.py

示例3: sh

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def sh(self):
        with moto.mock_ec2():
            sh = security_hub_rules.SecurityHubRules(logging)
            yield sh 
开发者ID:servian,项目名称:aws-auto-remediate,代码行数:6,代码来源:test_securityhub_ec2.py

示例4: moto_subnet

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def moto_subnet():
    with moto.mock_ec2():
        ec2 = boto3.resource("ec2", region_name="us-west-1")
        vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
        subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/24", AvailabilityZone="us-west-1a")
        yield subnet.id 
开发者ID:awslabs,项目名称:aws-data-wrangler,代码行数:8,代码来源:test_moto.py

示例5: ec2_client

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2_client(aws_region):
    with mock_ec2():
        yield boto3.client("ec2", region_name=aws_region) 
开发者ID:apache,项目名称:airflow,代码行数:5,代码来源:test_batch_waiters.py

示例6: test_class

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def test_class(self):
        with moto.mock_ec2():
            whitelist = {}
            settings = {
                "general": {"dry_run": False},
                "services": {"ec2": {"instances": {"clean": True, "ttl": -1}}},
            }
            resource_tree = {"AWS": {}}

            test_class = ec2_cleanup.EC2Cleanup(
                logging, whitelist, settings, resource_tree, "ap-southeast-2"
            )
            yield test_class 
开发者ID:servian,项目名称:aws-auto-cleanup,代码行数:15,代码来源:test_ec2.py

示例7: ec2

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2(sts, conn_dict):
    with mock_ec2():
        yield boto3_cached_conn("ec2", **conn_dict) 
开发者ID:Netflix-Skunkworks,项目名称:cloudaux,代码行数:5,代码来源:conftest.py

示例8: ec2

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2(ssh_key):
    """Mock EC2."""
    # Force moto to generate a deterministic key pair on creation.
    # Can be replaced by something more sensible when
    # https://github.com/spulec/moto/pull/2108 is merged

    key_pair = {'fingerprint': ssh_key.fingerprint,
                'material': ssh_key.private_key.decode('ascii')}
    with mock.patch('moto.ec2.models.random_key_pair', side_effect=[key_pair]):
        with mock_ec2():
            yield 
开发者ID:onicagroup,项目名称:runway,代码行数:13,代码来源:test_keypair.py

示例9: ec2_mock

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2_mock():
    mock = mock_ec2()
    mock_cw = mock_cloudwatch()

    mock.start()
    mock_cw.start()

    yield

    mock.stop()
    mock_cw.stop()

# Create a mock subnet_id 
开发者ID:asappresearch,项目名称:flambe,代码行数:15,代码来源:test_aws.py

示例10: ec2

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2(ssh_key):
    # Force moto to generate a deterministic key pair on creation.
    # Can be replaced by something more sensible when
    # https://github.com/spulec/moto/pull/2108 is merged

    key_pair = {'fingerprint': ssh_key.fingerprint,
                'material': ssh_key.private_key.decode('ascii')}
    with mock.patch('moto.ec2.models.random_key_pair', side_effect=[key_pair]):
        with mock_ec2():
            yield 
开发者ID:cloudtools,项目名称:stacker,代码行数:12,代码来源:test_keypair.py

示例11: setup_ec2

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def setup_ec2():
    mock_ec2_obj = moto.mock_ec2()
    mock_ec2_obj.start()
    yield
    mock_ec2_obj.stop() 
开发者ID:Yelp,项目名称:clusterman,代码行数:7,代码来源:conftest.py

示例12: ec2

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2():
    with mock_ec2():
        yield boto3.client("ec2", region_name="us-east-1") 
开发者ID:Netflix-Skunkworks,项目名称:diffy,代码行数:5,代码来源:conftest.py

示例13: ec2

# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_ec2 [as 别名]
def ec2():
    """EC2 mock service"""
    mock = mock_ec2()
    mock.start()

    ec2 = boto3.resource('ec2')
    ssh_server = ec2.create_instances(ImageId='ami-xxxxx', MinCount=1, MaxCount=1)
    for s in ssh_server:
        ec2.create_tags(
            Resources=[s.id],
            Tags=[{'Key': 'Name', 'Value': 'ssh_server'}])

    gateway_server = ec2.create_instances(ImageId='ami-xxxxx', MinCount=1, MaxCount=1)
    for s in gateway_server:
        ec2.create_tags(
            Resources=[s.id],
            Tags=[{'Key': 'Name', 'Value': 'gateway_server'}])

    server = ec2.create_instances(ImageId='ami-xxxxx', MinCount=1, MaxCount=1)
    servers = ec2.create_instances(ImageId='ami-xxxxx', MinCount=2, MaxCount=2)
    for i, s in enumerate(servers):
        ec2.create_tags(
            Resources=[s.id],
            Tags=[{'Key': 'Name', 'Value': 'server{:0>2d}'.format(i)}])

    yield dict(
        ec2=ec2,
        servers=servers,
        server=server[0],
        ssh_target_server=ssh_server[0],
        gateway_target_server=gateway_server[0],
    )

    mock.stop() 
开发者ID:achiku,项目名称:jungle,代码行数:36,代码来源:conftest.py


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