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

        # Modifies the specified attribute of the specified VPC.
        #
        # ==== Parameters
        # * vpc_id<~String> - The ID of the VPC.
        # * options<~Hash>:
        #   * enableDnsSupport<~Boolean> - Indicates whether DNS resolution is supported for the VPC. If this attribute is true, the Amazon DNS
        #     server resolves DNS hostnames for your instances to their corresponding IP addresses; otherwise, it does not.
        #   * enableDnsHostnames<~Boolean> - Indicates whether the instances launched in the VPC get DNS hostnames. If this attribute is true,
        #     instances in the VPC get DNS hostnames; otherwise, they do not. You can only set enableDnsHostnames to true if you also set the
        #     EnableDnsSupport attribute to true.
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'return'<~Boolean> - success?
        #
        # {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-ModifyVpcAttribute.html]
        def modify_vpc_attribute(vpc_id, options = {})
          request({
            'Action'             => 'ModifyVpcAttribute',
            'VpcId'              => vpc_id,
            :idempotent          => true,
            :parser              => Fog::Parsers::AWS::Compute::Basic.new
          }.merge!(options))
        end
      end

      class Mock
        def modify_vpc_attribute(vpc_id, options = {})
          response = Excon::Response.new
          if options.size == 0
            raise Fog::AWS::Compute::Error.new("InvalidParameterCombination => No attributes specified.")
          elsif options.size > 1
            raise Fog::AWS::Compute::Error.new("InvalidParameterCombination =>  InvalidParameterCombination => Fields for multiple attribute types specified: #{options.keys.join(', ')}")
          elsif vpc = self.data[:vpcs].find{ |v| v['vpcId'] == vpc_id }
            response.status = 200
            response.body = {
              'requestId' => Fog::AWS::Mock.request_id,
              'return'    => true
            }

            attribute = options.keys.first
            case attribute
            when 'EnableDnsSupport.Value'
              vpc['enableDnsSupport'] = options[attribute]
            when 'EnableDnsHostnames.Value'
              vpc['enableDnsHostnames'] = options[attribute]
            else
              raise Fog::AWS::Compute::Error.new("Illegal attribute '#{attribute}' specified")
            end
            response
          else
            raise Fog::AWS::Compute::NotFound.new("The VPC '#{vpc_id}' does not exist.")
          end
        end
      end
    end
  end
end