File: disassociate_route_table.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (54 lines) | stat: -rw-r--r-- 2,106 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
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/basic'

        # Disassociates a subnet from a route table.
        #
        # ==== Parameters
        # * AssociationId<~String> - The association ID representing the current association between the route table and subnet.
        #
        # ==== 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-DisassociateRouteTable.html]
        def disassociate_route_table(association_id)
          request(
            'Action'        => 'DisassociateRouteTable',
            'AssociationId' => association_id,
            :parser         => Fog::Parsers::AWS::Compute::Basic.new
          )
        end
      end

      class Mock
        def disassociate_route_table(association_id)
          assoc_array = nil
          routetable = self.data[:route_tables].find { |routetable|
            assoc_array = routetable["associationSet"].find { |association|
              association['routeTableAssociationId'].eql? association_id
            }
          }
          if !assoc_array.nil? && assoc_array['main'] == false
            routetable['associationSet'].delete(assoc_array)
            response = Excon::Response.new
            response.status = 200
            response.body = {
                'requestId'     => Fog::AWS::Mock.request_id,
                'return'        => true
            }
            response
          elsif assoc_array.nil?
            raise Fog::AWS::Compute::NotFound.new("The association ID '#{association_id}' does not exist")
          elsif assoc_array['main'] == true
            raise Fog::AWS::Compute::Error, "InvalidParameterValue => cannot disassociate the main route table association #{association_id}"
          end
        end
      end
    end
  end
end