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



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

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

#create_volume(size = nil, snapshot_id = nil, device = '/dev/sdh') ⇒ Object

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

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/awsum/ec2/instance.rb', line 39

def create_volume(size = nil, snapshot_id = nil, device = '/dev/sdh')
  raise ArgumentError.new('You must specify a size if not creating a volume from a snapshot') if size.blank? && snapshot_id.blank?
  raise ArgumentError.new('You must specify a device to attach the volume to') unless device

  volume = @ec2.create_volume availability_zone, :size => size, :snapshot_id => snapshot_id
  while volume.status != 'available'
    volume.reload
  end
  attach volume, device
  volume
end

#terminateObject

Terminates this instance



27
28
29
# File 'lib/awsum/ec2/instance.rb', line 27

def terminate
  @ec2.terminate_instances(id)
end

#volumesObject

Lists all the Volume(s) attached to this Instance



32
33
34
35
# File 'lib/awsum/ec2/instance.rb', line 32

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