Class: Serverspec::Type::AWS::EC2::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/resources/ec2/image.rb

Overview

The Instance class exposes the EC2::Image resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_id_name, instance = nil) ⇒ Image

AWS SDK for Ruby v2 Aws::EC2::Client wrapper for initializing an Instance resource

Parameters:

  • image_id_name (Array)

    The ID or Name tag of the Image

  • instance (Class) (defaults to: nil)

    Aws::EC2::Client instance

Raises:

  • (RuntimeError)

    if image_id_name.nil?

  • (RuntimeError)

    if image_id_name.length == 0

  • (RuntimeError)

    if image_id_name.length > 1



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/resources/ec2/image.rb', line 22

def initialize(image_id_name, instance = nil)
  check_init_arg 'image_id_name', 'EC2::image', image_id_name
  @aws = instance.nil? ? Aws::EC2::Client.new : instance
  if image_id_name.match(/^ami-[A-Fa-f0-9]{8,17}$/).nil?
    @image_name = image_id_name
    get_image_by_name image_id_name
  else
    @image_id = image_id_name
    get_image_by_id image_id_name
  end
end

Instance Attribute Details

#image_idObject (readonly)

The ID of the AMI



13
14
15
# File 'lib/resources/ec2/image.rb', line 13

def image_id
  @image_id
end

#image_nameObject (readonly)

The Name tag of the Instance (if available)



11
12
13
# File 'lib/resources/ec2/image.rb', line 11

def image_name
  @image_name
end

#instance_idObject (readonly)

The ID of the Instance



9
10
11
# File 'lib/resources/ec2/image.rb', line 9

def instance_id
  @instance_id
end

Instance Method Details

#root_volumeObject



41
42
43
44
45
46
# File 'lib/resources/ec2/image.rb', line 41

def root_volume
  root_vol = @image.block_device_mappings.first do |vol|
    vol.device_name == @image.root_device_name
  end
  Volume.new(root_vol, @image.root_device_type)
end

#to_sString

Returns the string representation of EC2::Instance

Returns:

  • (String)


36
37
38
39
# File 'lib/resources/ec2/image.rb', line 36

def to_s
  return "EC2 Image ID: #{@image_id}" if @image_name.nil?
  "EC2 Image ID: #{@image_id}; Name: #{@image_name}"
end