File: enable_metrics_collection.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,424 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'

        # Enables monitoring of group metrics for the Auto Scaling group
        # specified in auto_scaling_group_name. You can specify the list of
        # enabled metrics with the metrics parameter.
        #
        # Auto scaling metrics collection can be turned on only if the
        # instance_monitoring.enabled flag, in the Auto Scaling group's launch
        # configuration, is set to true.
        #
        # ==== Parameters
        # * 'AutoScalingGroupName'<~String>: The name or ARN of the Auto
        #   Scaling group
        # * options<~Hash>:
        #   * Granularity<~String>: The granularity to associate with the
        #     metrics to collect.
        #   * Metrics<~Array>: The list of metrics to collect. If no metrics
        #     are specified, all metrics are enabled.
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'ResponseMetadata'<~Hash>:
        #       * 'RequestId'<~String> - Id of request
        #
        # ==== See Also
        # http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_EnableMetricsCollection.html
        #
        def enable_metrics_collection(auto_scaling_group_name, granularity, options = {})
          if metrics = options.delete('Metrics')
            options.merge!(AWS.indexed_param('Metrics.member.%d', [*metrics]))
          end
          request({
            'Action'               => 'EnableMetricsCollection',
            'AutoScalingGroupName' => auto_scaling_group_name,
            'Granularity'          => granularity,
            :parser                => Fog::Parsers::AWS::AutoScaling::Basic.new
          }.merge!(options))
        end
      end

      class Mock
        def enable_metrics_collection(auto_scaling_group_name, granularity, options = {})
          unless self.data[:auto_scaling_groups].key?(auto_scaling_group_name)
            Fog::AWS::AutoScaling::ValidationError.new("Group #{auto_scaling_group_name} not found")
          end
          unless self.data[:metric_collection_types][:granularities].include?(granularity)
            Fog::AWS::AutoScaling::ValidationError.new('Valid metrics granularity type is: [1Minute].')
          end

          Fog::Mock.not_implemented
        end
      end
    end
  end
end