File: create_dhcp_options.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 (74 lines) | stat: -rw-r--r-- 2,751 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/create_dhcp_options'

        # Creates a set of DHCP options for your VPC
        #
        # ==== Parameters
        # * DhcpConfigurationOptions<~Hash> - hash of key value dhcp options to assign
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateDhcpOptions.html]
        def create_dhcp_options(dhcp_configurations = {})
          params = {}
          params.merge!(indexed_multidimensional_params(dhcp_configurations))
          request({
            'Action'    => 'CreateDhcpOptions',
            :idempotent => true,
            :parser     => Fog::Parsers::AWS::Compute::CreateDhcpOptions.new
          }.merge!(params))
        end
        private
          def indexed_multidimensional_params(multi_params)
            params = {}
            multi_params.keys.each_with_index do |key, key_index|
              key_index += 1
              params[format('DhcpConfiguration.%d.Key', key_index)] = key
              [*multi_params[key]].each_with_index do |value, value_index|
                value_index += 1
                params[format('DhcpConfiguration.%d.Value.%d', key_index, value_index)] = value
              end
            end
            params
         end
       end
      class Mock
        def create_dhcp_options(dhcp_configurations = {})
          params = {}
          params.merge!(indexed_multidimensional_params(dhcp_configurations))
          Excon::Response.new.tap do |response|
            response.status = 200
            self.data[:dhcp_options].push({
              'dhcpOptionsId' => Fog::AWS::Mock.dhcp_options_id,
              'dhcpConfigurationSet'  => {},
              'tagSet'             => {}
            })
            response.body = {
              'requestId'    => Fog::AWS::Mock.request_id,
              'dhcpOptionsSet'      => self.data[:dhcp_options]
            }
          end
        end
        private
          def indexed_multidimensional_params(multi_params)
            params = {}
            multi_params.keys.each_with_index do |key, key_index|
              key_index += 1
              params[format('DhcpConfiguration.%d.Key', key_index)] = key
              [*multi_params[key]].each_with_index do |value, value_index|
                value_index += 1
                params[format('DhcpConfiguration.%d.Value.%d', key_index, value_index)] = value
              end
            end
            params
         end
      end
    end
  end
end