File: delete_route.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (57 lines) | stat: -rw-r--r-- 2,547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Fog
  module AWS
    class Compute
      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::AWS::Compute::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::AWS::Compute::Error, "InvalidParameterValue => cannot remove local route #{destination_cidr_block} in route table #{route_table_id}"
            else
              raise Fog::AWS::Compute::NotFound.new("no route with destination-cidr-block #{destination_cidr_block} in route table #{route_table_id}")
            end
          else
            raise Fog::AWS::Compute::NotFound.new("no route with destination-cidr-block #{destination_cidr_block} in route table #{route_table_id}")
          end
        end
      end
    end
  end
end