From 13b04fb4a7fc984dbd1e0eb1834271f5fbf23cdf Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Sun, 10 Jan 2010 13:35:20 -0800 Subject: [PATCH] add images model for ec2 --- bin/fog | 4 ++ lib/fog/aws/ec2.rb | 2 + lib/fog/aws/models/ec2/flavor.rb | 1 - lib/fog/aws/models/ec2/image.rb | 24 ++++++++++++ lib/fog/aws/models/ec2/images.rb | 44 ++++++++++++++++++++++ lib/fog/rackspace/models/servers/flavor.rb | 1 - 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 lib/fog/aws/models/ec2/image.rb create mode 100644 lib/fog/aws/models/ec2/images.rb diff --git a/bin/fog b/bin/fog index b3d77c7b6..5ed97d1bb 100755 --- a/bin/fog +++ b/bin/fog @@ -56,6 +56,10 @@ module AWS connections[:ec2].flavors end + def images + connections[:ec2].images + end + def servers connections[:ec2].servers end diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index 6211921f0..4e0876352 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -24,6 +24,8 @@ module Fog load "fog/aws/models/ec2/addresses.rb" load "fog/aws/models/ec2/flavor.rb" load "fog/aws/models/ec2/flavors.rb" + load "fog/aws/models/ec2/image.rb" + load "fog/aws/models/ec2/images.rb" load "fog/aws/models/ec2/key_pair.rb" load "fog/aws/models/ec2/key_pairs.rb" load "fog/aws/models/ec2/security_group.rb" diff --git a/lib/fog/aws/models/ec2/flavor.rb b/lib/fog/aws/models/ec2/flavor.rb index 719d20be8..838937a7b 100644 --- a/lib/fog/aws/models/ec2/flavor.rb +++ b/lib/fog/aws/models/ec2/flavor.rb @@ -9,7 +9,6 @@ module Fog attribute :bits attribute :cores attribute :disk - attribute :id attribute :name attribute :ram diff --git a/lib/fog/aws/models/ec2/image.rb b/lib/fog/aws/models/ec2/image.rb new file mode 100644 index 000000000..d63393eee --- /dev/null +++ b/lib/fog/aws/models/ec2/image.rb @@ -0,0 +1,24 @@ +module Fog + module AWS + class EC2 + + class Image < Fog::Model + + 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 :platform + attribute :product_codes, 'productCodes' + attribute :ramdisk_id, 'ramdiskId' + + end + + end + end +end \ No newline at end of file diff --git a/lib/fog/aws/models/ec2/images.rb b/lib/fog/aws/models/ec2/images.rb new file mode 100644 index 000000000..ac9579733 --- /dev/null +++ b/lib/fog/aws/models/ec2/images.rb @@ -0,0 +1,44 @@ +module Fog + module AWS + class EC2 + + def images + Fog::AWS::EC2::Images.new(:connection => self) + end + + class Images < Fog::Collection + + attribute :image_id + + model Fog::AWS::EC2::Image + + def initialize(attributes) + @image_id ||= [] + super + end + + def all(image_id = @image_id) + @image_id = image_id + if @loaded + clear + end + @loaded = true + data = connection.describe_images('ImageId' => image_id).body + data['imagesSet'].each do |image| + self << new(image) + end + self + end + + def get(image_id) + if image_id + all(image_id).first + end + rescue Excon::Errors::BadRequest + nil + end + end + + end + end +end diff --git a/lib/fog/rackspace/models/servers/flavor.rb b/lib/fog/rackspace/models/servers/flavor.rb index 1017d45bb..957274804 100644 --- a/lib/fog/rackspace/models/servers/flavor.rb +++ b/lib/fog/rackspace/models/servers/flavor.rb @@ -9,7 +9,6 @@ module Fog attribute :bits attribute :cores attribute :disk - attribute :id attribute :name attribute :ram