File: attach_instances.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 (60 lines) | stat: -rw-r--r-- 2,157 bytes parent folder | download | duplicates (5)
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
module Fog
  module AWS
    class AutoScaling
      class Real
        require 'fog/aws/parsers/auto_scaling/basic'

        # Removes one or more instances from the specified Auto Scaling group.
        #
        #  cli equiv:
        # `aws autoscaling attach-instances --instance-ids i-93633f9b --auto-scaling-group-name my-auto-scaling-group`
        #
        # ==== Parameters
        #
        #   * AutoScalingGroupName<~String> - The name of the Auto Scaling group``
        #   * 'InstanceIds'<~Array> - The list of Auto Scaling instances to detach.
        #
        # ==== See Also
        #
        # http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_AttachInstances.html

        ExpectedOptions[:asg_name] = %w[AutoScalingGroupName]
        ExpectedOptions[:instance_ids] = %w[InstanceIds]

        def attach_instances(auto_scaling_group_name, options = {})

          if instance_ids = options.delete('InstanceIds')
            options.merge!(AWS.indexed_param('InstanceIds.member.%d', [*instance_ids]))
          end

          request({
            'Action'               => 'AttachInstances',
            'AutoScalingGroupName' => auto_scaling_group_name,
            :parser                => Fog::Parsers::AWS::AutoScaling::Basic.new
          }.merge!(options))
        end
      end

      class Mock
        def attach_instances(auto_scaling_group_name, options = {})
          unexpected_options = options.keys - ExpectedOptions[:asg_name] - ExpectedOptions[:instance_ids]

          unless unexpected_options.empty?
            raise Fog::AWS::AutoScaling::ValidationError.new("Options #{unexpected_options.join(',')} should not be included in request")
          end

          unless self.data[:auto_scaling_groups].key?(auto_scaling_group_name)
            raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
          end

          response = Excon::Response.new
          response.status = 200
          response.body = {
            'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
          }
          response
        end
      end
    end
  end
end