Performance: Leverage jinja2's Environment to cache compiled Templates.

This commit is contained in:
dreadpirateshawn 2014-12-12 12:46:07 -08:00
commit 9affa7753d
30 changed files with 228 additions and 235 deletions

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import instance_ids_from_querystring, image_ids_from_querystring, filters_from_querystring
@ -15,7 +13,7 @@ class AmisResponse(BaseResponse):
instance_ids = instance_ids_from_querystring(self.querystring)
instance_id = instance_ids[0]
image = self.ec2_backend.create_image(instance_id, name, description)
template = Template(CREATE_IMAGE_RESPONSE)
template = self.response_template(CREATE_IMAGE_RESPONSE)
return template.render(image=image)
def copy_image(self):
@ -24,26 +22,26 @@ class AmisResponse(BaseResponse):
name = self.querystring.get('Name')[0] if self.querystring.get('Name') else None
description = self.querystring.get('Description')[0] if self.querystring.get('Description') else None
image = self.ec2_backend.copy_image(source_image_id, source_region, name, description)
template = Template(COPY_IMAGE_RESPONSE)
template = self.response_template(COPY_IMAGE_RESPONSE)
return template.render(image=image)
def deregister_image(self):
ami_id = self.querystring.get('ImageId')[0]
success = self.ec2_backend.deregister_image(ami_id)
template = Template(DEREGISTER_IMAGE_RESPONSE)
template = self.response_template(DEREGISTER_IMAGE_RESPONSE)
return template.render(success=str(success).lower())
def describe_images(self):
ami_ids = image_ids_from_querystring(self.querystring)
filters = filters_from_querystring(self.querystring)
images = self.ec2_backend.describe_images(ami_ids=ami_ids, filters=filters)
template = Template(DESCRIBE_IMAGES_RESPONSE)
template = self.response_template(DESCRIBE_IMAGES_RESPONSE)
return template.render(images=images)
def describe_image_attribute(self):
ami_id = self.querystring.get('ImageId')[0]
groups = self.ec2_backend.get_launch_permission_groups(ami_id)
template = Template(DESCRIBE_IMAGE_ATTRIBUTES_RESPONSE)
template = self.response_template(DESCRIBE_IMAGE_ATTRIBUTES_RESPONSE)
return template.render(ami_id=ami_id, groups=groups)
def modify_image_attribute(self):

View file

