Replaced direct querystring access with inherited _get_param
This commit is contained in:
parent
17d62d9266
commit
7ed1036ba8
@ -7,10 +7,7 @@ class AmisResponse(BaseResponse):
|
|||||||
|
|
||||||
def create_image(self):
|
def create_image(self):
|
||||||
name = self.querystring.get('Name')[0]
|
name = self.querystring.get('Name')[0]
|
||||||
if "Description" in self.querystring:
|
description = self._get_param('Description', if_none='')
|
||||||
description = self.querystring.get('Description')[0]
|
|
||||||
else:
|
|
||||||
description = ""
|
|
||||||
instance_id = self._get_param('InstanceId')
|
instance_id = self._get_param('InstanceId')
|
||||||
if self.is_not_dryrun('CreateImage'):
|
if self.is_not_dryrun('CreateImage'):
|
||||||
image = self.ec2_backend.create_image(
|
image = self.ec2_backend.create_image(
|
||||||
@ -19,12 +16,10 @@ class AmisResponse(BaseResponse):
|
|||||||
return template.render(image=image)
|
return template.render(image=image)
|
||||||
|
|
||||||
def copy_image(self):
|
def copy_image(self):
|
||||||
source_image_id = self.querystring.get('SourceImageId')[0]
|
source_image_id = self._get_param('SourceImageId')
|
||||||
source_region = self.querystring.get('SourceRegion')[0]
|
source_region = self._get_param('SourceRegion')
|
||||||
name = self.querystring.get(
|
name = self._get_param('Name')
|
||||||
'Name')[0] if self.querystring.get('Name') else None
|
description = self._get_param('Description')
|
||||||
description = self.querystring.get(
|
|
||||||
'Description')[0] if self.querystring.get('Description') else None
|
|
||||||
if self.is_not_dryrun('CopyImage'):
|
if self.is_not_dryrun('CopyImage'):
|
||||||
image = self.ec2_backend.copy_image(
|
image = self.ec2_backend.copy_image(
|
||||||
source_image_id, source_region, name, description)
|
source_image_id, source_region, name, description)
|
||||||
@ -32,7 +27,7 @@ class AmisResponse(BaseResponse):
|
|||||||
return template.render(image=image)
|
return template.render(image=image)
|
||||||
|
|
||||||
def deregister_image(self):
|
def deregister_image(self):
|
||||||
ami_id = self.querystring.get('ImageId')[0]
|
ami_id = self._get_param('ImageId')
|
||||||
if self.is_not_dryrun('DeregisterImage'):
|
if self.is_not_dryrun('DeregisterImage'):
|
||||||
success = self.ec2_backend.deregister_image(ami_id)
|
success = self.ec2_backend.deregister_image(ami_id)
|
||||||
template = self.response_template(DEREGISTER_IMAGE_RESPONSE)
|
template = self.response_template(DEREGISTER_IMAGE_RESPONSE)
|
||||||
@ -48,16 +43,16 @@ class AmisResponse(BaseResponse):
|
|||||||
return template.render(images=images)
|
return template.render(images=images)
|
||||||
|
|
||||||
def describe_image_attribute(self):
|
def describe_image_attribute(self):
|
||||||
ami_id = self.querystring.get('ImageId')[0]
|
ami_id = self._get_param('ImageId')
|
||||||
groups = self.ec2_backend.get_launch_permission_groups(ami_id)
|
groups = self.ec2_backend.get_launch_permission_groups(ami_id)
|
||||||
users = self.ec2_backend.get_launch_permission_users(ami_id)
|
users = self.ec2_backend.get_launch_permission_users(ami_id)
|
||||||
template = self.response_template(DESCRIBE_IMAGE_ATTRIBUTES_RESPONSE)
|
template = self.response_template(DESCRIBE_IMAGE_ATTRIBUTES_RESPONSE)
|
||||||
return template.render(ami_id=ami_id, groups=groups, users=users)
|
return template.render(ami_id=ami_id, groups=groups, users=users)
|
||||||
|
|
||||||
def modify_image_attribute(self):
|
def modify_image_attribute(self):
|
||||||
ami_id = self.querystring.get('ImageId')[0]
|
ami_id = self._get_param('ImageId')
|
||||||
operation_type = self.querystring.get('OperationType')[0]
|
operation_type = self._get_param('OperationType')
|
||||||
group = self.querystring.get('UserGroup.1', [None])[0]
|
group = self._get_param('UserGroup.1')
|
||||||
user_ids = self._get_multi_param('UserId')
|
user_ids = self._get_multi_param('UserId')
|
||||||
if self.is_not_dryrun('ModifyImageAttribute'):
|
if self.is_not_dryrun('ModifyImageAttribute'):
|
||||||
if (operation_type == 'add'):
|
if (operation_type == 'add'):
|
||||||
|
@ -7,16 +7,16 @@ class CustomerGateways(BaseResponse):
|
|||||||
|
|
||||||
def create_customer_gateway(self):
|
def create_customer_gateway(self):
|
||||||
# raise NotImplementedError('CustomerGateways(AmazonVPC).create_customer_gateway is not yet implemented')
|
# raise NotImplementedError('CustomerGateways(AmazonVPC).create_customer_gateway is not yet implemented')
|
||||||
type = self.querystring.get('Type', None)[0]
|
type = self._get_param('Type')
|
||||||
ip_address = self.querystring.get('IpAddress', None)[0]
|
ip_address = self._get_param('IpAddress')
|
||||||
bgp_asn = self.querystring.get('BgpAsn', None)[0]
|
bgp_asn = self._get_param('BgpAsn')
|
||||||
customer_gateway = self.ec2_backend.create_customer_gateway(
|
customer_gateway = self.ec2_backend.create_customer_gateway(
|
||||||
type, ip_address=ip_address, bgp_asn=bgp_asn)
|
type, ip_address=ip_address, bgp_asn=bgp_asn)
|
||||||
template = self.response_template(CREATE_CUSTOMER_GATEWAY_RESPONSE)
|
template = self.response_template(CREATE_CUSTOMER_GATEWAY_RESPONSE)
|
||||||
return template.render(customer_gateway=customer_gateway)
|
return template.render(customer_gateway=customer_gateway)
|
||||||
|
|
||||||
def delete_customer_gateway(self):
|
def delete_customer_gateway(self):
|
||||||
customer_gateway_id = self.querystring.get('CustomerGatewayId')[0]
|
customer_gateway_id = self._get_param('CustomerGatewayId')
|
||||||
delete_status = self.ec2_backend.delete_customer_gateway(
|
delete_status = self.ec2_backend.delete_customer_gateway(
|
||||||
customer_gateway_id)
|
customer_gateway_id)
|
||||||
template = self.response_template(DELETE_CUSTOMER_GATEWAY_RESPONSE)
|
template = self.response_template(DELETE_CUSTOMER_GATEWAY_RESPONSE)
|
||||||
|
@ -8,8 +8,8 @@ from moto.ec2.utils import (
|
|||||||
class DHCPOptions(BaseResponse):
|
class DHCPOptions(BaseResponse):
|
||||||
|
|
||||||
def associate_dhcp_options(self):
|
def associate_dhcp_options(self):
|
||||||
dhcp_opt_id = self.querystring.get("DhcpOptionsId", [None])[0]
|
dhcp_opt_id = self._get_param('DhcpOptionsId')
|
||||||
vpc_id = self.querystring.get("VpcId", [None])[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
|
|
||||||
dhcp_opt = self.ec2_backend.describe_dhcp_options([dhcp_opt_id])[0]
|
dhcp_opt = self.ec2_backend.describe_dhcp_options([dhcp_opt_id])[0]
|
||||||
vpc = self.ec2_backend.get_vpc(vpc_id)
|
vpc = self.ec2_backend.get_vpc(vpc_id)
|
||||||
@ -42,7 +42,7 @@ class DHCPOptions(BaseResponse):
|
|||||||
return template.render(dhcp_options_set=dhcp_options_set)
|
return template.render(dhcp_options_set=dhcp_options_set)
|
||||||
|
|
||||||
def delete_dhcp_options(self):
|
def delete_dhcp_options(self):
|
||||||
dhcp_opt_id = self.querystring.get("DhcpOptionsId", [None])[0]
|
dhcp_opt_id = self._get_param('DhcpOptionsId')
|
||||||
delete_status = self.ec2_backend.delete_dhcp_options_set(dhcp_opt_id)
|
delete_status = self.ec2_backend.delete_dhcp_options_set(dhcp_opt_id)
|
||||||
template = self.response_template(DELETE_DHCP_OPTIONS_RESPONSE)
|
template = self.response_template(DELETE_DHCP_OPTIONS_RESPONSE)
|
||||||
return template.render(delete_status=delete_status)
|
return template.render(delete_status=delete_status)
|
||||||
|
@ -6,9 +6,9 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class ElasticBlockStore(BaseResponse):
|
class ElasticBlockStore(BaseResponse):
|
||||||
|
|
||||||
def attach_volume(self):
|
def attach_volume(self):
|
||||||
volume_id = self.querystring.get('VolumeId')[0]
|
volume_id = self._get_param('VolumeId')
|
||||||
instance_id = self.querystring.get('InstanceId')[0]
|
instance_id = self._get_param('InstanceId')
|
||||||
device_path = self.querystring.get('Device')[0]
|
device_path = self._get_param('Device')
|
||||||
if self.is_not_dryrun('AttachVolume'):
|
if self.is_not_dryrun('AttachVolume'):
|
||||||
attachment = self.ec2_backend.attach_volume(
|
attachment = self.ec2_backend.attach_volume(
|
||||||
volume_id, instance_id, device_path)
|
volume_id, instance_id, device_path)
|
||||||
@ -21,18 +21,18 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
'ElasticBlockStore.copy_snapshot is not yet implemented')
|
'ElasticBlockStore.copy_snapshot is not yet implemented')
|
||||||
|
|
||||||
def create_snapshot(self):
|
def create_snapshot(self):
|
||||||
description = self.querystring.get('Description', [None])[0]
|
volume_id = self._get_param('VolumeId')
|
||||||
volume_id = self.querystring.get('VolumeId')[0]
|
description = self._get_param('Description')
|
||||||
if self.is_not_dryrun('CreateSnapshot'):
|
if self.is_not_dryrun('CreateSnapshot'):
|
||||||
snapshot = self.ec2_backend.create_snapshot(volume_id, description)
|
snapshot = self.ec2_backend.create_snapshot(volume_id, description)
|
||||||
template = self.response_template(CREATE_SNAPSHOT_RESPONSE)
|
template = self.response_template(CREATE_SNAPSHOT_RESPONSE)
|
||||||
return template.render(snapshot=snapshot)
|
return template.render(snapshot=snapshot)
|
||||||
|
|
||||||
def create_volume(self):
|
def create_volume(self):
|
||||||
size = self.querystring.get('Size', [None])[0]
|
size = self._get_param('Size')
|
||||||
zone = self.querystring.get('AvailabilityZone', [None])[0]
|
zone = self._get_param('AvailabilityZone')
|
||||||
snapshot_id = self.querystring.get('SnapshotId', [None])[0]
|
snapshot_id = self._get_param('SnapshotId')
|
||||||
encrypted = self.querystring.get('Encrypted', ['false'])[0]
|
encrypted = self._get_param('Encrypted', if_none=False)
|
||||||
if self.is_not_dryrun('CreateVolume'):
|
if self.is_not_dryrun('CreateVolume'):
|
||||||
volume = self.ec2_backend.create_volume(
|
volume = self.ec2_backend.create_volume(
|
||||||
size, zone, snapshot_id, encrypted)
|
size, zone, snapshot_id, encrypted)
|
||||||
@ -40,23 +40,20 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
return template.render(volume=volume)
|
return template.render(volume=volume)
|
||||||
|
|
||||||
def delete_snapshot(self):
|
def delete_snapshot(self):
|
||||||
snapshot_id = self.querystring.get('SnapshotId')[0]
|
snapshot_id = self._get_param('SnapshotId')
|
||||||
if self.is_not_dryrun('DeleteSnapshot'):
|
if self.is_not_dryrun('DeleteSnapshot'):
|
||||||
self.ec2_backend.delete_snapshot(snapshot_id)
|
self.ec2_backend.delete_snapshot(snapshot_id)
|
||||||
return DELETE_SNAPSHOT_RESPONSE
|
return DELETE_SNAPSHOT_RESPONSE
|
||||||
|
|
||||||
def delete_volume(self):
|
def delete_volume(self):
|
||||||
volume_id = self.querystring.get('VolumeId')[0]
|
volume_id = self._get_param('VolumeId')
|
||||||
if self.is_not_dryrun('DeleteVolume'):
|
if self.is_not_dryrun('DeleteVolume'):
|
||||||
self.ec2_backend.delete_volume(volume_id)
|
self.ec2_backend.delete_volume(volume_id)
|
||||||
return DELETE_VOLUME_RESPONSE
|
return DELETE_VOLUME_RESPONSE
|
||||||
|
|
||||||
def describe_snapshots(self):
|
def describe_snapshots(self):
|
||||||
filters = filters_from_querystring(self.querystring)
|
filters = filters_from_querystring(self.querystring)
|
||||||
# querystring for multiple snapshotids results in SnapshotId.1,
|
snapshot_ids = self._get_multi_param('SnapshotId')
|
||||||
# SnapshotId.2 etc
|
|
||||||
snapshot_ids = ','.join(
|
|
||||||
[','.join(s[1]) for s in self.querystring.items() if 'SnapshotId' in s[0]])
|
|
||||||
snapshots = self.ec2_backend.describe_snapshots(filters=filters)
|
snapshots = self.ec2_backend.describe_snapshots(filters=filters)
|
||||||
# Describe snapshots to handle filter on snapshot_ids
|
# Describe snapshots to handle filter on snapshot_ids
|
||||||
snapshots = [
|
snapshots = [
|
||||||
@ -66,10 +63,7 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
|
|
||||||
def describe_volumes(self):
|
def describe_volumes(self):
|
||||||
filters = filters_from_querystring(self.querystring)
|
filters = filters_from_querystring(self.querystring)
|
||||||
# querystring for multiple volumeids results in VolumeId.1, VolumeId.2
|
volume_ids = self._get_multi_param('VolumeId')
|
||||||
# etc
|
|
||||||
volume_ids = ','.join(
|
|
||||||
[','.join(v[1]) for v in self.querystring.items() if 'VolumeId' in v[0]])
|
|
||||||
volumes = self.ec2_backend.describe_volumes(filters=filters)
|
volumes = self.ec2_backend.describe_volumes(filters=filters)
|
||||||
# Describe volumes to handle filter on volume_ids
|
# Describe volumes to handle filter on volume_ids
|
||||||
volumes = [
|
volumes = [
|
||||||
@ -86,9 +80,9 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
'ElasticBlockStore.describe_volume_status is not yet implemented')
|
'ElasticBlockStore.describe_volume_status is not yet implemented')
|
||||||
|
|
||||||
def detach_volume(self):
|
def detach_volume(self):
|
||||||
volume_id = self.querystring.get('VolumeId')[0]
|
volume_id = self._get_param('VolumeId')
|
||||||
instance_id = self.querystring.get('InstanceId')[0]
|
instance_id = self._get_param('InstanceId')
|
||||||
device_path = self.querystring.get('Device')[0]
|
device_path = self._get_param('Device')
|
||||||
if self.is_not_dryrun('DetachVolume'):
|
if self.is_not_dryrun('DetachVolume'):
|
||||||
attachment = self.ec2_backend.detach_volume(
|
attachment = self.ec2_backend.detach_volume(
|
||||||
volume_id, instance_id, device_path)
|
volume_id, instance_id, device_path)
|
||||||
@ -106,7 +100,7 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
'ElasticBlockStore.import_volume is not yet implemented')
|
'ElasticBlockStore.import_volume is not yet implemented')
|
||||||
|
|
||||||
def describe_snapshot_attribute(self):
|
def describe_snapshot_attribute(self):
|
||||||
snapshot_id = self.querystring.get('SnapshotId')[0]
|
snapshot_id = self._get_param('SnapshotId')
|
||||||
groups = self.ec2_backend.get_create_volume_permission_groups(
|
groups = self.ec2_backend.get_create_volume_permission_groups(
|
||||||
snapshot_id)
|
snapshot_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
@ -114,10 +108,10 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
return template.render(snapshot_id=snapshot_id, groups=groups)
|
return template.render(snapshot_id=snapshot_id, groups=groups)
|
||||||
|
|
||||||
def modify_snapshot_attribute(self):
|
def modify_snapshot_attribute(self):
|
||||||
snapshot_id = self.querystring.get('SnapshotId')[0]
|
snapshot_id = self._get_param('SnapshotId')
|
||||||
operation_type = self.querystring.get('OperationType')[0]
|
operation_type = self._get_param('OperationType')
|
||||||
group = self.querystring.get('UserGroup.1', [None])[0]
|
group = self._get_param('UserGroup.1')
|
||||||
user_id = self.querystring.get('UserId.1', [None])[0]
|
user_id = self._get_param('UserId.1')
|
||||||
if self.is_not_dryrun('ModifySnapshotAttribute'):
|
if self.is_not_dryrun('ModifySnapshotAttribute'):
|
||||||
if (operation_type == 'add'):
|
if (operation_type == 'add'):
|
||||||
self.ec2_backend.add_create_volume_permission(
|
self.ec2_backend.add_create_volume_permission(
|
||||||
|
@ -6,10 +6,7 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class ElasticIPAddresses(BaseResponse):
|
class ElasticIPAddresses(BaseResponse):
|
||||||
|
|
||||||
def allocate_address(self):
|
def allocate_address(self):
|
||||||
if "Domain" in self.querystring:
|
domain = self._get_param('Domain', if_none='standard')
|
||||||
domain = self.querystring.get('Domain')[0]
|
|
||||||
else:
|
|
||||||
domain = "standard"
|
|
||||||
if self.is_not_dryrun('AllocateAddress'):
|
if self.is_not_dryrun('AllocateAddress'):
|
||||||
address = self.ec2_backend.allocate_address(domain)
|
address = self.ec2_backend.allocate_address(domain)
|
||||||
template = self.response_template(ALLOCATE_ADDRESS_RESPONSE)
|
template = self.response_template(ALLOCATE_ADDRESS_RESPONSE)
|
||||||
@ -20,26 +17,28 @@ class ElasticIPAddresses(BaseResponse):
|
|||||||
|
|
||||||
if "InstanceId" in self.querystring:
|
if "InstanceId" in self.querystring:
|
||||||
instance = self.ec2_backend.get_instance(
|
instance = self.ec2_backend.get_instance(
|
||||||
self.querystring['InstanceId'][0])
|
self._get_param('InstanceId'))
|
||||||
elif "NetworkInterfaceId" in self.querystring:
|
elif "NetworkInterfaceId" in self.querystring:
|
||||||
eni = self.ec2_backend.get_network_interface(
|
eni = self.ec2_backend.get_network_interface(
|
||||||
self.querystring['NetworkInterfaceId'][0])
|
self._get_param('NetworkInterfaceId'))
|
||||||
else:
|
else:
|
||||||
self.ec2_backend.raise_error(
|
self.ec2_backend.raise_error(
|
||||||
"MissingParameter", "Invalid request, expect InstanceId/NetworkId parameter.")
|
"MissingParameter", "Invalid request, expect InstanceId/NetworkId parameter.")
|
||||||
|
|
||||||
reassociate = False
|
reassociate = False
|
||||||
if "AllowReassociation" in self.querystring:
|
if "AllowReassociation" in self.querystring:
|
||||||
reassociate = self.querystring['AllowReassociation'][0] == "true"
|
reassociate = self._get_param('AllowReassociation') == "true"
|
||||||
|
|
||||||
if self.is_not_dryrun('AssociateAddress'):
|
if self.is_not_dryrun('AssociateAddress'):
|
||||||
if instance or eni:
|
if instance or eni:
|
||||||
if "PublicIp" in self.querystring:
|
if "PublicIp" in self.querystring:
|
||||||
eip = self.ec2_backend.associate_address(instance=instance, eni=eni, address=self.querystring[
|
eip = self.ec2_backend.associate_address(
|
||||||
'PublicIp'][0], reassociate=reassociate)
|
instance=instance, eni=eni,
|
||||||
|
address=self._get_param('PublicIp'), reassociate=reassociate)
|
||||||
elif "AllocationId" in self.querystring:
|
elif "AllocationId" in self.querystring:
|
||||||
eip = self.ec2_backend.associate_address(instance=instance, eni=eni, allocation_id=self.querystring[
|
eip = self.ec2_backend.associate_address(
|
||||||
'AllocationId'][0], reassociate=reassociate)
|
instance=instance, eni=eni,
|
||||||
|
allocation_id=self._get_param('AllocationId'), reassociate=reassociate)
|
||||||
else:
|
else:
|
||||||
self.ec2_backend.raise_error(
|
self.ec2_backend.raise_error(
|
||||||
"MissingParameter", "Invalid request, expect PublicIp/AllocationId parameter.")
|
"MissingParameter", "Invalid request, expect PublicIp/AllocationId parameter.")
|
||||||
@ -63,10 +62,10 @@ class ElasticIPAddresses(BaseResponse):
|
|||||||
if self.is_not_dryrun('DisAssociateAddress'):
|
if self.is_not_dryrun('DisAssociateAddress'):
|
||||||
if "PublicIp" in self.querystring:
|
if "PublicIp" in self.querystring:
|
||||||
self.ec2_backend.disassociate_address(
|
self.ec2_backend.disassociate_address(
|
||||||
address=self.querystring['PublicIp'][0])
|
address=self._get_param('PublicIp'))
|
||||||
elif "AssociationId" in self.querystring:
|
elif "AssociationId" in self.querystring:
|
||||||
self.ec2_backend.disassociate_address(
|
self.ec2_backend.disassociate_address(
|
||||||
association_id=self.querystring['AssociationId'][0])
|
association_id=self._get_param('AssociationId'))
|
||||||
else:
|
else:
|
||||||
self.ec2_backend.raise_error(
|
self.ec2_backend.raise_error(
|
||||||
"MissingParameter", "Invalid request, expect PublicIp/AssociationId parameter.")
|
"MissingParameter", "Invalid request, expect PublicIp/AssociationId parameter.")
|
||||||
@ -77,10 +76,10 @@ class ElasticIPAddresses(BaseResponse):
|
|||||||
if self.is_not_dryrun('ReleaseAddress'):
|
if self.is_not_dryrun('ReleaseAddress'):
|
||||||
if "PublicIp" in self.querystring:
|
if "PublicIp" in self.querystring:
|
||||||
self.ec2_backend.release_address(
|
self.ec2_backend.release_address(
|
||||||
address=self.querystring['PublicIp'][0])
|
address=self._get_param('PublicIp'))
|
||||||
elif "AllocationId" in self.querystring:
|
elif "AllocationId" in self.querystring:
|
||||||
self.ec2_backend.release_address(
|
self.ec2_backend.release_address(
|
||||||
allocation_id=self.querystring['AllocationId'][0])
|
allocation_id=self._get_param('AllocationId'))
|
||||||
else:
|
else:
|
||||||
self.ec2_backend.raise_error(
|
self.ec2_backend.raise_error(
|
||||||
"MissingParameter", "Invalid request, expect PublicIp/AllocationId parameter.")
|
"MissingParameter", "Invalid request, expect PublicIp/AllocationId parameter.")
|
||||||
|
@ -6,9 +6,8 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class ElasticNetworkInterfaces(BaseResponse):
|
class ElasticNetworkInterfaces(BaseResponse):
|
||||||
|
|
||||||
def create_network_interface(self):
|
def create_network_interface(self):
|
||||||
subnet_id = self.querystring.get('SubnetId')[0]
|
subnet_id = self._get_param('SubnetId')
|
||||||
private_ip_address = self.querystring.get(
|
private_ip_address = self._get_param('PrivateIpAddress')
|
||||||
'PrivateIpAddress', [None])[0]
|
|
||||||
groups = self._get_multi_param('SecurityGroupId')
|
groups = self._get_multi_param('SecurityGroupId')
|
||||||
subnet = self.ec2_backend.get_subnet(subnet_id)
|
subnet = self.ec2_backend.get_subnet(subnet_id)
|
||||||
if self.is_not_dryrun('CreateNetworkInterface'):
|
if self.is_not_dryrun('CreateNetworkInterface'):
|
||||||
@ -19,7 +18,7 @@ class ElasticNetworkInterfaces(BaseResponse):
|
|||||||
return template.render(eni=eni)
|
return template.render(eni=eni)
|
||||||
|
|
||||||
def delete_network_interface(self):
|
def delete_network_interface(self):
|
||||||
eni_id = self.querystring.get('NetworkInterfaceId')[0]
|
eni_id = self._get_param('NetworkInterfaceId')
|
||||||
if self.is_not_dryrun('DeleteNetworkInterface'):
|
if self.is_not_dryrun('DeleteNetworkInterface'):
|
||||||
self.ec2_backend.delete_network_interface(eni_id)
|
self.ec2_backend.delete_network_interface(eni_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
@ -38,9 +37,9 @@ class ElasticNetworkInterfaces(BaseResponse):
|
|||||||
return template.render(enis=enis)
|
return template.render(enis=enis)
|
||||||
|
|
||||||
def attach_network_interface(self):
|
def attach_network_interface(self):
|
||||||
eni_id = self.querystring.get('NetworkInterfaceId')[0]
|
eni_id = self._get_param('NetworkInterfaceId')
|
||||||
instance_id = self.querystring.get('InstanceId')[0]
|
instance_id = self._get_param('InstanceId')
|
||||||
device_index = self.querystring.get('DeviceIndex')[0]
|
device_index = self._get_param('DeviceIndex')
|
||||||
if self.is_not_dryrun('AttachNetworkInterface'):
|
if self.is_not_dryrun('AttachNetworkInterface'):
|
||||||
attachment_id = self.ec2_backend.attach_network_interface(
|
attachment_id = self.ec2_backend.attach_network_interface(
|
||||||
eni_id, instance_id, device_index)
|
eni_id, instance_id, device_index)
|
||||||
@ -49,7 +48,7 @@ class ElasticNetworkInterfaces(BaseResponse):
|
|||||||
return template.render(attachment_id=attachment_id)
|
return template.render(attachment_id=attachment_id)
|
||||||
|
|
||||||
def detach_network_interface(self):
|
def detach_network_interface(self):
|
||||||
attachment_id = self.querystring.get('AttachmentId')[0]
|
attachment_id = self._get_param('AttachmentId')
|
||||||
if self.is_not_dryrun('DetachNetworkInterface'):
|
if self.is_not_dryrun('DetachNetworkInterface'):
|
||||||
self.ec2_backend.detach_network_interface(attachment_id)
|
self.ec2_backend.detach_network_interface(attachment_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
@ -58,8 +57,8 @@ class ElasticNetworkInterfaces(BaseResponse):
|
|||||||
|
|
||||||
def modify_network_interface_attribute(self):
|
def modify_network_interface_attribute(self):
|
||||||
# Currently supports modifying one and only one security group
|
# Currently supports modifying one and only one security group
|
||||||
eni_id = self.querystring.get('NetworkInterfaceId')[0]
|
eni_id = self._get_param('NetworkInterfaceId')
|
||||||
group_id = self.querystring.get('SecurityGroupId.1')[0]
|
group_id = self._get_param('SecurityGroupId.1')
|
||||||
if self.is_not_dryrun('ModifyNetworkInterface'):
|
if self.is_not_dryrun('ModifyNetworkInterface'):
|
||||||
self.ec2_backend.modify_network_interface_attribute(
|
self.ec2_backend.modify_network_interface_attribute(
|
||||||
eni_id, group_id)
|
eni_id, group_id)
|
||||||
|
@ -3,7 +3,7 @@ from boto.ec2.instancetype import InstanceType
|
|||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
from moto.core.utils import camelcase_to_underscores
|
from moto.core.utils import camelcase_to_underscores
|
||||||
from moto.ec2.utils import filters_from_querystring, \
|
from moto.ec2.utils import filters_from_querystring, \
|
||||||
dict_from_querystring, optional_from_querystring
|
dict_from_querystring
|
||||||
|
|
||||||
|
|
||||||
class InstanceResponse(BaseResponse):
|
class InstanceResponse(BaseResponse):
|
||||||
@ -33,20 +33,18 @@ class InstanceResponse(BaseResponse):
|
|||||||
return template.render(reservations=reservations_resp, next_token=next_token)
|
return template.render(reservations=reservations_resp, next_token=next_token)
|
||||||
|
|
||||||
def run_instances(self):
|
def run_instances(self):
|
||||||
min_count = int(self.querystring.get('MinCount', ['1'])[0])
|
min_count = int(self._get_param('MinCount', if_none='1'))
|
||||||
image_id = self.querystring.get('ImageId')[0]
|
image_id = self._get_param('ImageId')
|
||||||
user_data = self.querystring.get('UserData')
|
user_data = self._get_param('UserData')
|
||||||
security_group_names = self._get_multi_param('SecurityGroup')
|
security_group_names = self._get_multi_param('SecurityGroup')
|
||||||
security_group_ids = self._get_multi_param('SecurityGroupId')
|
security_group_ids = self._get_multi_param('SecurityGroupId')
|
||||||
nics = dict_from_querystring("NetworkInterface", self.querystring)
|
nics = dict_from_querystring("NetworkInterface", self.querystring)
|
||||||
instance_type = self.querystring.get("InstanceType", ["m1.small"])[0]
|
instance_type = self._get_param('InstanceType', if_none='m1.small')
|
||||||
placement = self.querystring.get(
|
placement = self._get_param('Placement.AvailabilityZone')
|
||||||
"Placement.AvailabilityZone", [None])[0]
|
subnet_id = self._get_param('SubnetId')
|
||||||
subnet_id = self.querystring.get("SubnetId", [None])[0]
|
private_ip = self._get_param('PrivateIpAddress')
|
||||||
private_ip = self.querystring.get("PrivateIpAddress", [None])[0]
|
associate_public_ip = self._get_param('AssociatePublicIpAddress')
|
||||||
associate_public_ip = self.querystring.get(
|
key_name = self._get_param('KeyName')
|
||||||
"AssociatePublicIpAddress", [None])[0]
|
|
||||||
key_name = self.querystring.get("KeyName", [None])[0]
|
|
||||||
tags = self._parse_tag_specification("TagSpecification")
|
tags = self._parse_tag_specification("TagSpecification")
|
||||||
region_name = self.region
|
region_name = self.region
|
||||||
|
|
||||||
@ -91,8 +89,7 @@ class InstanceResponse(BaseResponse):
|
|||||||
|
|
||||||
def describe_instance_status(self):
|
def describe_instance_status(self):
|
||||||
instance_ids = self._get_multi_param('InstanceId')
|
instance_ids = self._get_multi_param('InstanceId')
|
||||||
include_all_instances = optional_from_querystring('IncludeAllInstances',
|
include_all_instances = self._get_param('IncludeAllInstances') == 'true'
|
||||||
self.querystring) == 'true'
|
|
||||||
|
|
||||||
if instance_ids:
|
if instance_ids:
|
||||||
instances = self.ec2_backend.get_multi_instances_by_id(
|
instances = self.ec2_backend.get_multi_instances_by_id(
|
||||||
@ -114,7 +111,7 @@ class InstanceResponse(BaseResponse):
|
|||||||
def describe_instance_attribute(self):
|
def describe_instance_attribute(self):
|
||||||
# TODO this and modify below should raise IncorrectInstanceState if
|
# TODO this and modify below should raise IncorrectInstanceState if
|
||||||
# instance not in stopped state
|
# instance not in stopped state
|
||||||
attribute = self.querystring.get("Attribute")[0]
|
attribute = self._get_param('Attribute')
|
||||||
key = camelcase_to_underscores(attribute)
|
key = camelcase_to_underscores(attribute)
|
||||||
instance_id = self._get_param('InstanceId')
|
instance_id = self._get_param('InstanceId')
|
||||||
instance, value = self.ec2_backend.describe_instance_attribute(
|
instance, value = self.ec2_backend.describe_instance_attribute(
|
||||||
|
@ -8,8 +8,8 @@ from moto.ec2.utils import (
|
|||||||
class InternetGateways(BaseResponse):
|
class InternetGateways(BaseResponse):
|
||||||
|
|
||||||
def attach_internet_gateway(self):
|
def attach_internet_gateway(self):
|
||||||
igw_id = self.querystring.get("InternetGatewayId", [None])[0]
|
igw_id = self._get_param('InternetGatewayId')
|
||||||
vpc_id = self.querystring.get("VpcId", [None])[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
if self.is_not_dryrun('AttachInternetGateway'):
|
if self.is_not_dryrun('AttachInternetGateway'):
|
||||||
self.ec2_backend.attach_internet_gateway(igw_id, vpc_id)
|
self.ec2_backend.attach_internet_gateway(igw_id, vpc_id)
|
||||||
template = self.response_template(ATTACH_INTERNET_GATEWAY_RESPONSE)
|
template = self.response_template(ATTACH_INTERNET_GATEWAY_RESPONSE)
|
||||||
@ -22,7 +22,7 @@ class InternetGateways(BaseResponse):
|
|||||||
return template.render(internet_gateway=igw)
|
return template.render(internet_gateway=igw)
|
||||||
|
|
||||||
def delete_internet_gateway(self):
|
def delete_internet_gateway(self):
|
||||||
igw_id = self.querystring.get("InternetGatewayId", [None])[0]
|
igw_id = self._get_param('InternetGatewayId')
|
||||||
if self.is_not_dryrun('DeleteInternetGateway'):
|
if self.is_not_dryrun('DeleteInternetGateway'):
|
||||||
self.ec2_backend.delete_internet_gateway(igw_id)
|
self.ec2_backend.delete_internet_gateway(igw_id)
|
||||||
template = self.response_template(DELETE_INTERNET_GATEWAY_RESPONSE)
|
template = self.response_template(DELETE_INTERNET_GATEWAY_RESPONSE)
|
||||||
@ -44,8 +44,8 @@ class InternetGateways(BaseResponse):
|
|||||||
def detach_internet_gateway(self):
|
def detach_internet_gateway(self):
|
||||||
# TODO validate no instances with EIPs in VPC before detaching
|
# TODO validate no instances with EIPs in VPC before detaching
|
||||||
# raise else DependencyViolationError()
|
# raise else DependencyViolationError()
|
||||||
igw_id = self.querystring.get("InternetGatewayId", [None])[0]
|
igw_id = self._get_param('InternetGatewayId')
|
||||||
vpc_id = self.querystring.get("VpcId", [None])[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
if self.is_not_dryrun('DetachInternetGateway'):
|
if self.is_not_dryrun('DetachInternetGateway'):
|
||||||
self.ec2_backend.detach_internet_gateway(igw_id, vpc_id)
|
self.ec2_backend.detach_internet_gateway(igw_id, vpc_id)
|
||||||
template = self.response_template(DETACH_INTERNET_GATEWAY_RESPONSE)
|
template = self.response_template(DETACH_INTERNET_GATEWAY_RESPONSE)
|
||||||
|
@ -7,14 +7,14 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class KeyPairs(BaseResponse):
|
class KeyPairs(BaseResponse):
|
||||||
|
|
||||||
def create_key_pair(self):
|
def create_key_pair(self):
|
||||||
name = self.querystring.get('KeyName')[0]
|
name = self._get_param('KeyName')
|
||||||
if self.is_not_dryrun('CreateKeyPair'):
|
if self.is_not_dryrun('CreateKeyPair'):
|
||||||
keypair = self.ec2_backend.create_key_pair(name)
|
keypair = self.ec2_backend.create_key_pair(name)
|
||||||
template = self.response_template(CREATE_KEY_PAIR_RESPONSE)
|
template = self.response_template(CREATE_KEY_PAIR_RESPONSE)
|
||||||
return template.render(keypair=keypair)
|
return template.render(keypair=keypair)
|
||||||
|
|
||||||
def delete_key_pair(self):
|
def delete_key_pair(self):
|
||||||
name = self.querystring.get('KeyName')[0]
|
name = self._get_param('KeyName')
|
||||||
if self.is_not_dryrun('DeleteKeyPair'):
|
if self.is_not_dryrun('DeleteKeyPair'):
|
||||||
success = six.text_type(
|
success = six.text_type(
|
||||||
self.ec2_backend.delete_key_pair(name)).lower()
|
self.ec2_backend.delete_key_pair(name)).lower()
|
||||||
@ -28,8 +28,8 @@ class KeyPairs(BaseResponse):
|
|||||||
return template.render(keypairs=keypairs)
|
return template.render(keypairs=keypairs)
|
||||||
|
|
||||||
def import_key_pair(self):
|
def import_key_pair(self):
|
||||||
name = self.querystring.get('KeyName')[0]
|
name = self._get_param('KeyName')
|
||||||
material = self.querystring.get('PublicKeyMaterial')[0]
|
material = self._get_param('PublicKeyMaterial')
|
||||||
if self.is_not_dryrun('ImportKeyPair'):
|
if self.is_not_dryrun('ImportKeyPair'):
|
||||||
keypair = self.ec2_backend.import_key_pair(name, material)
|
keypair = self.ec2_backend.import_key_pair(name, material)
|
||||||
template = self.response_template(IMPORT_KEYPAIR_RESPONSE)
|
template = self.response_template(IMPORT_KEYPAIR_RESPONSE)
|
||||||
|
@ -6,22 +6,22 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class NetworkACLs(BaseResponse):
|
class NetworkACLs(BaseResponse):
|
||||||
|
|
||||||
def create_network_acl(self):
|
def create_network_acl(self):
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
network_acl = self.ec2_backend.create_network_acl(vpc_id)
|
network_acl = self.ec2_backend.create_network_acl(vpc_id)
|
||||||
template = self.response_template(CREATE_NETWORK_ACL_RESPONSE)
|
template = self.response_template(CREATE_NETWORK_ACL_RESPONSE)
|
||||||
return template.render(network_acl=network_acl)
|
return template.render(network_acl=network_acl)
|
||||||
|
|
||||||
def create_network_acl_entry(self):
|
def create_network_acl_entry(self):
|
||||||
network_acl_id = self.querystring.get('NetworkAclId')[0]
|
network_acl_id = self._get_param('NetworkAclId')
|
||||||
rule_number = self.querystring.get('RuleNumber')[0]
|
rule_number = self._get_param('RuleNumber')
|
||||||
protocol = self.querystring.get('Protocol')[0]
|
protocol = self._get_param('Protocol')
|
||||||
rule_action = self.querystring.get('RuleAction')[0]
|
rule_action = self._get_param('RuleAction')
|
||||||
egress = self.querystring.get('Egress')[0]
|
egress = self._get_param('Egress')
|
||||||
cidr_block = self.querystring.get('CidrBlock')[0]
|
cidr_block = self._get_param('CidrBlock')
|
||||||
icmp_code = self.querystring.get('Icmp.Code', [None])[0]
|
icmp_code = self._get_param('Icmp.Code')
|
||||||
icmp_type = self.querystring.get('Icmp.Type', [None])[0]
|
icmp_type = self._get_param('Icmp.Type')
|
||||||
port_range_from = self.querystring.get('PortRange.From')[0]
|
port_range_from = self._get_param('PortRange.From')
|
||||||
port_range_to = self.querystring.get('PortRange.To')[0]
|
port_range_to = self._get_param('PortRange.To')
|
||||||
|
|
||||||
network_acl_entry = self.ec2_backend.create_network_acl_entry(
|
network_acl_entry = self.ec2_backend.create_network_acl_entry(
|
||||||
network_acl_id, rule_number, protocol, rule_action,
|
network_acl_id, rule_number, protocol, rule_action,
|
||||||
@ -32,30 +32,30 @@ class NetworkACLs(BaseResponse):
|
|||||||
return template.render(network_acl_entry=network_acl_entry)
|
return template.render(network_acl_entry=network_acl_entry)
|
||||||
|
|
||||||
def delete_network_acl(self):
|
def delete_network_acl(self):
|
||||||
network_acl_id = self.querystring.get('NetworkAclId')[0]
|
network_acl_id = self._get_param('NetworkAclId')
|
||||||
self.ec2_backend.delete_network_acl(network_acl_id)
|
self.ec2_backend.delete_network_acl(network_acl_id)
|
||||||
template = self.response_template(DELETE_NETWORK_ACL_ASSOCIATION)
|
template = self.response_template(DELETE_NETWORK_ACL_ASSOCIATION)
|
||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def delete_network_acl_entry(self):
|
def delete_network_acl_entry(self):
|
||||||
network_acl_id = self.querystring.get('NetworkAclId')[0]
|
network_acl_id = self._get_param('NetworkAclId')
|
||||||
rule_number = self.querystring.get('RuleNumber')[0]
|
rule_number = self._get_param('RuleNumber')
|
||||||
egress = self.querystring.get('Egress')[0]
|
egress = self._get_param('Egress')
|
||||||
self.ec2_backend.delete_network_acl_entry(network_acl_id, rule_number, egress)
|
self.ec2_backend.delete_network_acl_entry(network_acl_id, rule_number, egress)
|
||||||
template = self.response_template(DELETE_NETWORK_ACL_ENTRY_RESPONSE)
|
template = self.response_template(DELETE_NETWORK_ACL_ENTRY_RESPONSE)
|
||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def replace_network_acl_entry(self):
|
def replace_network_acl_entry(self):
|
||||||
network_acl_id = self.querystring.get('NetworkAclId')[0]
|
network_acl_id = self._get_param('NetworkAclId')
|
||||||
rule_number = self.querystring.get('RuleNumber')[0]
|
rule_number = self._get_param('RuleNumber')
|
||||||
protocol = self.querystring.get('Protocol')[0]
|
protocol = self._get_param('Protocol')
|
||||||
rule_action = self.querystring.get('RuleAction')[0]
|
rule_action = self._get_param('RuleAction')
|
||||||
egress = self.querystring.get('Egress')[0]
|
egress = self._get_param('Egress')
|
||||||
cidr_block = self.querystring.get('CidrBlock')[0]
|
cidr_block = self._get_param('CidrBlock')
|
||||||
icmp_code = self.querystring.get('Icmp.Code', [None])[0]
|
icmp_code = self._get_param('Icmp.Code')
|
||||||
icmp_type = self.querystring.get('Icmp.Type', [None])[0]
|
icmp_type = self._get_param('Icmp.Type')
|
||||||
port_range_from = self.querystring.get('PortRange.From')[0]
|
port_range_from = self._get_param('PortRange.From')
|
||||||
port_range_to = self.querystring.get('PortRange.To')[0]
|
port_range_to = self._get_param('PortRange.To')
|
||||||
|
|
||||||
self.ec2_backend.replace_network_acl_entry(
|
self.ec2_backend.replace_network_acl_entry(
|
||||||
network_acl_id, rule_number, protocol, rule_action,
|
network_acl_id, rule_number, protocol, rule_action,
|
||||||
@ -74,8 +74,8 @@ class NetworkACLs(BaseResponse):
|
|||||||
return template.render(network_acls=network_acls)
|
return template.render(network_acls=network_acls)
|
||||||
|
|
||||||
def replace_network_acl_association(self):
|
def replace_network_acl_association(self):
|
||||||
association_id = self.querystring.get('AssociationId')[0]
|
association_id = self._get_param('AssociationId')
|
||||||
network_acl_id = self.querystring.get('NetworkAclId')[0]
|
network_acl_id = self._get_param('NetworkAclId')
|
||||||
|
|
||||||
association = self.ec2_backend.replace_network_acl_association(
|
association = self.ec2_backend.replace_network_acl_association(
|
||||||
association_id,
|
association_id,
|
||||||
|
@ -1,29 +1,25 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
from moto.ec2.utils import filters_from_querystring, optional_from_querystring
|
from moto.ec2.utils import filters_from_querystring
|
||||||
|
|
||||||
|
|
||||||
class RouteTables(BaseResponse):
|
class RouteTables(BaseResponse):
|
||||||
|
|
||||||
def associate_route_table(self):
|
def associate_route_table(self):
|
||||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
route_table_id = self._get_param('RouteTableId')
|
||||||
subnet_id = self.querystring.get('SubnetId')[0]
|
subnet_id = self._get_param('SubnetId')
|
||||||
association_id = self.ec2_backend.associate_route_table(
|
association_id = self.ec2_backend.associate_route_table(
|
||||||
route_table_id, subnet_id)
|
route_table_id, subnet_id)
|
||||||
template = self.response_template(ASSOCIATE_ROUTE_TABLE_RESPONSE)
|
template = self.response_template(ASSOCIATE_ROUTE_TABLE_RESPONSE)
|
||||||
return template.render(association_id=association_id)
|
return template.render(association_id=association_id)
|
||||||
|
|
||||||
def create_route(self):
|
def create_route(self):
|
||||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
route_table_id = self._get_param('RouteTableId')
|
||||||
destination_cidr_block = self.querystring.get(
|
destination_cidr_block = self._get_param('DestinationCidrBlock')
|
||||||
'DestinationCidrBlock')[0]
|
gateway_id = self._get_param('GatewayId')
|
||||||
|
instance_id = self._get_param('InstanceId')
|
||||||
gateway_id = optional_from_querystring('GatewayId', self.querystring)
|
interface_id = self._get_param('NetworkInterfaceId')
|
||||||
instance_id = optional_from_querystring('InstanceId', self.querystring)
|
pcx_id = self._get_param('VpcPeeringConnectionId')
|
||||||
interface_id = optional_from_querystring(
|
|
||||||
'NetworkInterfaceId', self.querystring)
|
|
||||||
pcx_id = optional_from_querystring(
|
|
||||||
'VpcPeeringConnectionId', self.querystring)
|
|
||||||
|
|
||||||
self.ec2_backend.create_route(route_table_id, destination_cidr_block,
|
self.ec2_backend.create_route(route_table_id, destination_cidr_block,
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
@ -35,21 +31,20 @@ class RouteTables(BaseResponse):
|
|||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def create_route_table(self):
|
def create_route_table(self):
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
route_table = self.ec2_backend.create_route_table(vpc_id)
|
route_table = self.ec2_backend.create_route_table(vpc_id)
|
||||||
template = self.response_template(CREATE_ROUTE_TABLE_RESPONSE)
|
template = self.response_template(CREATE_ROUTE_TABLE_RESPONSE)
|
||||||
return template.render(route_table=route_table)
|
return template.render(route_table=route_table)
|
||||||
|
|
||||||
def delete_route(self):
|
def delete_route(self):
|
||||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
route_table_id = self._get_param('RouteTableId')
|
||||||
destination_cidr_block = self.querystring.get(
|
destination_cidr_block = self._get_param('DestinationCidrBlock')
|
||||||
'DestinationCidrBlock')[0]
|
|
||||||
self.ec2_backend.delete_route(route_table_id, destination_cidr_block)
|
self.ec2_backend.delete_route(route_table_id, destination_cidr_block)
|
||||||
template = self.response_template(DELETE_ROUTE_RESPONSE)
|
template = self.response_template(DELETE_ROUTE_RESPONSE)
|
||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def delete_route_table(self):
|
def delete_route_table(self):
|
||||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
route_table_id = self._get_param('RouteTableId')
|
||||||
self.ec2_backend.delete_route_table(route_table_id)
|
self.ec2_backend.delete_route_table(route_table_id)
|
||||||
template = self.response_template(DELETE_ROUTE_TABLE_RESPONSE)
|
template = self.response_template(DELETE_ROUTE_TABLE_RESPONSE)
|
||||||
return template.render()
|
return template.render()
|
||||||
@ -63,22 +58,18 @@ class RouteTables(BaseResponse):
|
|||||||
return template.render(route_tables=route_tables)
|
return template.render(route_tables=route_tables)
|
||||||
|
|
||||||
def disassociate_route_table(self):
|
def disassociate_route_table(self):
|
||||||
association_id = self.querystring.get('AssociationId')[0]
|
association_id = self._get_param('AssociationId')
|
||||||
self.ec2_backend.disassociate_route_table(association_id)
|
self.ec2_backend.disassociate_route_table(association_id)
|
||||||
template = self.response_template(DISASSOCIATE_ROUTE_TABLE_RESPONSE)
|
template = self.response_template(DISASSOCIATE_ROUTE_TABLE_RESPONSE)
|
||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def replace_route(self):
|
def replace_route(self):
|
||||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
route_table_id = self._get_param('RouteTableId')
|
||||||
destination_cidr_block = self.querystring.get(
|
destination_cidr_block = self._get_param('DestinationCidrBlock')
|
||||||
'DestinationCidrBlock')[0]
|
gateway_id = self._get_param('GatewayId')
|
||||||
|
instance_id = self._get_param('InstanceId')
|
||||||
gateway_id = optional_from_querystring('GatewayId', self.querystring)
|
interface_id = self._get_param('NetworkInterfaceId')
|
||||||
instance_id = optional_from_querystring('InstanceId', self.querystring)
|
pcx_id = self._get_param('VpcPeeringConnectionId')
|
||||||
interface_id = optional_from_querystring(
|
|
||||||
'NetworkInterfaceId', self.querystring)
|
|
||||||
pcx_id = optional_from_querystring(
|
|
||||||
'VpcPeeringConnectionId', self.querystring)
|
|
||||||
|
|
||||||
self.ec2_backend.replace_route(route_table_id, destination_cidr_block,
|
self.ec2_backend.replace_route(route_table_id, destination_cidr_block,
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
@ -90,8 +81,8 @@ class RouteTables(BaseResponse):
|
|||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
def replace_route_table_association(self):
|
def replace_route_table_association(self):
|
||||||
route_table_id = self.querystring.get('RouteTableId')[0]
|
route_table_id = self._get_param('RouteTableId')
|
||||||
association_id = self.querystring.get('AssociationId')[0]
|
association_id = self._get_param('AssociationId')
|
||||||
new_association_id = self.ec2_backend.replace_route_table_association(
|
new_association_id = self.ec2_backend.replace_route_table_association(
|
||||||
association_id, route_table_id)
|
association_id, route_table_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
|
@ -11,69 +11,66 @@ def try_parse_int(value, default=None):
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
def process_rules_from_querystring(querystring):
|
|
||||||
try:
|
|
||||||
group_name_or_id = querystring.get('GroupName')[0]
|
|
||||||
except:
|
|
||||||
group_name_or_id = querystring.get('GroupId')[0]
|
|
||||||
|
|
||||||
querytree = {}
|
|
||||||
for key, value in querystring.items():
|
|
||||||
key_splitted = key.split('.')
|
|
||||||
key_splitted = [try_parse_int(e, e) for e in key_splitted]
|
|
||||||
|
|
||||||
d = querytree
|
|
||||||
for subkey in key_splitted[:-1]:
|
|
||||||
if subkey not in d:
|
|
||||||
d[subkey] = {}
|
|
||||||
d = d[subkey]
|
|
||||||
d[key_splitted[-1]] = value
|
|
||||||
|
|
||||||
ip_permissions = querytree.get('IpPermissions') or {}
|
|
||||||
for ip_permission_idx in sorted(ip_permissions.keys()):
|
|
||||||
ip_permission = ip_permissions[ip_permission_idx]
|
|
||||||
|
|
||||||
ip_protocol = ip_permission.get('IpProtocol', [None])[0]
|
|
||||||
from_port = ip_permission.get('FromPort', [None])[0]
|
|
||||||
to_port = ip_permission.get('ToPort', [None])[0]
|
|
||||||
|
|
||||||
ip_ranges = []
|
|
||||||
ip_ranges_tree = ip_permission.get('IpRanges') or {}
|
|
||||||
for ip_range_idx in sorted(ip_ranges_tree.keys()):
|
|
||||||
ip_ranges.append(ip_ranges_tree[ip_range_idx]['CidrIp'][0])
|
|
||||||
|
|
||||||
source_groups = []
|
|
||||||
source_group_ids = []
|
|
||||||
groups_tree = ip_permission.get('Groups') or {}
|
|
||||||
for group_idx in sorted(groups_tree.keys()):
|
|
||||||
group_dict = groups_tree[group_idx]
|
|
||||||
if 'GroupId' in group_dict:
|
|
||||||
source_group_ids.append(group_dict['GroupId'][0])
|
|
||||||
elif 'GroupName' in group_dict:
|
|
||||||
source_groups.append(group_dict['GroupName'][0])
|
|
||||||
|
|
||||||
yield (group_name_or_id, ip_protocol, from_port, to_port, ip_ranges,
|
|
||||||
source_groups, source_group_ids)
|
|
||||||
|
|
||||||
|
|
||||||
class SecurityGroups(BaseResponse):
|
class SecurityGroups(BaseResponse):
|
||||||
|
|
||||||
|
def _process_rules_from_querystring(self):
|
||||||
|
group_name_or_id = (self._get_param('GroupName') or
|
||||||
|
self._get_param('GroupId'))
|
||||||
|
|
||||||
|
querytree = {}
|
||||||
|
for key, value in self.querystring.items():
|
||||||
|
key_splitted = key.split('.')
|
||||||
|
key_splitted = [try_parse_int(e, e) for e in key_splitted]
|
||||||
|
|
||||||
|
d = querytree
|
||||||
|
for subkey in key_splitted[:-1]:
|
||||||
|
if subkey not in d:
|
||||||
|
d[subkey] = {}
|
||||||
|
d = d[subkey]
|
||||||
|
d[key_splitted[-1]] = value
|
||||||
|
|
||||||
|
ip_permissions = querytree.get('IpPermissions') or {}
|
||||||
|
for ip_permission_idx in sorted(ip_permissions.keys()):
|
||||||
|
ip_permission = ip_permissions[ip_permission_idx]
|
||||||
|
|
||||||
|
ip_protocol = ip_permission.get('IpProtocol', [None])[0]
|
||||||
|
from_port = ip_permission.get('FromPort', [None])[0]
|
||||||
|
to_port = ip_permission.get('ToPort', [None])[0]
|
||||||
|
|
||||||
|
ip_ranges = []
|
||||||
|
ip_ranges_tree = ip_permission.get('IpRanges') or {}
|
||||||
|
for ip_range_idx in sorted(ip_ranges_tree.keys()):
|
||||||
|
ip_ranges.append(ip_ranges_tree[ip_range_idx]['CidrIp'][0])
|
||||||
|
|
||||||
|
source_groups = []
|
||||||
|
source_group_ids = []
|
||||||
|
groups_tree = ip_permission.get('Groups') or {}
|
||||||
|
for group_idx in sorted(groups_tree.keys()):
|
||||||
|
group_dict = groups_tree[group_idx]
|
||||||
|
if 'GroupId' in group_dict:
|
||||||
|
source_group_ids.append(group_dict['GroupId'][0])
|
||||||
|
elif 'GroupName' in group_dict:
|
||||||
|
source_groups.append(group_dict['GroupName'][0])
|
||||||
|
|
||||||
|
yield (group_name_or_id, ip_protocol, from_port, to_port, ip_ranges,
|
||||||
|
source_groups, source_group_ids)
|
||||||
|
|
||||||
def authorize_security_group_egress(self):
|
def authorize_security_group_egress(self):
|
||||||
if self.is_not_dryrun('GrantSecurityGroupEgress'):
|
if self.is_not_dryrun('GrantSecurityGroupEgress'):
|
||||||
for args in process_rules_from_querystring(self.querystring):
|
for args in self._process_rules_from_querystring():
|
||||||
self.ec2_backend.authorize_security_group_egress(*args)
|
self.ec2_backend.authorize_security_group_egress(*args)
|
||||||
return AUTHORIZE_SECURITY_GROUP_EGRESS_RESPONSE
|
return AUTHORIZE_SECURITY_GROUP_EGRESS_RESPONSE
|
||||||
|
|
||||||
def authorize_security_group_ingress(self):
|
def authorize_security_group_ingress(self):
|
||||||
if self.is_not_dryrun('GrantSecurityGroupIngress'):
|
if self.is_not_dryrun('GrantSecurityGroupIngress'):
|
||||||
for args in process_rules_from_querystring(self.querystring):
|
for args in self._process_rules_from_querystring():
|
||||||
self.ec2_backend.authorize_security_group_ingress(*args)
|
self.ec2_backend.authorize_security_group_ingress(*args)
|
||||||
return AUTHORIZE_SECURITY_GROUP_INGRESS_REPONSE
|
return AUTHORIZE_SECURITY_GROUP_INGRESS_REPONSE
|
||||||
|
|
||||||
def create_security_group(self):
|
def create_security_group(self):
|
||||||
name = self.querystring.get('GroupName')[0]
|
name = self._get_param('GroupName')
|
||||||
description = self.querystring.get('GroupDescription', [None])[0]
|
description = self._get_param('GroupDescription')
|
||||||
vpc_id = self.querystring.get("VpcId", [None])[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
|
|
||||||
if self.is_not_dryrun('CreateSecurityGroup'):
|
if self.is_not_dryrun('CreateSecurityGroup'):
|
||||||
group = self.ec2_backend.create_security_group(
|
group = self.ec2_backend.create_security_group(
|
||||||
@ -86,14 +83,14 @@ class SecurityGroups(BaseResponse):
|
|||||||
# See
|
# See
|
||||||
# http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteSecurityGroup.html
|
# http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteSecurityGroup.html
|
||||||
|
|
||||||
name = self.querystring.get('GroupName')
|
name = self._get_param('GroupName')
|
||||||
sg_id = self.querystring.get('GroupId')
|
sg_id = self._get_param('GroupId')
|
||||||
|
|
||||||
if self.is_not_dryrun('DeleteSecurityGroup'):
|
if self.is_not_dryrun('DeleteSecurityGroup'):
|
||||||
if name:
|
if name:
|
||||||
self.ec2_backend.delete_security_group(name[0])
|
self.ec2_backend.delete_security_group(name)
|
||||||
elif sg_id:
|
elif sg_id:
|
||||||
self.ec2_backend.delete_security_group(group_id=sg_id[0])
|
self.ec2_backend.delete_security_group(group_id=sg_id)
|
||||||
|
|
||||||
return DELETE_GROUP_RESPONSE
|
return DELETE_GROUP_RESPONSE
|
||||||
|
|
||||||
@ -113,7 +110,7 @@ class SecurityGroups(BaseResponse):
|
|||||||
|
|
||||||
def revoke_security_group_egress(self):
|
def revoke_security_group_egress(self):
|
||||||
if self.is_not_dryrun('RevokeSecurityGroupEgress'):
|
if self.is_not_dryrun('RevokeSecurityGroupEgress'):
|
||||||
for args in process_rules_from_querystring(self.querystring):
|
for args in self._process_rules_from_querystring():
|
||||||
success = self.ec2_backend.revoke_security_group_egress(*args)
|
success = self.ec2_backend.revoke_security_group_egress(*args)
|
||||||
if not success:
|
if not success:
|
||||||
return "Could not find a matching egress rule", dict(status=404)
|
return "Could not find a matching egress rule", dict(status=404)
|
||||||
@ -121,7 +118,7 @@ class SecurityGroups(BaseResponse):
|
|||||||
|
|
||||||
def revoke_security_group_ingress(self):
|
def revoke_security_group_ingress(self):
|
||||||
if self.is_not_dryrun('RevokeSecurityGroupIngress'):
|
if self.is_not_dryrun('RevokeSecurityGroupIngress'):
|
||||||
for args in process_rules_from_querystring(self.querystring):
|
for args in self._process_rules_from_querystring():
|
||||||
self.ec2_backend.revoke_security_group_ingress(*args)
|
self.ec2_backend.revoke_security_group_ingress(*args)
|
||||||
return REVOKE_SECURITY_GROUP_INGRESS_REPONSE
|
return REVOKE_SECURITY_GROUP_INGRESS_REPONSE
|
||||||
|
|
||||||
|
@ -7,14 +7,11 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class Subnets(BaseResponse):
|
class Subnets(BaseResponse):
|
||||||
|
|
||||||
def create_subnet(self):
|
def create_subnet(self):
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
cidr_block = self.querystring.get('CidrBlock')[0]
|
cidr_block = self._get_param('CidrBlock')
|
||||||
if 'AvailabilityZone' in self.querystring:
|
availability_zone = self._get_param(
|
||||||
availability_zone = self.querystring['AvailabilityZone'][0]
|
'AvailabilityZone', if_none=random.choice(
|
||||||
else:
|
self.ec2_backend.describe_availability_zones()).name)
|
||||||
zone = random.choice(
|
|
||||||
self.ec2_backend.describe_availability_zones())
|
|
||||||
availability_zone = zone.name
|
|
||||||
subnet = self.ec2_backend.create_subnet(
|
subnet = self.ec2_backend.create_subnet(
|
||||||
vpc_id,
|
vpc_id,
|
||||||
cidr_block,
|
cidr_block,
|
||||||
@ -24,30 +21,21 @@ class Subnets(BaseResponse):
|
|||||||
return template.render(subnet=subnet)
|
return template.render(subnet=subnet)
|
||||||
|
|
||||||
def delete_subnet(self):
|
def delete_subnet(self):
|
||||||
subnet_id = self.querystring.get('SubnetId')[0]
|
subnet_id = self._get_param('SubnetId')
|
||||||
subnet = self.ec2_backend.delete_subnet(subnet_id)
|
subnet = self.ec2_backend.delete_subnet(subnet_id)
|
||||||
template = self.response_template(DELETE_SUBNET_RESPONSE)
|
template = self.response_template(DELETE_SUBNET_RESPONSE)
|
||||||
return template.render(subnet=subnet)
|
return template.render(subnet=subnet)
|
||||||
|
|
||||||
def describe_subnets(self):
|
def describe_subnets(self):
|
||||||
|
subnet_ids = self._get_multi_param('SubnetId')
|
||||||
filters = filters_from_querystring(self.querystring)
|
filters = filters_from_querystring(self.querystring)
|
||||||
|
|
||||||
subnet_ids = []
|
|
||||||
idx = 1
|
|
||||||
key = 'SubnetId.{0}'.format(idx)
|
|
||||||
while key in self.querystring:
|
|
||||||
v = self.querystring[key]
|
|
||||||
subnet_ids.append(v[0])
|
|
||||||
idx += 1
|
|
||||||
key = 'SubnetId.{0}'.format(idx)
|
|
||||||
|
|
||||||
subnets = self.ec2_backend.get_all_subnets(subnet_ids, filters)
|
subnets = self.ec2_backend.get_all_subnets(subnet_ids, filters)
|
||||||
template = self.response_template(DESCRIBE_SUBNETS_RESPONSE)
|
template = self.response_template(DESCRIBE_SUBNETS_RESPONSE)
|
||||||
return template.render(subnets=subnets)
|
return template.render(subnets=subnets)
|
||||||
|
|
||||||
def modify_subnet_attribute(self):
|
def modify_subnet_attribute(self):
|
||||||
subnet_id = self.querystring.get('SubnetId')[0]
|
subnet_id = self._get_param('SubnetId')
|
||||||
map_public_ip = self.querystring.get('MapPublicIpOnLaunch.Value')[0]
|
map_public_ip = self._get_param('MapPublicIpOnLaunch.Value')
|
||||||
self.ec2_backend.modify_subnet_attribute(subnet_id, map_public_ip)
|
self.ec2_backend.modify_subnet_attribute(subnet_id, map_public_ip)
|
||||||
return MODIFY_SUBNET_ATTRIBUTE_RESPONSE
|
return MODIFY_SUBNET_ATTRIBUTE_RESPONSE
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class VirtualPrivateGateways(BaseResponse):
|
class VirtualPrivateGateways(BaseResponse):
|
||||||
|
|
||||||
def attach_vpn_gateway(self):
|
def attach_vpn_gateway(self):
|
||||||
vpn_gateway_id = self.querystring.get('VpnGatewayId')[0]
|
vpn_gateway_id = self._get_param('VpnGatewayId')
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
attachment = self.ec2_backend.attach_vpn_gateway(
|
attachment = self.ec2_backend.attach_vpn_gateway(
|
||||||
vpn_gateway_id,
|
vpn_gateway_id,
|
||||||
vpc_id
|
vpc_id
|
||||||
@ -16,13 +16,13 @@ class VirtualPrivateGateways(BaseResponse):
|
|||||||
return template.render(attachment=attachment)
|
return template.render(attachment=attachment)
|
||||||
|
|
||||||
def create_vpn_gateway(self):
|
def create_vpn_gateway(self):
|
||||||
type = self.querystring.get('Type', None)[0]
|
type = self._get_param('Type')
|
||||||
vpn_gateway = self.ec2_backend.create_vpn_gateway(type)
|
vpn_gateway = self.ec2_backend.create_vpn_gateway(type)
|
||||||
template = self.response_template(CREATE_VPN_GATEWAY_RESPONSE)
|
template = self.response_template(CREATE_VPN_GATEWAY_RESPONSE)
|
||||||
return template.render(vpn_gateway=vpn_gateway)
|
return template.render(vpn_gateway=vpn_gateway)
|
||||||
|
|
||||||
def delete_vpn_gateway(self):
|
def delete_vpn_gateway(self):
|
||||||
vpn_gateway_id = self.querystring.get('VpnGatewayId')[0]
|
vpn_gateway_id = self._get_param('VpnGatewayId')
|
||||||
vpn_gateway = self.ec2_backend.delete_vpn_gateway(vpn_gateway_id)
|
vpn_gateway = self.ec2_backend.delete_vpn_gateway(vpn_gateway_id)
|
||||||
template = self.response_template(DELETE_VPN_GATEWAY_RESPONSE)
|
template = self.response_template(DELETE_VPN_GATEWAY_RESPONSE)
|
||||||
return template.render(vpn_gateway=vpn_gateway)
|
return template.render(vpn_gateway=vpn_gateway)
|
||||||
@ -34,8 +34,8 @@ class VirtualPrivateGateways(BaseResponse):
|
|||||||
return template.render(vpn_gateways=vpn_gateways)
|
return template.render(vpn_gateways=vpn_gateways)
|
||||||
|
|
||||||
def detach_vpn_gateway(self):
|
def detach_vpn_gateway(self):
|
||||||
vpn_gateway_id = self.querystring.get('VpnGatewayId')[0]
|
vpn_gateway_id = self._get_param('VpnGatewayId')
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
attachment = self.ec2_backend.detach_vpn_gateway(
|
attachment = self.ec2_backend.detach_vpn_gateway(
|
||||||
vpn_gateway_id,
|
vpn_gateway_id,
|
||||||
vpc_id
|
vpc_id
|
||||||
|
@ -5,16 +5,15 @@ from moto.core.responses import BaseResponse
|
|||||||
class VPCPeeringConnections(BaseResponse):
|
class VPCPeeringConnections(BaseResponse):
|
||||||
|
|
||||||
def create_vpc_peering_connection(self):
|
def create_vpc_peering_connection(self):
|
||||||
vpc = self.ec2_backend.get_vpc(self.querystring.get('VpcId')[0])
|
vpc = self.ec2_backend.get_vpc(self._get_param('VpcId'))
|
||||||
peer_vpc = self.ec2_backend.get_vpc(
|
peer_vpc = self.ec2_backend.get_vpc(self._get_param('PeerVpcId'))
|
||||||
self.querystring.get('PeerVpcId')[0])
|
|
||||||
vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc)
|
vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
CREATE_VPC_PEERING_CONNECTION_RESPONSE)
|
CREATE_VPC_PEERING_CONNECTION_RESPONSE)
|
||||||
return template.render(vpc_pcx=vpc_pcx)
|
return template.render(vpc_pcx=vpc_pcx)
|
||||||
|
|
||||||
def delete_vpc_peering_connection(self):
|
def delete_vpc_peering_connection(self):
|
||||||
vpc_pcx_id = self.querystring.get('VpcPeeringConnectionId')[0]
|
vpc_pcx_id = self._get_param('VpcPeeringConnectionId')
|
||||||
vpc_pcx = self.ec2_backend.delete_vpc_peering_connection(vpc_pcx_id)
|
vpc_pcx = self.ec2_backend.delete_vpc_peering_connection(vpc_pcx_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
DELETE_VPC_PEERING_CONNECTION_RESPONSE)
|
DELETE_VPC_PEERING_CONNECTION_RESPONSE)
|
||||||
@ -27,14 +26,14 @@ class VPCPeeringConnections(BaseResponse):
|
|||||||
return template.render(vpc_pcxs=vpc_pcxs)
|
return template.render(vpc_pcxs=vpc_pcxs)
|
||||||
|
|
||||||
def accept_vpc_peering_connection(self):
|
def accept_vpc_peering_connection(self):
|
||||||
vpc_pcx_id = self.querystring.get('VpcPeeringConnectionId')[0]
|
vpc_pcx_id = self._get_param('VpcPeeringConnectionId')
|
||||||
vpc_pcx = self.ec2_backend.accept_vpc_peering_connection(vpc_pcx_id)
|
vpc_pcx = self.ec2_backend.accept_vpc_peering_connection(vpc_pcx_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
ACCEPT_VPC_PEERING_CONNECTION_RESPONSE)
|
ACCEPT_VPC_PEERING_CONNECTION_RESPONSE)
|
||||||
return template.render(vpc_pcx=vpc_pcx)
|
return template.render(vpc_pcx=vpc_pcx)
|
||||||
|
|
||||||
def reject_vpc_peering_connection(self):
|
def reject_vpc_peering_connection(self):
|
||||||
vpc_pcx_id = self.querystring.get('VpcPeeringConnectionId')[0]
|
vpc_pcx_id = self._get_param('VpcPeeringConnectionId')
|
||||||
self.ec2_backend.reject_vpc_peering_connection(vpc_pcx_id)
|
self.ec2_backend.reject_vpc_peering_connection(vpc_pcx_id)
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
REJECT_VPC_PEERING_CONNECTION_RESPONSE)
|
REJECT_VPC_PEERING_CONNECTION_RESPONSE)
|
||||||
|
@ -7,15 +7,14 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class VPCs(BaseResponse):
|
class VPCs(BaseResponse):
|
||||||
|
|
||||||
def create_vpc(self):
|
def create_vpc(self):
|
||||||
cidr_block = self.querystring.get('CidrBlock')[0]
|
cidr_block = self._get_param('CidrBlock')
|
||||||
instance_tenancy = self.querystring.get(
|
instance_tenancy = self._get_param('InstanceTenancy', if_none='default')
|
||||||
'InstanceTenancy', ['default'])[0]
|
|
||||||
vpc = self.ec2_backend.create_vpc(cidr_block, instance_tenancy)
|
vpc = self.ec2_backend.create_vpc(cidr_block, instance_tenancy)
|
||||||
template = self.response_template(CREATE_VPC_RESPONSE)
|
template = self.response_template(CREATE_VPC_RESPONSE)
|
||||||
return template.render(vpc=vpc)
|
return template.render(vpc=vpc)
|
||||||
|
|
||||||
def delete_vpc(self):
|
def delete_vpc(self):
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
vpc = self.ec2_backend.delete_vpc(vpc_id)
|
vpc = self.ec2_backend.delete_vpc(vpc_id)
|
||||||
template = self.response_template(DELETE_VPC_RESPONSE)
|
template = self.response_template(DELETE_VPC_RESPONSE)
|
||||||
return template.render(vpc=vpc)
|
return template.render(vpc=vpc)
|
||||||
@ -28,15 +27,15 @@ class VPCs(BaseResponse):
|
|||||||
return template.render(vpcs=vpcs)
|
return template.render(vpcs=vpcs)
|
||||||
|
|
||||||
def describe_vpc_attribute(self):
|
def describe_vpc_attribute(self):
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
attribute = self.querystring.get('Attribute')[0]
|
attribute = self._get_param('Attribute')
|
||||||
attr_name = camelcase_to_underscores(attribute)
|
attr_name = camelcase_to_underscores(attribute)
|
||||||
value = self.ec2_backend.describe_vpc_attribute(vpc_id, attr_name)
|
value = self.ec2_backend.describe_vpc_attribute(vpc_id, attr_name)
|
||||||
template = self.response_template(DESCRIBE_VPC_ATTRIBUTE_RESPONSE)
|
template = self.response_template(DESCRIBE_VPC_ATTRIBUTE_RESPONSE)
|
||||||
return template.render(vpc_id=vpc_id, attribute=attribute, value=value)
|
return template.render(vpc_id=vpc_id, attribute=attribute, value=value)
|
||||||
|
|
||||||
def modify_vpc_attribute(self):
|
def modify_vpc_attribute(self):
|
||||||
vpc_id = self.querystring.get('VpcId')[0]
|
vpc_id = self._get_param('VpcId')
|
||||||
|
|
||||||
for attribute in ('EnableDnsSupport', 'EnableDnsHostnames'):
|
for attribute in ('EnableDnsSupport', 'EnableDnsHostnames'):
|
||||||
if self.querystring.get('%s.Value' % attribute):
|
if self.querystring.get('%s.Value' % attribute):
|
||||||
|
@ -6,17 +6,17 @@ from moto.ec2.utils import filters_from_querystring
|
|||||||
class VPNConnections(BaseResponse):
|
class VPNConnections(BaseResponse):
|
||||||
|
|
||||||
def create_vpn_connection(self):
|
def create_vpn_connection(self):
|
||||||
type = self.querystring.get("Type", [None])[0]
|
type = self._get_param('Type')
|
||||||
cgw_id = self.querystring.get("CustomerGatewayId", [None])[0]
|
cgw_id = self._get_param('CustomerGatewayId')
|
||||||
vgw_id = self.querystring.get("VPNGatewayId", [None])[0]
|
vgw_id = self._get_param('VPNGatewayId')
|
||||||
static_routes = self.querystring.get("StaticRoutesOnly", [None])[0]
|
static_routes = self._get_param('StaticRoutesOnly')
|
||||||
vpn_connection = self.ec2_backend.create_vpn_connection(
|
vpn_connection = self.ec2_backend.create_vpn_connection(
|
||||||
type, cgw_id, vgw_id, static_routes_only=static_routes)
|
type, cgw_id, vgw_id, static_routes_only=static_routes)
|
||||||
template = self.response_template(CREATE_VPN_CONNECTION_RESPONSE)
|
template = self.response_template(CREATE_VPN_CONNECTION_RESPONSE)
|
||||||
return template.render(vpn_connection=vpn_connection)
|
return template.render(vpn_connection=vpn_connection)
|
||||||
|
|
||||||
def delete_vpn_connection(self):
|
def delete_vpn_connection(self):
|
||||||
vpn_connection_id = self.querystring.get('VpnConnectionId')[0]
|
vpn_connection_id = self._get_param('VpnConnectionId')
|
||||||
vpn_connection = self.ec2_backend.delete_vpn_connection(
|
vpn_connection = self.ec2_backend.delete_vpn_connection(
|
||||||
vpn_connection_id)
|
vpn_connection_id)
|
||||||
template = self.response_template(DELETE_VPN_CONNECTION_RESPONSE)
|
template = self.response_template(DELETE_VPN_CONNECTION_RESPONSE)
|
||||||
|
@ -230,11 +230,6 @@ def dhcp_configuration_from_querystring(querystring, option=u'DhcpConfiguration'
|
|||||||
return response_values
|
return response_values
|
||||||
|
|
||||||
|
|
||||||
def optional_from_querystring(parameter, querystring):
|
|
||||||
parameter_array = querystring.get(parameter)
|
|
||||||
return parameter_array[0] if parameter_array else None
|
|
||||||
|
|
||||||
|
|
||||||
def filters_from_querystring(querystring_dict):
|
def filters_from_querystring(querystring_dict):
|
||||||
response_values = {}
|
response_values = {}
|
||||||
for key, value in querystring_dict.items():
|
for key, value in querystring_dict.items():
|
||||||
|
Loading…
Reference in New Issue
Block a user