From c2c46d18eebdb9ab387b32442d3352cc78d2092e Mon Sep 17 00:00:00 2001 From: Eric Stonfer Date: Mon, 5 Nov 2012 12:53:36 -0500 Subject: [PATCH] [AWS] Adds ModifyVolumeAttribute --- lib/fog/aws/compute.rb | 1 + lib/fog/aws/models/compute/volume.rb | 1 - .../compute/modify_volume_attribute.rb | 51 +++++++++++++++++++ tests/aws/requests/compute/volume_tests.rb | 8 +++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/fog/aws/requests/compute/modify_volume_attribute.rb diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index 8c2a54021..0978f5e30 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -113,6 +113,7 @@ module Fog request :modify_instance_attribute request :modify_network_interface_attribute request :modify_snapshot_attribute + request :modify_volume_attribute request :purchase_reserved_instances_offering request :reboot_instances request :release_address diff --git a/lib/fog/aws/models/compute/volume.rb b/lib/fog/aws/models/compute/volume.rb index bd9af8828..acc9c78fa 100644 --- a/lib/fog/aws/models/compute/volume.rb +++ b/lib/fog/aws/models/compute/volume.rb @@ -125,7 +125,6 @@ module Fog end end - end end end diff --git a/lib/fog/aws/requests/compute/modify_volume_attribute.rb b/lib/fog/aws/requests/compute/modify_volume_attribute.rb new file mode 100644 index 000000000..afbc7761d --- /dev/null +++ b/lib/fog/aws/requests/compute/modify_volume_attribute.rb @@ -0,0 +1,51 @@ +module Fog + module Compute + class AWS + class Real + + require 'fog/aws/parsers/compute/basic' + + # Modifies a volume attribute. + # + # ==== Parameters + # * volume_id<~String> - The ID of the volume. + # * auto_enable_io_value<~Boolean> - This attribute exists to auto-enable the I/O operations to the volume. + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'requestId'<~String> - Id of request + # * 'return'<~Boolean> - success? + # + # {Amazon API Reference}[http://http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ModifyVolumeAttribute.html] + def modify_volume_attribute(volume_id=nil, auto_enable_io_value=false) + request( + 'Action' => 'ModifyVolumeAttribute', + 'VolumeId' => volume_id, + 'AutoEnableIO.Value' => auto_enable_io_value, + :idempotent => true, + :parser => Fog::Parsers::Compute::AWS::Basic.new + ) + end + + end + + class Mock + + def modify_volume_attribute(volume_id=nil, auto_enable_io_value=false) + response = Excon::Response.new + if volume = self.data[:volumes][volume_id] + response.status = 200 + response.body = { + 'requestId' => Fog::AWS::Mock.request_id, + 'return' => true + } + response + else + raise Fog::Compute::AWS::NotFound.new("The volume '#{volume_id}' does not exist.") + end + end + end + end + end +end diff --git a/tests/aws/requests/compute/volume_tests.rb b/tests/aws/requests/compute/volume_tests.rb index 91d1b2a76..6da7b358e 100644 --- a/tests/aws/requests/compute/volume_tests.rb +++ b/tests/aws/requests/compute/volume_tests.rb @@ -136,6 +136,10 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do Fog::Compute[:aws].volumes.get(@volume_id).wait_for { ready? } + tests("#modify_volume_attribute('#{@volume_id}', true)").formats(AWS::Compute::Formats::BASIC) do + Fog::Compute[:aws].modify_volume_attribute(@volume_id, true).body + end + tests("#delete_volume('#{@volume_id}')").formats(AWS::Compute::Formats::BASIC) do Fog::Compute[:aws].delete_volume(@volume_id).body end @@ -156,6 +160,10 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do Fog::Compute[:aws].detach_volume('vol-00000000') end + tests("#modify_volume_attribute('vol-00000000', true)").raises(Fog::Compute::AWS::NotFound) do + Fog::Compute[:aws].modify_volume_attribute('vol-00000000', true) + end + tests("#detach_volume('#{@volume.identity}')").raises(Fog::Compute::AWS::Error) do Fog::Compute[:aws].detach_volume(@volume.identity) end