@ -1,18 +1,16 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
class AvailabilityZonesAndRegions(BaseResponse):
def describe_availability_zones(self):
zones = self.ec2_backend.describe_availability_zones()
template = Template(DESCRIBE_ZONES_RESPONSE)
template = self.response_template(DESCRIBE_ZONES_RESPONSE)
return template.render(zones=zones)
def describe_regions(self):
regions = self.ec2_backend.describe_regions()
template = Template(DESCRIBE_REGIONS_RESPONSE)
template = self.response_template(DESCRIBE_REGIONS_RESPONSE)
return template.render(regions=regions)
DESCRIBE_REGIONS_RESPONSE = """<DescribeRegionsResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">

View file

@ -1,5 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import (
dhcp_configuration_from_querystring,
@ -16,7 +15,7 @@ class DHCPOptions(BaseResponse):
self.ec2_backend.associate_dhcp_options(dhcp_opt, vpc)
template = Template(ASSOCIATE_DHCP_OPTIONS_RESPONSE)
template = self.response_template(ASSOCIATE_DHCP_OPTIONS_RESPONSE)
return template.render()
def create_dhcp_options(self):
@ -38,13 +37,13 @@ class DHCPOptions(BaseResponse):
netbios_node_type=netbios_node_type
)
template = Template(CREATE_DHCP_OPTIONS_RESPONSE)
template = self.response_template(CREATE_DHCP_OPTIONS_RESPONSE)
return template.render(dhcp_options_set=dhcp_options_set)
def delete_dhcp_options(self):
dhcp_opt_id = self.querystring.get("DhcpOptionsId", [None])[0]
delete_status = self.ec2_backend.delete_dhcp_options_set(dhcp_opt_id)
template = Template(DELETE_DHCP_OPTIONS_RESPONSE)
template = self.response_template(DELETE_DHCP_OPTIONS_RESPONSE)
return template.render(delete_status=delete_status)
def describe_dhcp_options(self):
@ -55,7 +54,7 @@ class DHCPOptions(BaseResponse):
dhcp_opt = self.ec2_backend.describe_dhcp_options(dhcp_opt_ids)
else:
dhcp_opt = self.ec2_backend.describe_dhcp_options()
template = Template(DESCRIBE_DHCP_OPTIONS_RESPONSE)
template = self.response_template(DESCRIBE_DHCP_OPTIONS_RESPONSE)
return template.render(dhcp_options=dhcp_opt)

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
@ -11,7 +9,7 @@ class ElasticBlockStore(BaseResponse):
device_path = self.querystring.get('Device')[0]
attachment = self.ec2_backend.attach_volume(volume_id, instance_id, device_path)
template = Template(ATTACHED_VOLUME_RESPONSE)
template = self.response_template(ATTACHED_VOLUME_RESPONSE)
return template.render(attachment=attachment)
def copy_snapshot(self):
@ -23,14 +21,14 @@ class ElasticBlockStore(BaseResponse):
description = self.querystring.get('Description')[0]
volume_id = self.querystring.get('VolumeId')[0]
snapshot = self.ec2_backend.create_snapshot(volume_id, description)
template = Template(CREATE_SNAPSHOT_RESPONSE)
template = self.response_template(CREATE_SNAPSHOT_RESPONSE)
return template.render(snapshot=snapshot)
def create_volume(self):
size = self.querystring.get('Size')[0]
zone = self.querystring.get('AvailabilityZone')[0]
volume = self.ec2_backend.create_volume(size, zone)
template = Template(CREATE_VOLUME_RESPONSE)
template = self.response_template(CREATE_VOLUME_RESPONSE)
return template.render(volume=volume)
def delete_snapshot(self):
@ -45,12 +43,12 @@ class ElasticBlockStore(BaseResponse):
def describe_snapshots(self):
snapshots = self.ec2_backend.describe_snapshots()
template = Template(DESCRIBE_SNAPSHOTS_RESPONSE)
template = self.response_template(DESCRIBE_SNAPSHOTS_RESPONSE)
return template.render(snapshots=snapshots)
def describe_volumes(self):
volumes = self.ec2_backend.describe_volumes()
template = Template(DESCRIBE_VOLUMES_RESPONSE)
template = self.response_template(DESCRIBE_VOLUMES_RESPONSE)
return template.render(volumes=volumes)
def describe_volume_attribute(self):
@ -65,7 +63,7 @@ class ElasticBlockStore(BaseResponse):
device_path = self.querystring.get('Device')[0]
attachment = self.ec2_backend.detach_volume(volume_id, instance_id, device_path)
template = Template(DETATCH_VOLUME_RESPONSE)
template = self.response_template(DETATCH_VOLUME_RESPONSE)
return template.render(attachment=attachment)
def enable_volume_io(self):
@ -77,7 +75,7 @@ class ElasticBlockStore(BaseResponse):
def describe_snapshot_attribute(self):
snapshot_id = self.querystring.get('SnapshotId')[0]
groups = self.ec2_backend.get_create_volume_permission_groups(snapshot_id)
template = Template(DESCRIBE_SNAPSHOT_ATTRIBUTES_RESPONSE)
template = self.response_template(DESCRIBE_SNAPSHOT_ATTRIBUTES_RESPONSE)
return template.render(snapshot_id=snapshot_id, groups=groups)
def modify_snapshot_attribute(self):

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import sequence_from_querystring
@ -12,7 +10,7 @@ class ElasticIPAddresses(BaseResponse):
else:
domain = "standard"
address = self.ec2_backend.allocate_address(domain)
template = Template(ALLOCATE_ADDRESS_RESPONSE)
template = self.response_template(ALLOCATE_ADDRESS_RESPONSE)
return template.render(address=address)
def associate_address(self):
@ -39,11 +37,11 @@ class ElasticIPAddresses(BaseResponse):
else:
self.ec2_backend.raise_error("MissingParameter", "Invalid request, expect either instance or ENI.")
template = Template(ASSOCIATE_ADDRESS_RESPONSE)
template = self.response_template(ASSOCIATE_ADDRESS_RESPONSE)
return template.render(address=eip)
def describe_addresses(self):
template = Template(DESCRIBE_ADDRESS_RESPONSE)
template = self.response_template(DESCRIBE_ADDRESS_RESPONSE)
if "Filter.1.Name" in self.querystring:
raise NotImplementedError("Filtering not supported in describe_address.")
@ -65,7 +63,7 @@ class ElasticIPAddresses(BaseResponse):
else:
self.ec2_backend.raise_error("MissingParameter", "Invalid request, expect PublicIp/AssociationId parameter.")
return Template(DISASSOCIATE_ADDRESS_RESPONSE).render()
return self.response_template(DISASSOCIATE_ADDRESS_RESPONSE).render()
def release_address(self):
if "PublicIp" in self.querystring:
@ -75,7 +73,7 @@ class ElasticIPAddresses(BaseResponse):
else:
self.ec2_backend.raise_error("MissingParameter", "Invalid request, expect PublicIp/AllocationId parameter.")
return Template(RELEASE_ADDRESS_RESPONSE).render()
return self.response_template(RELEASE_ADDRESS_RESPONSE).render()
ALLOCATE_ADDRESS_RESPONSE = """<AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2013-07-15/">

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import sequence_from_querystring, filters_from_querystring
@ -12,13 +10,13 @@ class ElasticNetworkInterfaces(BaseResponse):
groups = sequence_from_querystring('SecurityGroupId', self.querystring)
subnet = self.ec2_backend.get_subnet(subnet_id)
eni = self.ec2_backend.create_network_interface(subnet, private_ip_address, groups)
template = Template(CREATE_NETWORK_INTERFACE_RESPONSE)
template = self.response_template(CREATE_NETWORK_INTERFACE_RESPONSE)
return template.render(eni=eni)
def delete_network_interface(self):
eni_id = self.querystring.get('NetworkInterfaceId')[0]
self.ec2_backend.delete_network_interface(eni_id)
template = Template(DELETE_NETWORK_INTERFACE_RESPONSE)
template = self.response_template(DELETE_NETWORK_INTERFACE_RESPONSE)
return template.render()
def describe_network_interface_attribute(self):
@ -28,7 +26,7 @@ class ElasticNetworkInterfaces(BaseResponse):
# Partially implemented. Supports only network-interface-id and group-id filters
filters = filters_from_querystring(self.querystring)
enis = self.ec2_backend.describe_network_interfaces(filters)
template = Template(DESCRIBE_NETWORK_INTERFACES_RESPONSE)
template = self.response_template(DESCRIBE_NETWORK_INTERFACES_RESPONSE)
return template.render(enis=enis)
def attach_network_interface(self):
@ -36,13 +34,13 @@ class ElasticNetworkInterfaces(BaseResponse):
instance_id = self.querystring.get('InstanceId')[0]
device_index = self.querystring.get('DeviceIndex')[0]
attachment_id = self.ec2_backend.attach_network_interface(eni_id, instance_id, device_index)
template = Template(ATTACH_NETWORK_INTERFACE_RESPONSE)
template = self.response_template(ATTACH_NETWORK_INTERFACE_RESPONSE)
return template.render(attachment_id=attachment_id)
def detach_network_interface(self):
attachment_id = self.querystring.get('AttachmentId')[0]
self.ec2_backend.detach_network_interface(attachment_id)
template = Template(DETACH_NETWORK_INTERFACE_RESPONSE)
template = self.response_template(DETACH_NETWORK_INTERFACE_RESPONSE)
return template.render()
def modify_network_interface_attribute(self):

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import instance_ids_from_querystring
@ -10,7 +8,7 @@ class General(BaseResponse):
self.instance_ids = instance_ids_from_querystring(self.querystring)
instance_id = self.instance_ids[0]
instance = self.ec2_backend.get_instance(instance_id)
template = Template(GET_CONSOLE_OUTPUT_RESULT)
template = self.response_template(GET_CONSOLE_OUTPUT_RESULT)
return template.render(instance=instance)

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.core.utils import camelcase_to_underscores
from moto.ec2.utils import instance_ids_from_querystring, filters_from_querystring, \
@ -16,7 +14,7 @@ class InstanceResponse(BaseResponse):
else:
reservations = self.ec2_backend.all_reservations(make_copy=True, filters=filter_dict)
template = Template(EC2_DESCRIBE_INSTANCES)
template = self.response_template(EC2_DESCRIBE_INSTANCES)
return template.render(reservations=reservations)
def run_instances(self):
@ -38,31 +36,31 @@ class InstanceResponse(BaseResponse):
key_name=key_name, security_group_ids=security_group_ids,
nics=nics, private_ip=private_ip, associate_public_ip=associate_public_ip)
template = Template(EC2_RUN_INSTANCES)
template = self.response_template(EC2_RUN_INSTANCES)
return template.render(reservation=new_reservation)
def terminate_instances(self):
instance_ids = instance_ids_from_querystring(self.querystring)
instances = self.ec2_backend.terminate_instances(instance_ids)
template = Template(EC2_TERMINATE_INSTANCES)
template = self.response_template(EC2_TERMINATE_INSTANCES)
return template.render(instances=instances)
def reboot_instances(self):
instance_ids = instance_ids_from_querystring(self.querystring)
instances = self.ec2_backend.reboot_instances(instance_ids)
template = Template(EC2_REBOOT_INSTANCES)
template = self.response_template(EC2_REBOOT_INSTANCES)
return template.render(instances=instances)
def stop_instances(self):
instance_ids = instance_ids_from_querystring(self.querystring)
instances = self.ec2_backend.stop_instances(instance_ids)
template = Template(EC2_STOP_INSTANCES)
template = self.response_template(EC2_STOP_INSTANCES)
return template.render(instances=instances)
def start_instances(self):
instance_ids = instance_ids_from_querystring(self.querystring)
instances = self.ec2_backend.start_instances(instance_ids)
template = Template(EC2_START_INSTANCES)
template = self.response_template(EC2_START_INSTANCES)
return template.render(instances=instances)
def describe_instance_status(self):
@ -77,7 +75,7 @@ class InstanceResponse(BaseResponse):
else:
instances = self.ec2_backend.all_running_instances()
template = Template(EC2_INSTANCE_STATUS)
template = self.response_template(EC2_INSTANCE_STATUS)
return template.render(instances=instances)
def describe_instance_attribute(self):
@ -90,9 +88,9 @@ class InstanceResponse(BaseResponse):
instance, value = self.ec2_backend.describe_instance_attribute(instance_id, key)
if key == "group_set":
template = Template(EC2_DESCRIBE_INSTANCE_GROUPSET_ATTRIBUTE)
template = self.response_template(EC2_DESCRIBE_INSTANCE_GROUPSET_ATTRIBUTE)
else:
template = Template(EC2_DESCRIBE_INSTANCE_ATTRIBUTE)
template = self.response_template(EC2_DESCRIBE_INSTANCE_ATTRIBUTE)
return template.render(instance=instance, attribute=attribute, value=value)

