File: disassociate_address.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (58 lines) | stat: -rw-r--r-- 2,239 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
58
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/basic'

        # Disassociate an elastic IP address from its instance (if any)
        #
        # ==== Parameters
        # * public_ip<~String> - Public ip to assign to instance
        # * association_id<~String> - Id associating eip to an network interface
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'return'<~Boolean> - success?
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DisassociateAddress.html]
        def disassociate_address(public_ip=nil, association_id=nil)
          request(
            'Action'        => 'DisassociateAddress',
            'PublicIp'      => public_ip,
            'AssociationId' => association_id,
            :idempotent     => true,
            :parser         => Fog::Parsers::AWS::Compute::Basic.new
          )
        end
      end

      class Mock
        def disassociate_address(public_ip, association_id=nil)
          response = Excon::Response.new
          response.status = 200
          if address = self.data[:addresses][public_ip]
            if address['allocationId'] && association_id.nil?
              raise Fog::AWS::Compute::Error.new("InvalidParameterValue => You must specify an association id when unmapping an address from a VPC instance")
            end
            instance_id = address['instanceId']
            if instance = self.data[:instances][instance_id]
              instance['ipAddress']         = instance['originalIpAddress']
              instance['dnsName']           = Fog::AWS::Mock.dns_name_for(instance['ipAddress'])
            end
            address['instanceId'] = nil
            response.status = 200
            response.body = {
              'requestId' => Fog::AWS::Mock.request_id,
              'return'    => true
            }
            response
          else
            raise Fog::AWS::Compute::Error.new("AuthFailure => The address '#{public_ip}' does not belong to you.")
          end
        end
      end
    end
  end
end