File: assign_private_ip_addresses.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 (55 lines) | stat: -rw-r--r-- 2,389 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
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/assign_private_ip_addresses'

        # Assigns one or more secondary private IP addresses to the specified network interface.
        #
        # ==== Parameters
        # * NetworkInterfaceId<~String> - The ID of the network interface
        # * PrivateIpAddresses<~Array> - One or more IP addresses to be assigned as a secondary private IP address (conditional)
        # * SecondaryPrivateIpAddressCount<~String> - The number of secondary IP addresses to assign (conditional)
        # * AllowReassignment<~Boolean> - Whether to reassign an IP address
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - The ID of the request.
        #     * 'return'<~Boolean> - success?
        #
        # {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-AssignPrivateIpAddresses.html]
        def assign_private_ip_addresses(network_interface_id, options={})
          if options['PrivateIpAddresses'] && options['SecondaryPrivateIpAddressCount']
            raise Fog::AWS::Compute::Error.new("You may specify secondaryPrivateIpAddressCount or specific secondary private IP addresses, but not both.")
          end

          if private_ip_addresses = options.delete('PrivateIpAddresses')
            options.merge!(Fog::AWS.indexed_param('PrivateIpAddress.%d', [*private_ip_addresses]))
          end

          request({
            'Action'  => 'AssignPrivateIpAddresses',
            'NetworkInterfaceId' => network_interface_id,
            :parser   => Fog::Parsers::AWS::Compute::AssignPrivateIpAddresses.new
          }.merge(options))
        end
      end

      class Mock
        def assign_private_ip_addresses(network_interface_id, options={})
          if options['PrivateIpAddresses'] && options['SecondaryPrivateIpAddressCount']
            raise Fog::AWS::Compute::Error.new("You may specify secondaryPrivateIpAddressCount or specific secondary private IP addresses, but not both.")
          end

          response = Excon::Response.new
          response.status = 200
          response.body = {
            'requestId' => Fog::AWS::Mock.request_id,
            'return' => true
          }
          response
        end
      end
    end
  end
end