View file

@ -4,7 +4,6 @@ from moto.ec2.utils import (
sequence_from_querystring,
filters_from_querystring,
)
from jinja2 import Template
class InternetGateways(BaseResponse):
@ -12,18 +11,18 @@ class InternetGateways(BaseResponse):
igw_id = self.querystring.get("InternetGatewayId", [None])[0]
vpc_id = self.querystring.get("VpcId", [None])[0]
self.ec2_backend.attach_internet_gateway(igw_id, vpc_id)
template = Template(ATTACH_INTERNET_GATEWAY_RESPONSE)
template = self.response_template(ATTACH_INTERNET_GATEWAY_RESPONSE)
return template.render()
def create_internet_gateway(self):
igw = self.ec2_backend.create_internet_gateway()
template = Template(CREATE_INTERNET_GATEWAY_RESPONSE)
template = self.response_template(CREATE_INTERNET_GATEWAY_RESPONSE)
return template.render(internet_gateway=igw)
def delete_internet_gateway(self):
igw_id = self.querystring.get("InternetGatewayId", [None])[0]
self.ec2_backend.delete_internet_gateway(igw_id)
template = Template(DELETE_INTERNET_GATEWAY_RESPONSE)
template = self.response_template(DELETE_INTERNET_GATEWAY_RESPONSE)
return template.render()
def describe_internet_gateways(self):
@ -35,7 +34,7 @@ class InternetGateways(BaseResponse):
else:
igws = self.ec2_backend.describe_internet_gateways(filters=filter_dict)
template = Template(DESCRIBE_INTERNET_GATEWAYS_RESPONSE)
template = self.response_template(DESCRIBE_INTERNET_GATEWAYS_RESPONSE)
return template.render(internet_gateways=igws)
def detach_internet_gateway(self):
@ -44,7 +43,7 @@ class InternetGateways(BaseResponse):
igw_id = self.querystring.get("InternetGatewayId", [None])[0]
vpc_id = self.querystring.get("VpcId", [None])[0]
self.ec2_backend.detach_internet_gateway(igw_id, vpc_id)
template = Template(DETACH_INTERNET_GATEWAY_RESPONSE)
template = self.response_template(DETACH_INTERNET_GATEWAY_RESPONSE)
return template.render()

