Class: AWS::EC2::Image
- Inherits:
-
Resource
- Object
- Core::Resource
- Resource
- AWS::EC2::Image
- Includes:
- HasPermissions, TaggedItem
- Defined in:
- lib/aws/ec2/image.rb
Overview
Represents an Amazon Machine Image (AMI).
Instance Attribute Summary collapse
-
#architecture ⇒ Symbol
readonly
The architecture of the image (e.g.
:i386
). -
#description ⇒ String
A description of the image.
-
#hypervisor ⇒ Symbol
readonly
The image's hypervisor type.
-
#image_id ⇒ String
(also: #id)
readonly
The ID of the AMI.
-
#kernel_id ⇒ String
readonly
The kernel ID associated with the image, if any.
-
#location ⇒ String
readonly
The location of the AMI.
-
#name ⇒ String
readonly
The name of the AMI that was provided during image creation.
-
#owner_alias ⇒ String
readonly
The AWS account alias (e.g.,
"amazon"
) or AWS account ID that owns the AMI. -
#owner_id ⇒ String
readonly
The AWS account ID of the image owner.
-
#platform ⇒ String
readonly
Value is
windows
for Windows AMIs; otherwise blank. -
#product_codes ⇒ Array<String>
readonly
Returns an array of product codes attached to this instance.
-
#ramdisk_id ⇒ String
readonly
The RAM disk ID associated with the image, if any.
-
#root_device_name ⇒ String
readonly
The root device name (e.g.,
"/dev/sda1"
, or"xvda"
). -
#root_device_type ⇒ Symbol
readonly
The root device type used by the AMI.
-
#state ⇒ Symbol
readonly
Current state of the AMI.
-
#state_reason ⇒ Object
readonly
The reason for the image's most recent state change.
-
#type ⇒ Symbol
readonly
The type of image.
-
#virtualization_type ⇒ Symbol
readonly
The type of virtualization of the AMI.
Instance Method Summary collapse
-
#add_product_codes(*product_codes) ⇒ nil
Adds one or more product codes:.
-
#block_device_mappings ⇒ Hash
Returns a hash of block device mappings for the image.
-
#block_devices ⇒ Array<Hash>
Returns a list of all block device mappings.
-
#deregister ⇒ nil
(also: #delete)
Deregisters this AMI.
-
#exists? ⇒ Boolean
Returns
true
if the AMI exists (is returned by the DescribeImages action). -
#initialize(image_id, options = {}) ⇒ Image
constructor
A new instance of Image.
-
#kernel ⇒ Image
The kernel associated with the image, if any.
-
#ramdisk ⇒ Image
The RAM disk associated with the image, if any.
-
#run_instance(options = {}) ⇒ Instance or Array
Runs a single instance of this image.
-
#run_instances(count, options = {}) ⇒ Array<Instance>
Runs multiple instances of this image.
Methods included from HasPermissions
#permissions, #private?, #public=, #public?
Methods included from TaggedItem
Constructor Details
#initialize(image_id, options = {}) ⇒ Image
Returns a new instance of Image.
95 96 97 98 |
# File 'lib/aws/ec2/image.rb', line 95 def initialize image_id, = {} @image_id = image_id super end |
Instance Attribute Details
#architecture ⇒ Symbol (readonly)
The architecture of the
image (e.g. :i386
).
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def architecture @architecture end |
#description ⇒ String
A description of the image.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def description @description end |
#hypervisor ⇒ Symbol (readonly)
The image's hypervisor type. Possible values are:
:ovm
:xen
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def hypervisor @hypervisor end |
#image_id ⇒ String (readonly) Also known as: id
Returns The ID of the AMI.
101 102 103 |
# File 'lib/aws/ec2/image.rb', line 101 def image_id @image_id end |
#kernel_id ⇒ String (readonly)
The kernel ID associated with the image, if any. Only applicable for machine images.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def kernel_id @kernel_id end |
#location ⇒ String (readonly)
The location of the AMI.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def location @location end |
#name ⇒ String (readonly)
The name of the AMI that was provided during image creation.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def name @name end |
#owner_alias ⇒ String (readonly)
The AWS account alias (e.g.,
"amazon"
) or AWS account ID that owns the AMI.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def owner_alias @owner_alias end |
#owner_id ⇒ String (readonly)
The AWS account ID of the image owner.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def owner_id @owner_id end |
#platform ⇒ String (readonly)
Value is windows
for Windows
AMIs; otherwise blank.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def platform @platform end |
#product_codes ⇒ Array<String> (readonly)
Returns an array of product codes attached to this instance.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def product_codes @product_codes end |
#ramdisk_id ⇒ String (readonly)
The RAM disk ID associated with the image, if any. Only applicable for machine images.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def ramdisk_id @ramdisk_id end |
#root_device_name ⇒ String (readonly)
The root device name
(e.g., "/dev/sda1"
, or "xvda"
).
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def root_device_name @root_device_name end |
#root_device_type ⇒ Symbol (readonly)
The root device type used by the AMI. Possible values:
:ebs
:instance_store
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def root_device_type @root_device_type end |
#state ⇒ Symbol (readonly)
Current state of the AMI. If the
state is :available
, the image is successfully registered
and available for launching. Valid values:
:available
:pending
:failed
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def state @state end |
#state_reason ⇒ Object (readonly)
The reason for the image's most recent state change. The return value is an object with the following methods:
code
- Reason code for the state change.message
- A textual description of the state change.
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def state_reason @state_reason end |
#type ⇒ Symbol (readonly)
The type of image. Valid values are:
:machine
:kernel
:ramdisk
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def type @type end |
#virtualization_type ⇒ Symbol (readonly)
The type of virtualization of the AMI. Possible values:
:paravirtual
:hvm
89 90 91 |
# File 'lib/aws/ec2/image.rb', line 89 def virtualization_type @virtualization_type end |
Instance Method Details
#add_product_codes(*product_codes) ⇒ nil
Adds one or more product codes:
image.add_product_codes 'ABCXYZ', 'MNOPQR'
You can also pass an array of product codes:
image.add_product_codes ['ABCXYZ', 'MNOPQR']
254 255 256 257 258 259 260 |
# File 'lib/aws/ec2/image.rb', line 254 def add_product_codes *product_codes client_opts = {} client_opts[:image_id] = self.id client_opts[:product_codes] = product_codes.flatten client.modify_image_attribute(client_opts) nil end |
#block_device_mappings ⇒ Hash
This method will not return data for ephemeral volumes.
Returns a hash of block
device mappings for the image. In each entry, the key is
the device name (e.g. "/dev/sda1"
) and the value is an
hash with the following keys that return information
about the block device:
:snapshot_id
- The ID of the snapshot that will be used to create this device (may benil
).:volume_size
- The size of the volume, in GiBs.:delete_on_termination
- True if the Amazon EBS volume is deleted on instance termination.
167 168 169 170 171 172 173 174 |
# File 'lib/aws/ec2/image.rb', line 167 def block_device_mappings (block_device_mapping || []).inject({}) do |h, mapping| if ebs = mapping[:ebs] h[mapping[:device_name]] = ebs end h end end |
#block_devices ⇒ Array<Hash>
Returns a list of all block device mappings. This list may contain ephemeral volumes.
178 179 180 |
# File 'lib/aws/ec2/image.rb', line 178 def block_devices block_device_mapping.to_a end |
#deregister ⇒ nil Also known as: delete
Deregisters this AMI. Once deregistered, the AMI cannot be used to launch new instances.
185 186 187 188 |
# File 'lib/aws/ec2/image.rb', line 185 def deregister client.deregister_image(:image_id => id) nil end |
#exists? ⇒ Boolean
Returns true
if the AMI exists (is returned by
the DescribeImages action).
219 220 221 222 223 224 |
# File 'lib/aws/ec2/image.rb', line 219 def exists? resp = client.describe_images(:filters => [ { :name => "image-id", :values => [id] } ]) !resp.images_set.empty? end |
#kernel ⇒ Image
Returns The kernel associated with the image, if any. Only applicable for machine images.
228 229 230 231 232 |
# File 'lib/aws/ec2/image.rb', line 228 def kernel if id = kernel_id Image.new(id, :config => config) end end |
#ramdisk ⇒ Image
Returns The RAM disk associated with the image, if any. Only applicable for machine images.
236 237 238 239 240 |
# File 'lib/aws/ec2/image.rb', line 236 def ramdisk if id = ramdisk_id Image.new(id, :config => config) end end |
#run_instance(options = {}) ⇒ Instance or Array
Runs a single instance of this image.
197 198 199 200 |
# File 'lib/aws/ec2/image.rb', line 197 def run_instance = {} instances = InstanceCollection.new(:config => config) instances.create(.merge(:image => self)) end |
#run_instances(count, options = {}) ⇒ Array<Instance>
Runs multiple instances of this image.
213 214 215 |
# File 'lib/aws/ec2/image.rb', line 213 def run_instances count, = {} run_instance(.merge(:count => count)) end |