Replaced direct querystring access with inherited _get_param

This commit is contained in:
Nuwan Goonasekera 2017-09-16 18:31:30 +05:30
commit 7ed1036ba8
18 changed files with 215 additions and 262 deletions

View file

@ -1,29 +1,25 @@
from __future__ import unicode_literals
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):
def associate_route_table(self):
route_table_id = self.querystring.get('RouteTableId')[0]
subnet_id = self.querystring.get('SubnetId')[0]
route_table_id = self._get_param('RouteTableId')
subnet_id = self._get_param('SubnetId')
association_id = self.ec2_backend.associate_route_table(
route_table_id, subnet_id)
template = self.response_template(ASSOCIATE_ROUTE_TABLE_RESPONSE)
return template.render(association_id=association_id)
def create_route(self):
route_table_id = self.querystring.get('RouteTableId')[0]
destination_cidr_block = self.querystring.get(
'DestinationCidrBlock')[0]
gateway_id = optional_from_querystring('GatewayId', self.querystring)
instance_id = optional_from_querystring('InstanceId', self.querystring)
interface_id = optional_from_querystring(
'NetworkInterfaceId', self.querystring)
pcx_id = optional_from_querystring(
'VpcPeeringConnectionId', self.querystring)
route_table_id = self._get_param('RouteTableId')
destination_cidr_block = self._get_param('DestinationCidrBlock')
gateway_id = self._get_param('GatewayId')
instance_id = self._get_param('InstanceId')
interface_id = self._get_param('NetworkInterfaceId')
pcx_id = self._get_param('VpcPeeringConnectionId')
self.ec2_backend.create_route(route_table_id, destination_cidr_block,
gateway_id=gateway_id,
@ -35,21 +31,20 @@ class RouteTables(BaseResponse):
return template.render()
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)
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]
route_table_id = self._get_param('RouteTableId')
destination_cidr_block = self._get_param('DestinationCidrBlock')
self.ec2_backend.delete_route(route_table_id, destination_cidr_block)
template = self.response_template(DELETE_ROUTE_RESPONSE)
return template.render()
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)
template = self.response_template(DELETE_ROUTE_TABLE_RESPONSE)
return template.render()
@ -63,22 +58,18 @@ class RouteTables(BaseResponse):
return template.render(route_tables=route_tables)
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)
template = self.response_template(DISASSOCIATE_ROUTE_TABLE_RESPONSE)
return template.render()
def replace_route(self):
route_table_id = self.querystring.get('RouteTableId')[0]
destination_cidr_block = self.querystring.get(
'DestinationCidrBlock')[0]
gateway_id = optional_from_querystring('GatewayId', self.querystring)
instance_id = optional_from_querystring('InstanceId', self.querystring)
interface_id = optional_from_querystring(
'NetworkInterfaceId', self.querystring)
pcx_id = optional_from_querystring(
'VpcPeeringConnectionId', self.querystring)
route_table_id = self._get_param('RouteTableId')
destination_cidr_block = self._get_param('DestinationCidrBlock')
gateway_id = self._get_param('GatewayId')
instance_id = self._get_param('InstanceId')
interface_id = self._get_param('NetworkInterfaceId')
pcx_id = self._get_param('VpcPeeringConnectionId')
self.ec2_backend.replace_route(route_table_id, destination_cidr_block,
gateway_id=gateway_id,
@ -90,8 +81,8 @@ class RouteTables(BaseResponse):
return template.render()
def replace_route_table_association(self):
route_table_id = self.querystring.get('RouteTableId')[0]
association_id = self.querystring.get('AssociationId')[0]
route_table_id = self._get_param('RouteTableId')
association_id = self._get_param('AssociationId')
new_association_id = self.ec2_backend.replace_route_table_association(
association_id, route_table_id)
template = self.response_template(