View file

@ -1,6 +1,5 @@
from __future__ import unicode_literals
import six
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import keypair_names_from_querystring, filters_from_querystring
@ -10,13 +9,13 @@ class KeyPairs(BaseResponse):
def create_key_pair(self):
name = self.querystring.get('KeyName')[0]
keypair = self.ec2_backend.create_key_pair(name)
template = Template(CREATE_KEY_PAIR_RESPONSE)
template = self.response_template(CREATE_KEY_PAIR_RESPONSE)
return template.render(**keypair)
def delete_key_pair(self):
name = self.querystring.get('KeyName')[0]
success = six.text_type(self.ec2_backend.delete_key_pair(name)).lower()
return Template(DELETE_KEY_PAIR_RESPONSE).render(success=success)
return self.response_template(DELETE_KEY_PAIR_RESPONSE).render(success=success)
def describe_key_pairs(self):
names = keypair_names_from_querystring(self.querystring)
@ -25,7 +24,7 @@ class KeyPairs(BaseResponse):
raise NotImplementedError('Using filters in KeyPairs.describe_key_pairs is not yet implemented')
keypairs = self.ec2_backend.describe_key_pairs(names)
template = Template(DESCRIBE_KEY_PAIRS_RESPONSE)
template = self.response_template(DESCRIBE_KEY_PAIRS_RESPONSE)
return template.render(keypairs=keypairs)
def import_key_pair(self):

