diff --git a/lib/fog/compute/models/aws/server.rb b/lib/fog/compute/models/aws/server.rb index f3a8d245a..82c90580a 100644 --- a/lib/fog/compute/models/aws/server.rb +++ b/lib/fog/compute/models/aws/server.rb @@ -234,8 +234,8 @@ module Fog raise ArgumentError.new("only Boolean allowed here") end - #set the attribute - response[identity] == 'enabled' ? self.monitoring=true : self.monitoring=false + #set the attribute, there is only one instance_id here + response.body['instancesSet'][0]['monitoring'] == 'enabled' ? self.monitoring=true : self.monitoring=false end end diff --git a/lib/fog/compute/parsers/aws/monitor_unmonitor_instances.rb b/lib/fog/compute/parsers/aws/monitor_unmonitor_instances.rb index c48c7479d..507e26af0 100644 --- a/lib/fog/compute/parsers/aws/monitor_unmonitor_instances.rb +++ b/lib/fog/compute/parsers/aws/monitor_unmonitor_instances.rb @@ -7,17 +7,23 @@ module Fog def reset @response = {} - @current_id = nil + @instance_set = [] + @current_instance_set = {} end def end_element(name) case name + when 'requestId' + @response['requestId'] = @value when 'instanceId' - @current_id = @value + @current_instance_set['instanceId'] = @value when 'item' - @current_id = nil + @instance_set << @current_instance_set + @current_instance_set = {} when 'state' - @response[@current_id] = @value + @current_instance_set['monitoring'] = @value + when 'instancesSet' + @response['instancesSet'] = @instance_set end end diff --git a/lib/fog/compute/requests/aws/monitor_instances.rb b/lib/fog/compute/requests/aws/monitor_instances.rb index e3c03aace..03cb7d471 100644 --- a/lib/fog/compute/requests/aws/monitor_instances.rb +++ b/lib/fog/compute/requests/aws/monitor_instances.rb @@ -33,7 +33,16 @@ module Fog def monitor_instances(instance_ids) response = Excon::Response.new response.status = 200 - response.body = instance_ids.inject({}) { |memo, id| {memo[id] => 'enabled'} } + [*instance_ids].each do |instance_id| + if instance = @data[:instances][instance_id] + instance['monitoring']['state'] = 'enabled' + else + raise Fog::AWS::Compute::NotFound.new("The instance ID '#{instance_ids}' does not exist") + end + end + instances_set = [*instance_ids].inject([]) { |memo, id| memo << {'instanceId' => id, 'monitoring' => 'enabled'} } + response.body = {'requestId' => 'some_request_id', 'instancesSet' => instances_set} + response end end diff --git a/lib/fog/compute/requests/aws/unmonitor_instances.rb b/lib/fog/compute/requests/aws/unmonitor_instances.rb index 2d76a4708..2f74e93ba 100644 --- a/lib/fog/compute/requests/aws/unmonitor_instances.rb +++ b/lib/fog/compute/requests/aws/unmonitor_instances.rb @@ -33,9 +33,18 @@ module Fog def unmonitor_instances(instance_ids) response = Excon::Response.new response.status = 200 - response.body = instance_ids.inject({}) { |memo, id| {memo[id] => 'disabled'} } + [*instance_ids].each do |instance_id| + if instance = @data[:instances][instance_id] + instance['monitoring']['state'] = 'enabled' + else + raise Fog::AWS::Compute::NotFound.new("The instance ID '#{instance_ids}' does not exist") + end + end + instances_set = [*instance_ids].inject([]) { |memo, id| memo << {'instanceId' => id, 'monitoring' => 'disabled'} } + response.body = {'requestId' => 'some_request_id', 'instancesSet' => instances_set} + response end - + end end diff --git a/tests/compute/parsers/aws/monitor_unmonitor_instances_tests.rb b/tests/compute/parsers/aws/monitor_unmonitor_instances_tests.rb index 4d08b2ac0..5b543d9bd 100644 --- a/tests/compute/parsers/aws/monitor_unmonitor_instances_tests.rb +++ b/tests/compute/parsers/aws/monitor_unmonitor_instances_tests.rb @@ -30,8 +30,17 @@ Shindo.tests('AWS::Compute::MonitorUnmonitorInstances | monitor/unmonitor parser body = Nokogiri::XML::SAX::PushParser.new(parser) body << aws_result - test('enabled') { parser.response['i-43a4412a'] == 'enabled' } - test('disabled') { parser.response['i-23a3397d'] == 'disabled' } + test('requestId') { parser.response['requestId'] == '59dbff89-35bd-4eac-99ed-be587EXAMPLE' } + + test('enabled') do + selected = parser.response['instancesSet'].select { |item| item['instanceId'] == 'i-43a4412a' }[0] + selected['monitoring'] == 'enabled' + end + + test('disabled') do + selected = parser.response['instancesSet'].select { |item| item['instanceId'] == 'i-23a3397d' }[0] + selected['monitoring'] == 'disabled' + end end