1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

create image extended to allow for EBS volume handling

This commit is contained in:
Eric Stonfer 2012-10-04 08:53:44 -04:00
parent bac800f3ba
commit 15bbb42dc5
2 changed files with 31 additions and 8 deletions

View file

@ -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']))

View file

@ -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