From 15bbb42dc59cb351076fc85675e8bc4c36da2346 Mon Sep 17 00:00:00 2001 From: Eric Stonfer Date: Thu, 4 Oct 2012 08:53:44 -0400 Subject: [PATCH] create image extended to allow for EBS volume handling --- lib/fog/aws/requests/compute/create_image.rb | 20 ++++++++++++-------- tests/aws/requests/compute/image_tests.rb | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/fog/aws/requests/compute/create_image.rb b/lib/fog/aws/requests/compute/create_image.rb index 2b2077cee..232a1a3d4 100644 --- a/lib/fog/aws/requests/compute/create_image.rb +++ b/lib/fog/aws/requests/compute/create_image.rb @@ -20,14 +20,17 @@ module Fog # * 'requestId'<~String> - Id of request. # # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateImage.html] - def create_image(instance_id, name, description, no_reboot = false, attributes={}) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.DeviceName', attributes['DeviceName'])) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.NoDevice', attributes['NoDevice'])) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.VirtualName', attributes['VirtualName'])) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.SnapshotId', attributes['Ebs.SnapshotId'])) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.DeleteOnTermination', attributes['Ebs.DeleteOnTermination'])) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.VolumeType', attributes['Ebs.VolumeType'])) - params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.Iops', attributes['Ebs.Iops'])) + def create_image(instance_id, name, description, no_reboot = false, attributes=[]) + params = {} + attributes.each{|attr| + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.DeviceName', attr['DeviceName'])) + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.NoDevice', attr['NoDevice'])) + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.VirtualName', attr['VirtualName'])) + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.SnapshotId', attr['Ebs.SnapshotId'])) + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.DeleteOnTermination', attr['Ebs.DeleteOnTermination'])) + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.VolumeType', attr['Ebs.VolumeType'])) + params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.Ebs.Iops', attr['Ebs.Iops'])) + } request({ 'Action' => 'CreateImage', 'InstanceId' => instance_id, @@ -47,6 +50,7 @@ module Fog # def create_image(instance_id, name, description, no_reboot = false, attributes = {}) + params = {} params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.DeviceName', attributes['DeviceName'])) params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.NoDevice', attributes['NoDevice'])) params.merge!(Fog::AWS.indexed_param('BlockDeviceMapping.%d.VirtualName', attributes['VirtualName'])) diff --git a/tests/aws/requests/compute/image_tests.rb b/tests/aws/requests/compute/image_tests.rb index 9b3bcdb30..11bc0f000 100644 --- a/tests/aws/requests/compute/image_tests.rb +++ b/tests/aws/requests/compute/image_tests.rb @@ -35,6 +35,10 @@ Shindo.tests('Fog::Compute[:aws] | image requests', ['aws']) do 'return' => Fog::Boolean, 'requestId' => String } + @create_image_format = { + 'requestId' => String, + 'imageId' => String + } tests('success') do # the result for this is HUGE and relatively uninteresting... @@ -46,6 +50,21 @@ Shindo.tests('Fog::Compute[:aws] | image requests', ['aws']) do if Fog.mocking? @other_account = Fog::Compute::AWS.new(:aws_access_key_id => 'other', :aws_secret_access_key => 'account') + @server = Fog::Compute[:aws].servers.create + @server.wait_for{state == 'running'} + @created_image + tests("#create_image").formats(@create_image_format) do + result = Fog::Compute[:aws].create_image(@server.id, 'Fog-Test-Image', 'Fog Test Image', false).body + @created_image = Fog::Compute[:aws].images.get(result['imageId']) + result + end + tests("#create_image - no reboot").formats(@create_image_format) do + result = Fog::Compute[:aws].create_image(@server.id, 'Fog-Test-Image', 'Fog Test Image', true).body + @created_image = Fog::Compute[:aws].images.get(result['imageId']) + result + end + @server.destroy + tests("#register_image").formats(@register_image_format) do @image = Fog::Compute[:aws].register_image('image', 'image', '/dev/sda1').body end