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

[ec2] Add the deregister_image request and parser.

[ec2] Add ability to call "deregister" directly on an image.
[ec2] Add rootDeviceType and rootDeviceName attributes to the image model.
This commit is contained in:
Caleb Tennis 2010-07-26 00:24:08 +08:00 committed by Wesley Beary
parent f377cfd7b5
commit 9696e21c71
8 changed files with 107 additions and 20 deletions

View file

@ -67,16 +67,18 @@ module Fog
path << letters(rand(9) + 8)
end
{
"imageOwnerId" => letters(rand(5) + 4),
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine"
"imageOwnerId" => letters(rand(5) + 4),
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine",
"rootDeviceType" => ["ebs","instance-store"][rand(2)],
"rootDeviceName" => "/dev/sda1"
}
end

View file

@ -39,6 +39,7 @@ module Fog
request 'delete_security_group'
request 'delete_snapshot'
request 'delete_volume'
request 'deregister_image'
request 'describe_addresses'
request 'describe_availability_zones'
request 'describe_images'

View file

@ -9,18 +9,24 @@ module Fog
identity :id, 'imageId'
attribute :architecture
attribute :location, 'imageLocation'
attribute :owner_id, 'imageOwnerId'
attribute :state, 'imageState'
attribute :type, 'imageType'
attribute :is_public, 'isPublic'
attribute :kernel_id, 'kernelId'
attribute :location, 'imageLocation'
attribute :owner_id, 'imageOwnerId'
attribute :state, 'imageState'
attribute :type, 'imageType'
attribute :is_public, 'isPublic'
attribute :kernel_id, 'kernelId'
attribute :platform
attribute :product_codes, 'productCodes'
attribute :ramdisk_id, 'ramdiskId'
attribute :product_codes, 'productCodes'
attribute :ramdisk_id, 'ramdiskId'
attribute :root_device_type, 'rootDeviceType'
attribute :root_device_name, 'rootDeviceName'
def deregister
connection.deregister_image(@id)
end
end
end
end
end
end

View file

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

View file

@ -19,7 +19,7 @@ module Fog
def end_element(name)
case name
when 'architecture', 'imageId', 'imageLocation', 'imageOwnerId', 'imageState', 'imageType', 'kernelId', 'platform', 'ramdiskId'
when 'architecture', 'imageId', 'imageLocation', 'imageOwnerId', 'imageState', 'imageType', 'kernelId', 'platform', 'ramdiskId', 'rootDeviceType','rootDeviceName'
@image[name] = @value
when 'isPublic'
if @value == 'true'

View file

@ -0,0 +1,51 @@
module Fog
module AWS
module EC2
class Real
require 'fog/aws/parsers/ec2/deregister_image'
# Attach an Amazon EBS volume with a running instance, exposing as specified device
#
# ==== Parameters
# * image_id<~String> - Id of image to deregister
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'return'<~Boolean> - Returns true if deregistration succeeded
# * 'requestId'<~String> - Id of request
def deregister_image(image_id)
request(
'Action' => 'DeregisterImage',
'ImageId' => image_id,
:parser => Fog::Parsers::AWS::EC2::DeregisterImage.new
)
end
end
class Mock
def deregister_image(image_id)
response = Excon::Response.new
if image_id
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'return' => "true"
}
response
else
message = 'MissingParameter => '
if !instance_id
message << 'The request must contain the parameter image_id'
end
raise Fog::AWS::EC2::Error.new(message)
end
end
end
end
end
end

View file

@ -30,6 +30,8 @@ module Fog
# * 'platform'<~String> - Operating platform of the image
# * 'productCodes'<~Array> - Product codes for the image
# * 'ramdiskId'<~String> - Ramdisk id associated with image, if any
# * 'rootDeviceName'<~String> - Root device name, e.g. /dev/sda1
# * 'rootDeviceType'<~String> - Root device type, ebs or instance-store
def describe_images(options = {})
if image_id = options.delete('ImageId')
options.merge!(AWS.indexed_param('ImageId', image_id))

View file

@ -17,6 +17,9 @@ describe 'EC2.describe_images' do
image['kernelId'].should be_a(String) if image['kernelId']
image['platform'].should be_a(String) if image['platform']
image['ramdiskId'].should be_a(String) if image['ramdiskId']
image['rootDeviceName'].should be_a(String) if image['rootDeviceName']
["ebs","instance-store"].should include(image['rootDeviceType'])
image['rootDeviceName'].should be_a(String) if image['rootDeviceName']
end
it "should return proper attributes with params" do
@ -33,6 +36,8 @@ describe 'EC2.describe_images' do
image['kernelId'].should be_a(String) if image['kernelId']
image['platform'].should be_a(String) if image['platform']
image['ramdiskId'].should be_a(String) if image['ramdiskId']
["ebs","instance-store"].should include(image['rootDeviceType'])
image['rootDeviceName'].should be_a(String) if image['rootDeviceName']
end
end