1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/requests/compute/delete_route.rb
2015-03-10 13:16:06 +01:00

57 lines
2.5 KiB
Ruby

module Fog
module Compute
class AWS
class Real
require 'fog/aws/parsers/compute/basic'
# Deletes the specified route from the specified route table.
#
# ==== Parameters
# * RouteTableId<~String> - The ID of the route table.
# * DestinationCidrBlock<~String> - The CIDR range for the route. The value you specify must match the CIDR for the route exactly.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - The ID of the request.
# * 'return'<~Boolean> - Returns true if the request succeeds. Otherwise, returns an error.
#
# {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteRoute.html]
def delete_route(route_table_id, destination_cidr_block)
request(
'Action' => 'DeleteRoute',
'RouteTableId' => route_table_id,
'DestinationCidrBlock' => destination_cidr_block,
:parser => Fog::Parsers::Compute::AWS::Basic.new
)
end
end
class Mock
def delete_route(route_table_id, destination_cidr_block)
route_table = self.data[:route_tables].find { |routetable| routetable["routeTableId"].eql? route_table_id }
unless route_table.nil?
route = route_table['routeSet'].find { |route| route["destinationCidrBlock"].eql? destination_cidr_block }
if !route.nil? && route['gatewayId'] != "local"
route_table['routeSet'].delete(route)
response = Excon::Response.new
response.status = 200
response.body = {
'requestId'=> Fog::AWS::Mock.request_id,
'return' => true
}
response
elsif route['gatewayId'] == "local"
# Cannot delete the default route
raise Fog::Compute::AWS::Error, "InvalidParameterValue => cannot remove local route #{destination_cidr_block} in route table #{route_table_id}"
else
raise Fog::Compute::AWS::NotFound.new("no route with destination-cidr-block #{destination_cidr_block} in route table #{route_table_id}")
end
else
raise Fog::Compute::AWS::NotFound.new("no route with destination-cidr-block #{destination_cidr_block} in route table #{route_table_id}")
end
end
end
end
end
end