View file

@ -1,5 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring, \
network_acl_ids_from_querystring
@ -10,7 +9,7 @@ class NetworkACLs(BaseResponse):
def create_network_acl(self):
vpc_id = self.querystring.get('VpcId')[0]
network_acl = self.ec2_backend.create_network_acl(vpc_id)
template = Template(CREATE_NETWORK_ACL_RESPONSE)
template = self.response_template(CREATE_NETWORK_ACL_RESPONSE)
return template.render(network_acl=network_acl)
def create_network_acl_entry(self):
@ -30,13 +29,13 @@ class NetworkACLs(BaseResponse):
egress, cidr_block, icmp_code, icmp_type,
port_range_from, port_range_to)
template = Template(CREATE_NETWORK_ACL_ENTRY_RESPONSE)
template = self.response_template(CREATE_NETWORK_ACL_ENTRY_RESPONSE)
return template.render(network_acl_entry=network_acl_entry)
def delete_network_acl(self):
network_acl_id = self.querystring.get('NetworkAclId')[0]
self.ec2_backend.delete_network_acl(network_acl_id)
template = Template(DELETE_NETWORK_ACL_ASSOCIATION)
template = self.response_template(DELETE_NETWORK_ACL_ASSOCIATION)
return template.render()
def delete_network_acl_entry(self):
@ -47,7 +46,7 @@ class NetworkACLs(BaseResponse):
network_acl_ids = network_acl_ids_from_querystring(self.querystring)
filters = filters_from_querystring(self.querystring)
network_acls = self.ec2_backend.get_all_network_acls(network_acl_ids, filters)
template = Template(DESCRIBE_NETWORK_ACL_RESPONSE)
template = self.response_template(DESCRIBE_NETWORK_ACL_RESPONSE)
return template.render(network_acls=network_acls)
def replace_network_acl_association(self):
@ -58,7 +57,7 @@ class NetworkACLs(BaseResponse):
association_id,
network_acl_id
)
template = Template(REPLACE_NETWORK_ACL_ASSOCIATION)
template = self.response_template(REPLACE_NETWORK_ACL_ASSOCIATION)
return template.render(association=association)
def replace_network_acl_entry(self):
@ -159,4 +158,4 @@ DELETE_NETWORK_ACL_ASSOCIATION = """
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<return>true</return>
</DeleteNetworkAclResponse>
"""
"""

View file

@ -1,16 +1,15 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import route_table_ids_from_querystring, filters_from_querystring, optional_from_querystring
class RouteTables(BaseResponse):
def associate_route_table(self):
route_table_id = self.querystring.get('RouteTableId')[0]
subnet_id = self.querystring.get('SubnetId')[0]
association_id = self.ec2_backend.associate_route_table(route_table_id, subnet_id)
template = Template(ASSOCIATE_ROUTE_TABLE_RESPONSE)
template = self.response_template(ASSOCIATE_ROUTE_TABLE_RESPONSE)
return template.render(association_id=association_id)
def create_route(self):
@ -28,39 +27,39 @@ class RouteTables(BaseResponse):
interface_id=interface_id,
vpc_peering_connection_id=pcx_id)
template = Template(CREATE_ROUTE_RESPONSE)
template = self.response_template(CREATE_ROUTE_RESPONSE)
return template.render()
def create_route_table(self):
vpc_id = self.querystring.get('VpcId')[0]
route_table = self.ec2_backend.create_route_table(vpc_id)
template = Template(CREATE_ROUTE_TABLE_RESPONSE)
template = self.response_template(CREATE_ROUTE_TABLE_RESPONSE)
return template.render(route_table=route_table)
def delete_route(self):
route_table_id = self.querystring.get('RouteTableId')[0]
destination_cidr_block = self.querystring.get('DestinationCidrBlock')[0]
self.ec2_backend.delete_route(route_table_id, destination_cidr_block)
template = Template(DELETE_ROUTE_RESPONSE)
template = self.response_template(DELETE_ROUTE_RESPONSE)
return template.render()
def delete_route_table(self):
route_table_id = self.querystring.get('RouteTableId')[0]
self.ec2_backend.delete_route_table(route_table_id)
template = Template(DELETE_ROUTE_TABLE_RESPONSE)
template = self.response_template(DELETE_ROUTE_TABLE_RESPONSE)
return template.render()
def describe_route_tables(self):
route_table_ids = route_table_ids_from_querystring(self.querystring)
filters = filters_from_querystring(self.querystring)
route_tables = self.ec2_backend.get_all_route_tables(route_table_ids, filters)
template = Template(DESCRIBE_ROUTE_TABLES_RESPONSE)
template = self.response_template(DESCRIBE_ROUTE_TABLES_RESPONSE)
return template.render(route_tables=route_tables)
def disassociate_route_table(self):
association_id = self.querystring.get('AssociationId')[0]
self.ec2_backend.disassociate_route_table(association_id)
template = Template(DISASSOCIATE_ROUTE_TABLE_RESPONSE)
template = self.response_template(DISASSOCIATE_ROUTE_TABLE_RESPONSE)
return template.render()
def replace_route(self):
@ -78,14 +77,14 @@ class RouteTables(BaseResponse):
interface_id=interface_id,
vpc_peering_connection_id=pcx_id)
template = Template(REPLACE_ROUTE_RESPONSE)
template = self.response_template(REPLACE_ROUTE_RESPONSE)
return template.render()
def replace_route_table_association(self):
route_table_id = self.querystring.get('RouteTableId')[0]
association_id = self.querystring.get('AssociationId')[0]
new_association_id = self.ec2_backend.replace_route_table_association(association_id, route_table_id)
template = Template(REPLACE_ROUTE_TABLE_ASSOCIATION_RESPONSE)
template = self.response_template(REPLACE_ROUTE_TABLE_ASSOCIATION_RESPONSE)
return template.render(association_id=new_association_id)

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring
@ -48,7 +46,7 @@ class SecurityGroups(BaseResponse):
description = self.querystring.get('GroupDescription', [None])[0]
vpc_id = self.querystring.get("VpcId", [None])[0]
group = self.ec2_backend.create_security_group(name, description, vpc_id=vpc_id)
template = Template(CREATE_SECURITY_GROUP_RESPONSE)
template = self.response_template(CREATE_SECURITY_GROUP_RESPONSE)
return template.render(group=group)
def delete_security_group(self):
@ -75,7 +73,7 @@ class SecurityGroups(BaseResponse):
filters=filters
)
template = Template(DESCRIBE_SECURITY_GROUPS_RESPONSE)
template = self.response_template(DESCRIBE_SECURITY_GROUPS_RESPONSE)
return template.render(groups=groups)
def revoke_security_group_egress(self):

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring
@ -17,7 +15,7 @@ class SpotInstances(BaseResponse):
def cancel_spot_instance_requests(self):
request_ids = self._get_multi_param('SpotInstanceRequestId')
requests = self.ec2_backend.cancel_spot_instance_requests(request_ids)
template = Template(CANCEL_SPOT_INSTANCES_TEMPLATE)
template = self.response_template(CANCEL_SPOT_INSTANCES_TEMPLATE)
return template.render(requests=requests)
def create_spot_datafeed_subscription(self):
@ -32,7 +30,7 @@ class SpotInstances(BaseResponse):
def describe_spot_instance_requests(self):
filters = filters_from_querystring(self.querystring)
requests = self.ec2_backend.describe_spot_instance_requests(filters=filters)
template = Template(DESCRIBE_SPOT_INSTANCES_TEMPLATE)
template = self.response_template(DESCRIBE_SPOT_INSTANCES_TEMPLATE)
return template.render(requests=requests)
def describe_spot_price_history(self):
@ -77,7 +75,7 @@ class SpotInstances(BaseResponse):
subnet_id=subnet_id,
)
template = Template(REQUEST_SPOT_INSTANCES_TEMPLATE)
template = self.response_template(REQUEST_SPOT_INSTANCES_TEMPLATE)
return template.render(requests=requests)

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring
@ -10,19 +8,19 @@ class Subnets(BaseResponse):
vpc_id = self.querystring.get('VpcId')[0]
cidr_block = self.querystring.get('CidrBlock')[0]
subnet = self.ec2_backend.create_subnet(vpc_id, cidr_block)
template = Template(CREATE_SUBNET_RESPONSE)
template = self.response_template(CREATE_SUBNET_RESPONSE)
return template.render(subnet=subnet)
def delete_subnet(self):
subnet_id = self.querystring.get('SubnetId')[0]
subnet = self.ec2_backend.delete_subnet(subnet_id)
template = Template(DELETE_SUBNET_RESPONSE)
template = self.response_template(DELETE_SUBNET_RESPONSE)
return template.render(subnet=subnet)
def describe_subnets(self):
filters = filters_from_querystring(self.querystring)
subnets = self.ec2_backend.get_all_subnets(filters)
template = Template(DESCRIBE_SUBNETS_RESPONSE)
template = self.response_template(DESCRIBE_SUBNETS_RESPONSE)
return template.render(subnets=subnets)

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.models import validate_resource_ids
from moto.ec2.utils import sequence_from_querystring, tags_from_query_string, filters_from_querystring
@ -26,7 +24,7 @@ class TagResponse(BaseResponse):
def describe_tags(self):
filters = filters_from_querystring(querystring_dict=self.querystring)
tags = self.ec2_backend.describe_tags(filters=filters)
template = Template(DESCRIBE_RESPONSE)
template = self.response_template(DESCRIBE_RESPONSE)
return template.render(tags=tags)

View file

@ -1,5 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring
@ -12,25 +11,25 @@ class VirtualPrivateGateways(BaseResponse):
vpn_gateway_id,
vpc_id
)
template = Template(ATTACH_VPN_GATEWAY_RESPONSE)
template = self.response_template(ATTACH_VPN_GATEWAY_RESPONSE)
return template.render(attachment=attachment)
def create_vpn_gateway(self):
type = self.querystring.get('Type', None)[0]
vpn_gateway = self.ec2_backend.create_vpn_gateway(type)
template = Template(CREATE_VPN_GATEWAY_RESPONSE)
template = self.response_template(CREATE_VPN_GATEWAY_RESPONSE)
return template.render(vpn_gateway=vpn_gateway)
def delete_vpn_gateway(self):
vpn_gateway_id = self.querystring.get('VpnGatewayId')[0]
vpn_gateway = self.ec2_backend.delete_vpn_gateway(vpn_gateway_id)
template = Template(DELETE_VPN_GATEWAY_RESPONSE)
template = self.response_template(DELETE_VPN_GATEWAY_RESPONSE)
return template.render(vpn_gateway=vpn_gateway)
def describe_vpn_gateways(self):
filters = filters_from_querystring(self.querystring)
vpn_gateways = self.ec2_backend.get_all_vpn_gateways(filters)
template = Template(DESCRIBE_VPN_GATEWAYS_RESPONSE)
template = self.response_template(DESCRIBE_VPN_GATEWAYS_RESPONSE)
return template.render(vpn_gateways=vpn_gateways)
def detach_vpn_gateway(self):
@ -40,7 +39,7 @@ class VirtualPrivateGateways(BaseResponse):
vpn_gateway_id,
vpc_id
)
template = Template(DETACH_VPN_GATEWAY_RESPONSE)
template = self.response_template(DETACH_VPN_GATEWAY_RESPONSE)
return template.render(attachment=attachment)
CREATE_VPN_GATEWAY_RESPONSE = """
@ -120,4 +119,4 @@ DETACH_VPN_GATEWAY_RESPONSE = """
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
<return>true</return>
</DetachVpnGatewayResponse>
"""
"""

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
@ -9,30 +7,30 @@ class VPCPeeringConnections(BaseResponse):
vpc = self.ec2_backend.get_vpc(self.querystring.get('VpcId')[0])
peer_vpc = self.ec2_backend.get_vpc(self.querystring.get('PeerVpcId')[0])
vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc)
template = Template(CREATE_VPC_PEERING_CONNECTION_RESPONSE)
template = self.response_template(CREATE_VPC_PEERING_CONNECTION_RESPONSE)
return template.render(vpc_pcx=vpc_pcx)
def delete_vpc_peering_connection(self):
vpc_pcx_id = self.querystring.get('VpcPeeringConnectionId')[0]
vpc_pcx = self.ec2_backend.delete_vpc_peering_connection(vpc_pcx_id)
template = Template(DELETE_VPC_PEERING_CONNECTION_RESPONSE)
template = self.response_template(DELETE_VPC_PEERING_CONNECTION_RESPONSE)
return template.render(vpc_pcx=vpc_pcx)
def describe_vpc_peering_connections(self):
vpc_pcxs = self.ec2_backend.get_all_vpc_peering_connections()
template = Template(DESCRIBE_VPC_PEERING_CONNECTIONS_RESPONSE)
template = self.response_template(DESCRIBE_VPC_PEERING_CONNECTIONS_RESPONSE)
return template.render(vpc_pcxs=vpc_pcxs)
def accept_vpc_peering_connection(self):
vpc_pcx_id = self.querystring.get('VpcPeeringConnectionId')[0]
vpc_pcx = self.ec2_backend.accept_vpc_peering_connection(vpc_pcx_id)
template = Template(ACCEPT_VPC_PEERING_CONNECTION_RESPONSE)
template = self.response_template(ACCEPT_VPC_PEERING_CONNECTION_RESPONSE)
return template.render(vpc_pcx=vpc_pcx)
def reject_vpc_peering_connection(self):
vpc_pcx_id = self.querystring.get('VpcPeeringConnectionId')[0]
self.ec2_backend.reject_vpc_peering_connection(vpc_pcx_id)
template = Template(REJECT_VPC_PEERING_CONNECTION_RESPONSE)
template = self.response_template(REJECT_VPC_PEERING_CONNECTION_RESPONSE)
return template.render()

View file

@ -1,6 +1,4 @@
from __future__ import unicode_literals
from jinja2 import Template
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring, vpc_ids_from_querystring
@ -9,20 +7,20 @@ class VPCs(BaseResponse):
def create_vpc(self):
cidr_block = self.querystring.get('CidrBlock')[0]
vpc = self.ec2_backend.create_vpc(cidr_block)
template = Template(CREATE_VPC_RESPONSE)
template = self.response_template(CREATE_VPC_RESPONSE)
return template.render(vpc=vpc)
def delete_vpc(self):
vpc_id = self.querystring.get('VpcId')[0]
vpc = self.ec2_backend.delete_vpc(vpc_id)
template = Template(DELETE_VPC_RESPONSE)
template = self.response_template(DELETE_VPC_RESPONSE)
return template.render(vpc=vpc)
def describe_vpcs(self):
vpc_ids = vpc_ids_from_querystring(self.querystring)
filters = filters_from_querystring(self.querystring)
vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
template = Template(DESCRIBE_VPCS_RESPONSE)
template = self.response_template(DESCRIBE_VPCS_RESPONSE)
return template.render(vpcs=vpcs)