2009-08-22 01:04:12 -04:00
|
|
|
unless Fog.mocking?
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
# Terminate specified instances
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * instance_id<~Array> - Ids of instances to terminates
|
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# # * response<~Excon::Response>:
|
2009-08-22 01:04:12 -04:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'requestId'<~String> - Id of request
|
|
|
|
# * 'instancesSet'<~Array>:
|
|
|
|
# * 'instanceId'<~String> - id of the terminated instance
|
|
|
|
# * 'previousState'<~Hash>: previous state of instance
|
|
|
|
# * 'code'<~Integer> - previous status code
|
|
|
|
# * 'name'<~String> - name of previous state
|
|
|
|
# * 'shutdownState'<~Hash>: shutdown state of instance
|
|
|
|
# * 'code'<~Integer> - current status code
|
|
|
|
# * 'name'<~String> - name of current state
|
|
|
|
def terminate_instances(instance_id)
|
2010-01-31 17:07:26 -05:00
|
|
|
params = AWS.indexed_param('InstanceId', instance_id)
|
2009-08-22 01:04:12 -04:00
|
|
|
request({
|
|
|
|
'Action' => 'TerminateInstances'
|
|
|
|
}.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
|
|
|
|
end
|
|
|
|
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|
2009-08-22 01:04:12 -04:00
|
|
|
end
|
|
|
|
end
|
2009-07-17 03:36:42 -04:00
|
|
|
|
2009-08-22 01:04:12 -04:00
|
|
|
else
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
def terminate_instances(instance_id)
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-09-12 14:29:55 -04:00
|
|
|
instance_id = [*instance_id]
|
|
|
|
if (Fog::AWS::EC2.data[:instances].keys & instance_id).length == instance_id.length
|
|
|
|
for instance_id in instance_id
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id,
|
|
|
|
'instancesSet' => []
|
|
|
|
}
|
|
|
|
instance = Fog::AWS::EC2.data[:instances][instance_id]
|
2009-08-22 01:04:12 -04:00
|
|
|
Fog::AWS::EC2.data[:deleted_at][instance_id] = Time.now
|
|
|
|
instance['status'] = 'deleting'
|
|
|
|
response.status = 200
|
2009-09-12 14:29:55 -04:00
|
|
|
# TODO: the codes are mostly educated guessing, not certainty
|
2009-08-23 14:01:37 -04:00
|
|
|
code = case instance['state']
|
|
|
|
when 'pending'
|
|
|
|
0
|
|
|
|
when 'running'
|
|
|
|
16
|
|
|
|
when 'shutting-down'
|
|
|
|
32
|
|
|
|
when 'terminated'
|
|
|
|
64
|
2009-09-12 14:29:55 -04:00
|
|
|
when 'rebooting'
|
|
|
|
128
|
2009-08-23 14:01:37 -04:00
|
|
|
end
|
2009-08-22 01:04:12 -04:00
|
|
|
response.body['instancesSet'] << {
|
|
|
|
'instanceId' => instance_id,
|
2009-08-23 14:01:37 -04:00
|
|
|
'previousState' => { 'name' => instance['state'], 'code' => code },
|
2009-08-22 01:04:12 -04:00
|
|
|
'shutdownState' => { 'name' => 'shutting-down', 'code' => 32}
|
|
|
|
}
|
|
|
|
end
|
2009-09-12 14:29:55 -04:00
|
|
|
else
|
|
|
|
response.status = 400
|
2009-11-20 14:08:08 -05:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-08-22 01:04:12 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|
|
|
|
end
|
2009-08-22 01:04:12 -04:00
|
|
|
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|