Performance: Leverage jinja2's Environment to cache compiled Templates.
This commit is contained in:
parent
3a82f089a2
commit
9affa7753d
30 changed files with 228 additions and 235 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue