Class: AWS::EC2::ImageCollection
- Inherits:
-
Collection
- Object
- Collection
- AWS::EC2::ImageCollection
- Defined in:
- lib/aws/ec2/image_collection.rb
Overview
Represents a collection of EC2 images. You can use this to find out which images exist with the characteristics you are interested in:
ec2 = EC2.new
all_images = ec2.images
amazon_owned_images = all_images.with_owner('amazon')
my_images = all_images.with_owner('self')
tagged_amis = all_images.tagged('mytag')
tagged_amis.map(&:id) # => ["ami-123", ...]
You can also use it to create new images. For example:
ec2.images.create(:instance_id => "i-123",
:name => "my-image")
Instance Method Summary collapse
-
#[](image_id) ⇒ Image
Image_id The ID of the image.
-
#create(options = {}) ⇒ Image
Creates an AMI.
- #each {|image| ... } ⇒ nil
-
#executable_by(*users) ⇒ ImageCollection
A new collection that only includes images for which the specified user ID has explicit launch permissions.
-
#with_owner(*owners) ⇒ ImageCollection
A new collection that only includes images owned by one or more of the specified AWS accounts.
Instance Method Details
#[](image_id) ⇒ Image
Returns image_id The ID of the image.
52 53 54 |
# File 'lib/aws/ec2/image_collection.rb', line 52 def [] image_id super end |
#create(options = {}) ⇒ Image
Creates an AMI. There are several ways to create an AMI using this method; for detailed information on each strategy see the EC2 Developer Guide.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/aws/ec2/image_collection.rb', line 197 def create( = {}) resp = case when [:instance_id] client.create_image() when [:image_location] || [:root_device_name] if kernel = .delete(:kernel) [:kernel_id] = kernel.id end if ramdisk = .delete(:ramdisk) [:ramdisk_id] = ramdisk.id end [:block_device_mappings] = translate_block_device_mappings([:block_device_mappings]) if [:block_device_mappings] client.register_image() else raise(ArgumentError, "expected instance_id, image_location, " + "or root_device_name") end self[resp.image_id] end |
#each {|image| ... } ⇒ nil
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aws/ec2/image_collection.rb', line 82 def each(&block) opts = {} opts[:owners] = @owners.map { |id| id.to_s } unless @owners.empty? opts[:executable_users] = @executable_users.map { |id| id.to_s } unless @executable_users.empty? response = filtered_request(:describe_images, opts) response.images_set.each do |i| image = Image.new(i.image_id, :config => config) yield(image) end nil end |
#executable_by(*users) ⇒ ImageCollection
Returns A new collection that only includes images for which the specified user ID has explicit launch permissions. The user ID can be an AWS account ID, :self
to return AMIs for which the sender of the request has explicit launch permissions, or :all
to return AMIs with public launch permissions.
76 77 78 |
# File 'lib/aws/ec2/image_collection.rb', line 76 def executable_by(*users) collection_with(:executable_users => @executable_users + users) end |
#with_owner(*owners) ⇒ ImageCollection
Returns A new collection that only includes images owned by one or more of the specified AWS accounts. The IDs :amazon
and :self
can be used to include AMIs owned by Amazon or AMIs owned by you, respectively.
63 64 65 |
# File 'lib/aws/ec2/image_collection.rb', line 63 def with_owner(*owners) collection_with(:owners => @owners + owners) end |