Sha256: e7cbbacc7915e51208561ca5054bc7b29b91ee5b1dd46f4ca05720055951cf9e

Contents?: true

Size: 1.92 KB

Versions: 61

Compression:

Stored size: 1.92 KB

Contents

module Fog
  module Compute
    class AWS
      class Real
        require 'fog/aws/parsers/compute/monitor_unmonitor_instances'

        # Monitor specified instance
        # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-MonitorInstances.html
        #
        # ==== Parameters
        # * instance_ids<~Array> - Arrays of instances Ids to monitor
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'instancesSet': http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-MonitorInstancesResponseSetItemType.html
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-MonitorInstances.html]
        def monitor_instances(instance_ids)
          params = Fog::AWS.indexed_param('InstanceId', instance_ids)
          request({
                          'Action' => 'MonitorInstances',
                          :idempotent => true,
                          :parser => Fog::Parsers::Compute::AWS::MonitorUnmonitorInstances.new
                  }.merge!(params))
        end
      end

      class Mock
        def monitor_instances(instance_ids)
          response        = Excon::Response.new
          response.status = 200
          [*instance_ids].each do |instance_id|
            if instance = self.data[:instances][instance_id]
              instance['monitoring']['state'] = 'enabled'
            else
              raise Fog::Compute::AWS::NotFound.new("The instance ID '#{instance_ids}' does not exist")
            end
          end
          instances_set = [*instance_ids].reduce([]) { |memo, id| memo << {'instanceId' => id, 'monitoring' => 'enabled'} }
          response.body = {'requestId' => 'some_request_id', 'instancesSet' => instances_set}
          response
        end
      end
    end
  end
end

Version data entries

61 entries across 59 versions & 6 rubygems

Version Path
fog-1.22.1 lib/fog/aws/requests/compute/monitor_instances.rb