2010-07-23 00:52:27 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class AWS
|
2010-07-23 00:52:27 -04:00
|
|
|
class Real
|
|
|
|
|
2011-08-24 21:37:00 -04:00
|
|
|
require 'fog/aws/parsers/compute/start_stop_instances'
|
2010-07-23 00:52:27 -04:00
|
|
|
|
|
|
|
# Stop specified instance
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * instance_id<~Array> - Id of instance to start
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'requestId'<~String> - Id of request
|
|
|
|
# * TODO: fill in the blanks
|
2011-05-19 12:31:56 -04:00
|
|
|
#
|
|
|
|
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-StopInstances.html]
|
2011-08-08 03:29:16 -04:00
|
|
|
def stop_instances(instance_id, force = false)
|
2011-06-20 16:49:37 -04:00
|
|
|
params = Fog::AWS.indexed_param('InstanceId', instance_id)
|
2011-08-08 03:29:16 -04:00
|
|
|
params.merge!('Force' => 'true') if force
|
2010-07-23 00:52:27 -04:00
|
|
|
request({
|
|
|
|
'Action' => 'StopInstances',
|
|
|
|
:idempotent => true,
|
2011-06-16 19:28:54 -04:00
|
|
|
:parser => Fog::Parsers::Compute::AWS::StartStopInstances.new
|
2010-07-23 00:52:27 -04:00
|
|
|
}.merge!(params))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-05-30 20:52:59 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
def stop_instances(instance_id, force = false)
|
|
|
|
instance_ids = Array(instance_id)
|
|
|
|
|
|
|
|
instance_set = self.data[:instances].values
|
|
|
|
instance_set = apply_tag_filters(instance_set, {'instance_id' => instance_ids}, 'instanceId')
|
2012-07-13 11:33:23 -04:00
|
|
|
instance_set = instance_set.find_all {|x| instance_ids.include?(x["instanceId"]) }
|
2012-05-30 20:52:59 -04:00
|
|
|
|
|
|
|
if instance_set.empty?
|
|
|
|
raise Fog::Compute::AWS::NotFound.new("The instance ID '#{instance_ids.first}' does not exist")
|
|
|
|
else
|
|
|
|
response = Excon::Response.new
|
|
|
|
response.status = 200
|
|
|
|
|
|
|
|
response.body = {
|
|
|
|
'instancesSet' => instance_set.inject([]) do |ia, instance|
|
|
|
|
ia << {'currentState' => { 'code' => 0, 'name' => 'stopping' },
|
|
|
|
'previousState' => instance['instanceState'],
|
|
|
|
'instanceId' => instance['instanceId'] }
|
|
|
|
instance['instanceState'] = {'code'=>0, 'name'=>'stopping'}
|
|
|
|
ia
|
|
|
|
end
|
|
|
|
}
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 00:52:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|