Sha256: ea3ef73ea77cd12701372c3c996ee167aaee435c742582f01ee2144d0e268e7c

Contents?: true

Size: 1.89 KB

Versions: 37

Compression:

Stored size: 1.89 KB

Contents

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

        # Terminate specified spot instance requests
        #
        # ==== Parameters
        # * spot_instance_request_id<~Array> - Ids of instances to terminates
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> id of request
        #     * 'spotInstanceRequestSet'<~Array>:
        #       * 'spotInstanceRequestId'<~String> - id of cancelled spot instance
        #       * 'state'<~String> - state of cancelled spot instance
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CancelSpotInstanceRequests.html]
        def cancel_spot_instance_requests(spot_instance_request_id)
          params = Fog::AWS.indexed_param('SpotInstanceRequestId', spot_instance_request_id)
          request({
            'Action'    => 'CancelSpotInstanceRequests',
            :idempotent => true,
            :parser     => Fog::Parsers::AWS::Compute::CancelSpotInstanceRequests.new
          }.merge!(params))
        end
      end

      class Mock
        def cancel_spot_instance_requests(spot_instance_request_id)
          response = Excon::Response.new
          spot_request = self.data[:spot_requests][spot_instance_request_id]

          unless spot_request
            raise Fog::AWS::Compute::NotFound.new("The spot instance request ID '#{spot_instance_request_id}' does not exist")
          end

          spot_request['fault']['code'] = 'request-cancelled'
          spot_request['state'] = 'cancelled'

          response.body = {'spotInstanceRequestSet' => [{'spotInstanceRequestId' => spot_instance_request_id, 'state' => 'cancelled'}], 'requestId' => Fog::AWS::Mock.request_id}
          response
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
fog-aws-3.30.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.29.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.28.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.27.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.26.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.25.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.24.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.23.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.22.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.21.1 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.21.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.20.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.19.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.18.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.17.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.16.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.15.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.14.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.13.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb
fog-aws-3.12.0 lib/fog/aws/requests/compute/cancel_spot_instance_requests.rb