Class: AWS::EC2::Image

Inherits:
Resource
  • Object
show all
Includes:
HasPermissions, TaggedItem
Defined in:
lib/aws/ec2/image.rb

Overview

Represents an Amazon Machine Image (AMI).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasPermissions

#permissions, #private?, #public=, #public?

Methods included from TaggedItem

#add_tag, #clear_tags, #tags

Instance Attribute Details

#architectureSymbol (readonly)

The architecture of the image (e.g. :i386).

Returns:

  • (Symbol)

    the current value of architecture



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def architecture
  @architecture
end

#block_device_mappingsHash (readonly)

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 object with the following methods that return information about the block device:

snapshot_id

The ID of the snapshot that will be used to create this device (may be nil).

volume_size

The size of the volume, in GiBs.

delete_on_termination

True if the Amazon EBS volume is deleted on instance termination.

Returns:

  • (Hash)

    the current value of block_device_mappings



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def block_device_mappings
  @block_device_mappings
end

#descriptionString

A description of the image.

Returns:

  • (String)

    the current value of description



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def description
  @description
end

#hypervisorSymbol (readonly)

The image’s hypervisor type. Possible values:

  • :ovm

  • :xen

Returns:

  • (Symbol)

    the current value of hypervisor



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def hypervisor
  @hypervisor
end

#idObject (readonly)

The ID of the AMI.



118
119
120
# File 'lib/aws/ec2/image.rb', line 118

def id
  @id
end

#kernel_idString (readonly)

The kernel ID associated with the image, if any. Only applicable for machine images.

Returns:

  • (String)

    the current value of kernel_id



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def kernel_id
  @kernel_id
end

#locationString (readonly)

The location of the AMI.

Returns:

  • (String)

    the current value of location



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def location
  @location
end

#nameString (readonly)

The name of the AMI that was provided during image creation.

Returns:

  • (String)

    the current value of name



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def name
  @name
end

#owner_aliasString (readonly)

The AWS account alias (e.g., “amazon”) or AWS account ID that owns the AMI.

Returns:

  • (String)

    the current value of owner_alias



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def owner_alias
  @owner_alias
end

#owner_idString (readonly)

AWS account ID of the image owner.

Returns:

  • (String)

    the current value of owner_id



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def owner_id
  @owner_id
end

#platformString (readonly)

Value is windows for Windows AMIs; otherwise blank.

Returns:

  • (String)

    the current value of platform



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def platform
  @platform
end

#product_codesArray<String> (readonly)

Returns an array of product codes attached to this instance.

Returns:

  • (Array<String>)

    the current value of product_codes



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def product_codes
  @product_codes
end

#ramdisk_idString (readonly)

The RAM disk ID associated with the image, if any. Only applicable for machine images.

Returns:

  • (String)

    the current value of ramdisk_id



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def ramdisk_id
  @ramdisk_id
end

#root_device_nameString (readonly)

The root device name (e.g., “/dev/sda1”, or “xvda”).

Returns:

  • (String)

    the current value of root_device_name



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def root_device_name
  @root_device_name
end

#root_device_typeSymbol (readonly)

The root device type used by the AMI. Possible values:

  • :ebs

  • :instance_store

Returns:

  • (Symbol)

    the current value of root_device_type



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def root_device_type
  @root_device_type
end

#stateSymbol (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

Returns:

  • (Symbol)

    the current value of state



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def state
  @state
end

#state_reasonObject (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.

Returns:

  • (Object)

    the current value of state_reason



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def state_reason
  @state_reason
end

#typeSymbol (readonly)

The type of image. Valid values:

  • :machine

  • :kernel

  • :ramdisk

Returns:

  • (Symbol)

    the current value of type



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

def type
  @type
end

#virtualization_typeSymbol (readonly)

The type of virtualization of the AMI. Possible values:

  • :paravirtual

  • :hvm

Returns:

  • (Symbol)

    the current value of virtualization_type



111
112
113
# File 'lib/aws/ec2/image.rb', line 111

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']

Parameters:

  • product_codes (Array<String>)

Returns:

  • (nil)


251
252
253
254
255
256
257
# File 'lib/aws/ec2/image.rb', line 251

def add_product_codes *product_codes
  opts = {}
  opts[:image_id] = self.id
  opts[:product_codes] = product_codes.flatten
  client.modify_image_attribute(opts)
  nil
end

#deregisterObject Also known as: delete

Deregisters this AMI. Once deregistered, the AMI cannot be used to launch new instances.



128
129
130
# File 'lib/aws/ec2/image.rb', line 128

def deregister
  client.deregister_image(:image_id => id)
end

#exists?Boolean

the DescribeImages action).

Returns:

  • (Boolean)

    true if the AMI exists (is returned by



167
168
169
170
171
172
# File 'lib/aws/ec2/image.rb', line 167

def exists?
  resp = client.describe_images(:filters =>
                                [{ :name => "image-id",
                                   :values => [id] }]) and
    !resp.images_set.empty?
end

#kernelImage

Returns The kernel associated with the image, if any. Only applicable for machine images.

Returns:

  • (Image)

    The kernel associated with the image, if any. Only applicable for machine images.



201
202
203
204
205
# File 'lib/aws/ec2/image.rb', line 201

def kernel
  if id = kernel_id
    Image.new(id, :config => config)
  end
end

#ramdiskImage

Returns The RAM disk associated with the image, if any. Only applicable for machine images.

Returns:

  • (Image)

    The RAM disk associated with the image, if any. Only applicable for machine images.



211
212
213
214
215
# File 'lib/aws/ec2/image.rb', line 211

def ramdisk
  if id = ramdisk_id
    Image.new(id, :config => config)
  end
end

#run_instance(opts = {}) ⇒ Instance

Runs a single instance of this image.

Parameters:

Returns:

  • (Instance)

    An object representing the new instance.



140
141
142
143
# File 'lib/aws/ec2/image.rb', line 140

def run_instance(opts = {})
  InstanceCollection.new(:config => config).
    create(opts.merge(:image => self))
end

#run_instances(count, opts = {}) ⇒ Array

Runs multiple instances of this image.

Parameters:

  • count

    How many instances to request. You can specify this either as an integer or as a Range, to indicate the minimum and maximum number of instances to run. Note that for a new account you can request at most 20 instances at a time.

  • opts (Hash) (defaults to: {})

    Additional options for running the instance. See AWS::EC2::InstanceCollection#create for a full list of supported options.

Returns:

  • (Array)

    An array containing an AWS::EC2::Instance object for each instance that was run.



159
160
161
162
163
# File 'lib/aws/ec2/image.rb', line 159

def run_instances(count, opts = {})
  InstanceCollection.new(:config => config).
    create(opts.merge(:image => self,
                      :count => count))
end