Class: Awsum::Ec2::Instance

Inherits:
Object show all
Defined in:
lib/awsum/ec2/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2, id, image_id, type, state, dns_name, private_dns_name, key_name, kernel_id, launch_time, availability_zone, product_codes, ramdisk_id, reason, launch_index) ⇒ Instance

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/awsum/ec2/instance.rb', line 8

def initialize(ec2, id, image_id, type, state, dns_name, private_dns_name, key_name, kernel_id, launch_time, availability_zone, product_codes, ramdisk_id, reason, launch_index) #:nodoc:
  @ec2 = ec2
  @id = id
  @image_id = image_id
  @type = type
  @state = state
  @dns_name = dns_name
  @private_dns_name = private_dns_name
  @key_name = key_name
  @kernel_id = kernel_id
  @launch_time = launch_time
  @availability_zone = availability_zone
  @product_codes = product_codes
  @ramdisk_id = ramdisk_id
  @reason = reason
  @launch_index = launch_index
end

Instance Attribute Details

#availability_zoneObject (readonly)

Returns the value of attribute availability_zone.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def availability_zone
  @availability_zone
end

#dns_nameObject (readonly)

Returns the value of attribute dns_name.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def dns_name
  @dns_name
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def id
  @id
end

#image_idObject (readonly)

Returns the value of attribute image_id.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def image_id
  @image_id
end

#kernel_idObject (readonly)

Returns the value of attribute kernel_id.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def kernel_id
  @kernel_id
end

#key_nameObject (readonly)

Returns the value of attribute key_name.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def key_name
  @key_name
end

#launch_indexObject (readonly)

Returns the value of attribute launch_index.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def launch_index
  @launch_index
end

#launch_timeObject (readonly)

Returns the value of attribute launch_time.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def launch_time
  @launch_time
end

#private_dns_nameObject (readonly)

Returns the value of attribute private_dns_name.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def private_dns_name
  @private_dns_name
end

#product_codesObject (readonly)

Returns the value of attribute product_codes.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def product_codes
  @product_codes
end

#ramdisk_idObject (readonly)

Returns the value of attribute ramdisk_id.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def ramdisk_id
  @ramdisk_id
end

#reasonObject (readonly)

Returns the value of attribute reason.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def reason
  @reason
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def state
  @state
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/awsum/ec2/instance.rb', line 6

def type
  @type
end

Instance Method Details

#attach(volume, device = '/dev/sdh') ⇒ Object

Will attach a Volume to this Instance



81
82
83
# File 'lib/awsum/ec2/instance.rb', line 81

def attach(volume, device = '/dev/sdh')
  @ec2.attach_volume volume.id, id, device
end

#create_volume(size_or_snapshot_id, options = {}) ⇒ Object

Will create and attach a Volume to this Instance You must specify a size or a snapshot_id

Options:

:tags => Hash of tags :device => Will automatically attach the volume to the specified device



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/awsum/ec2/instance.rb', line 61

def create_volume(size_or_snapshot_id, options = {})
  options = {:device => '/dev/sdh'}.merge(options)
  if size_or_snapshot_id.is_a?(Numeric)
    volume = @ec2.create_volume availability_zone, :size => size_or_snapshot_id
  else
    volume = @ec2.create_volume availability_zone, :snapshot_id => size_or_snapshot_id
  end
  if options[:tags]
    @ec2.create_tags(volume.id, options[:tags])
  end
  while volume.status != 'available'
    volume.reload
  end
  if options[:device]
    attach volume, options[:device]
  end
  volume
end

#reloadObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/awsum/ec2/instance.rb', line 26

def reload
  replacement_instance = @ec2.instance id
  #TODO: Make this easier
  @image_id = replacement_instance.image_id
  @type = replacement_instance.type
  @state = replacement_instance.state
  @dns_name = replacement_instance.dns_name
  @private_dns_name = replacement_instance.private_dns_name
  @key_name = replacement_instance.key_name
  @kernel_id = replacement_instance.kernel_id
  @launch_time = replacement_instance.launch_time
  @availability_zone = replacement_instance.availability_zone
  @product_codes = replacement_instance.product_codes
  @ramdisk_id = replacement_instance.ramdisk_id
  @reason = replacement_instance.reason
  @launch_index = replacement_instance.launch_index
end

#terminateObject

Terminates this instance



45
46
47
# File 'lib/awsum/ec2/instance.rb', line 45

def terminate
  @ec2.terminate_instances(id)
end

#volumesObject

Lists all the Volume(s) attached to this Instance



50
51
52
53
# File 'lib/awsum/ec2/instance.rb', line 50

def volumes
  volumes = @ec2.volumes
  volumes.delete_if {|v| v.instance_id != id}
end