From f7b4c40c7404290e8d674849c626a6918ef887fe Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Wed, 30 May 2012 17:52:59 -0700 Subject: [PATCH] Mock stop_instances Not perfect, but looks like it works for me --- .../requests/compute/describe_instances.rb | 3 +++ .../aws/requests/compute/stop_instances.rb | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/fog/aws/requests/compute/describe_instances.rb b/lib/fog/aws/requests/compute/describe_instances.rb index 302d63d3b..5b178b9fe 100644 --- a/lib/fog/aws/requests/compute/describe_instances.rb +++ b/lib/fog/aws/requests/compute/describe_instances.rb @@ -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']) diff --git a/lib/fog/aws/requests/compute/stop_instances.rb b/lib/fog/aws/requests/compute/stop_instances.rb index c06ca9dad..a7b719799 100644 --- a/lib/fog/aws/requests/compute/stop_instances.rb +++ b/lib/fog/aws/requests/compute/stop_instances.rb @@ -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