本文整理汇总了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()
示例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
示例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
示例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
示例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)
示例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
示例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)
示例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
示例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
示例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
示例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()
示例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")
示例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()