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

[ec2] Add ability to use create_image to make bootable AMIs

This commit is contained in:
Caleb Tennis 2010-07-25 01:25:29 +08:00 committed by Wesley Beary
parent 9503514777
commit 770fe8fc46
3 changed files with 79 additions and 0 deletions

View file

@ -33,6 +33,7 @@ module Fog
request 'create_key_pair'
request 'create_security_group'
request 'create_snapshot'
request 'create_image'
request 'create_volume'
request 'delete_key_pair'
request 'delete_security_group'

View file

@ -0,0 +1,20 @@
module Fog
module Parsers
module AWS
module EC2
class CreateImage < Fog::Parsers::Base
def end_element(name)
case name
when 'instanceId', 'requestId', 'name', 'description', 'noReboot', 'imageId'
@response[name] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,58 @@
module Fog
module AWS
module EC2
class Real
require 'fog/aws/parsers/ec2/create_image'
# Create a bootable EBS volume AMI
#
# ==== Parameters
# * instance_id<~String> - Instance used to create image.
# * name<~Name> - Name to give image.
# * description<~Name> - Description of image.
# * no_reboot<~Boolean> - Optional, whether or not to reboot the image when making the snapshot
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'imageId'<~String> - The ID of the created AMI.
# * 'requestId'<~String> - Id of request.
def create_image(instance_id, name, description, no_reboot = false)
request(
'Action' => 'CreateImage',
'InstanceId' => instance_id,
'Name' => name,
'Description' => description,
'NoReboot' => no_reboot.to_s,
:parser => Fog::Parsers::AWS::EC2::CreateImage.new
)
end
end
class Mock
def create_image(instance_id, name, description, no_reboot = false)
response = Excon::Response.new
if instance_id && !name.empty?
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'imageId' => Fog::AWS::Mock.image_id
}
else
response.status = 400
response.body = {
'Code' => 'InvalidParameterValue'
}
if name.empty?
response.body['Message'] = "Invalid value '' for name. Must be specified."
end
end
response
end
end
end
end
end