1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Mock stop_instances

Not perfect, but looks like it works for me
This commit is contained in:
Edward Muller 2012-05-30 17:52:59 -07:00
parent 74e7efdae3
commit f7b4c40c74
2 changed files with 30 additions and 0 deletions

View file

@ -183,6 +183,9 @@ module Fog
end
when 'rebooting'
instance['instanceState'] = { 'code' => 16, 'name' => 'running' }
when 'stopping'
instance['instanceState'] = { 'code' => 0, 'name' => 'stopping' }
instance['stateReason'] = { 'code' => 0 }
when 'shutting-down'
if Time.now - self.data[:deleted_at][instance['instanceId']] >= Fog::Mock.delay * 2
self.data[:deleted_at].delete(instance['instanceId'])

View file

@ -28,6 +28,33 @@ module Fog
end
end
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')
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
end
end
end