File: put_scaling_policy.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 (79 lines) | stat: -rw-r--r-- 3,753 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
75
76
77
78
79
module Fog
  module AWS
    class AutoScaling
      class Real
        require 'fog/aws/parsers/auto_scaling/put_scaling_policy'

        # Creates or updates a policy for an Auto Scaling group. To update an
        # existing policy, use the existing policy name and set the
        # parameter(s) you want to change. Any existing parameter not changed
        # in an update to an existing policy is not changed in this update
        # request.
        #
        # ==== Parameters
        # * adjustment_type<~String> - Specifies whether the scaling_adjustment
        #   is an absolute number or a percentage of the current capacity.
        # * auto_scaling_group_name<~String> - The name or ARN of the Auto
        #   Scaling group.
        # * policy_name<~String> - The name of the policy you want to create or
        #   update.
        # * scaling_adjustment<~Integer> - The number of instances by which to
        #   scale. AdjustmentType determines the interpretation of this number
        #   (e.g., as an absolute number or as a percentage of the existing
        #   Auto Scaling group size). A positive increment adds to the current
        #   capacity and a negative value removes from the current capacity.
        # * options<~Hash>:
        #   * 'Cooldown'<~Integer> - The amount of time, in seconds, after a
        #     scaling activity completes before any further trigger-related
        #     scaling activities can start
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'ResponseMetadata'<~Hash>:
        #       * 'RequestId'<~String> - Id of request
        #     * 'PutScalingPolicyResult'<~Hash>:
        #       * 'PolicyARN'<~String> - A policy's Amazon Resource Name (ARN).
        #
        # ==== See Also
        # http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_PutScalingPolicy.html
        #
        def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
          request({
            'Action'               => 'PutScalingPolicy',
            'AdjustmentType'       => adjustment_type,
            'AutoScalingGroupName' => auto_scaling_group_name,
            'PolicyName'           => policy_name,
            'ScalingAdjustment'    => scaling_adjustment,
            :parser                => Fog::Parsers::AWS::AutoScaling::PutScalingPolicy.new
          }.merge!(options))
        end
      end

      class Mock
        def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
          unless self.data[:auto_scaling_groups].key?(auto_scaling_group_name)
            raise Fog::AWS::AutoScaling::ValidationError.new('Auto Scaling Group name not found - null')
          end
          self.data[:scaling_policies][policy_name] = {
            'AdjustmentType'       => adjustment_type,
            'Alarms'               => [],
            'AutoScalingGroupName' => auto_scaling_group_name,
            'Cooldown'             => 0,
            'MinAdjustmentStep'    => 0,
            'PolicyARN'            => Fog::AWS::Mock.arn('autoscaling', self.data[:owner_id], "scalingPolicy:00000000-0000-0000-0000-000000000000:autoScalingGroupName/#{auto_scaling_group_name}:policyName/#{policy_name}", self.region),
            'PolicyName'           => policy_name,
            'ScalingAdjustment'    => scaling_adjustment
          }.merge!(options)

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