Sha256: b8dccf8a33124376b00a7f340da6adae7572a4bf8ddb05440f476c9925b3efe2

Contents?: true

Size: 1.48 KB

Versions: 83

Compression:

Stored size: 1.48 KB

Contents

module Fog
  module Compute
    class IBM
      class Real

        # Deletes the Instance that the authenticated user manages with the specified :instance_id
        #
        # ==== Parameters
        # * instance_id<~String> - Id of instance
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     *'success'<~Bool>: true or false for success
        def delete_instance(instance_id)
          request(
            :method   => 'DELETE',
            :expects  => 200,
            :path     => "/instances/#{instance_id}"
          )
        end

      end

      class Mock

        def delete_instance(instance_id)
          response = Excon::Response.new
          if deleteable? instance_id
            # remove from memoreeeez.
            self.data[:instances].delete instance_id
            response.body = { 'success' => true }
            response.status = 200
          else
            # TODO: we should really return a 412 if the instance is in an invalid state, and a 404 if it doesn't exist.
            response.status = 404
          end
          response
        end

        # we can't delete the instance if it doesn't exist, or is in an invalid state.
        def deleteable?(instance_id)
          return false unless instance_exists? instance_id
          instance = self.data[:instances][instance_id]
          return false if [0, 1, 7, 14, 15].include?(instance["status"].to_i)
          true
        end

      end
    end
  end
end

Version data entries

83 entries across 83 versions & 14 rubygems

Version Path
fog-1.22.0 lib/fog/ibm/requests/compute/delete_instance.rb
fog-1.21.0 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/ibm/requests/compute/delete_instance.rb
fog-1.20.0 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/ibm/requests/compute/delete_instance.rb
fog-1.19.0 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/ibm/requests/compute/delete_instance.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/ibm/requests/compute/delete_instance.rb