Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: lib/fog/compute/aws.rb
- Loading branch information
Showing
8 changed files
with
269 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/fog/compute/parsers/aws/monitor_unmonitor_instances.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module Compute | ||
|
||
class MonitorUnmonitorInstances < Fog::Parsers::Base | ||
|
||
def reset | ||
@response = {} | ||
@instance_set = [] | ||
@current_instance_set = {} | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'requestId' | ||
@response['requestId'] = @value | ||
when 'instanceId' | ||
@current_instance_set['instanceId'] = @value | ||
when 'item' | ||
@instance_set << @current_instance_set | ||
@current_instance_set = {} | ||
when 'state' | ||
@current_instance_set['monitoring'] = @value | ||
when 'instancesSet' | ||
@response['instancesSet'] = @instance_set | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Fog | ||
module AWS | ||
class Compute | ||
|
||
class Real | ||
|
||
require 'fog/compute/parsers/aws/monitor_unmonitor_instances' | ||
|
||
# Monitor specified instance | ||
# http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-MonitorInstances.html | ||
# | ||
# ==== Parameters | ||
# * instance_ids<~Array> - Arrays of instances Ids to monitor | ||
# | ||
# ==== Returns | ||
# * response<~Excon::Response>: | ||
# * body<~Hash>: | ||
# * 'requestId'<~String> - Id of request | ||
# * 'instancesSet': http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-MonitorInstancesResponseSetItemType.html | ||
def monitor_instances(instance_ids) | ||
params = AWS.indexed_param('InstanceId', instance_ids) | ||
request({ | ||
'Action' => 'MonitorInstances', | ||
:idempotent => true, | ||
:parser => Fog::Parsers::AWS::Compute::MonitorUnmonitorInstances.new | ||
}.merge!(params)) | ||
end | ||
|
||
end | ||
|
||
class Mock | ||
|
||
def monitor_instances(instance_ids) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
[*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 | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Fog | ||
module AWS | ||
class Compute | ||
|
||
class Real | ||
|
||
require 'fog/compute/parsers/aws/monitor_unmonitor_instances' | ||
|
||
# UnMonitor specified instance | ||
# http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-UnmonitorInstances.html | ||
# | ||
# ==== Parameters | ||
# * instance_ids<~Array> - Arrays of instances Ids to monitor | ||
# | ||
# ==== Returns | ||
# * response<~Excon::Response>: | ||
# * body<~Hash>: | ||
# * 'requestId'<~String> - Id of request | ||
# * 'instancesSet': http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-MonitorInstancesResponseSetItemType.html | ||
def unmonitor_instances(instance_ids) | ||
params = AWS.indexed_param('InstanceId', instance_ids) | ||
request({ | ||
'Action' => 'UnmonitorInstances', | ||
:idempotent => true, | ||
:parser => Fog::Parsers::AWS::Compute::MonitorUnmonitorInstances.new | ||
}.merge!(params)) | ||
end | ||
|
||
end | ||
|
||
class Mock | ||
|
||
def unmonitor_instances(instance_ids) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
[*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 | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Shindo.tests("AWS::Compute::Server | monitor", ['aws']) do | ||
|
||
config = compute_providers[AWS] | ||
|
||
if !Fog.mocking? || config[:mocked] | ||
@instance = AWS[:compute].servers.new(config[:server_attributes]) | ||
end | ||
|
||
tests('new instance') do | ||
|
||
test('monitor') do | ||
@instance.monitoring = true | ||
@instance.attributes[:monitoring] == true | ||
end | ||
|
||
test('unmonitor') do | ||
@instance.monitoring = false | ||
@instance.attributes[:monitoring] == false | ||
end | ||
|
||
end | ||
|
||
tests('existing instance') do | ||
|
||
@instance.save | ||
|
||
test('monitor') do | ||
#what I'd really like to test is if connection.monitor_instances is being called | ||
#this is a safeguard | ||
@instance.identity != nil | ||
@instance.monitoring = false | ||
@instance.monitor = true | ||
@instance.monitoring == true | ||
end | ||
|
||
test('unmonitor') do | ||
#what I'd really like to test is if connection.monitor_instances is being called | ||
#this is a safeguard | ||
@instance.identity != nil | ||
@instance.monitoring = true | ||
@instance.monitor = false | ||
@instance.monitoring == false | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/compute/parsers/aws/monitor_unmonitor_instances_tests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'fog/compute/parsers/aws/monitor_unmonitor_instances' | ||
|
||
Shindo.tests('AWS::Compute::MonitorUnmonitorInstances | monitor/unmonitor parser') do | ||
|
||
tests('success') do | ||
|
||
tests('#parse') do | ||
|
||
aws_result = <<-AWS | ||
<UnmonitorInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"> | ||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> | ||
<instancesSet> | ||
<item> | ||
<instanceId>i-43a4412a</instanceId> | ||
<monitoring> | ||
<state>enabled</state> | ||
</monitoring> | ||
</item> | ||
<item> | ||
<instanceId>i-23a3397d</instanceId> | ||
<monitoring> | ||
<state>disabled</state> | ||
</monitoring> | ||
</item> | ||
</instancesSet> | ||
</UnmonitorInstancesResponse> | ||
AWS | ||
|
||
parser = Fog::Parsers::AWS::Compute::MonitorUnmonitorInstances.new | ||
body = Nokogiri::XML::SAX::PushParser.new(parser) | ||
body << aws_result | ||
|
||
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 | ||
|
||
end | ||
|
||
end |