Class: Awsum::Ec2::Address

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2, public_ip, instance_id) ⇒ Address

:nodoc:



6
7
8
9
10
# File 'lib/ec2/address.rb', line 6

def initialize(ec2, public_ip, instance_id) #:nodoc:
  @ec2 = ec2
  @public_ip = public_ip
  @instance_id = instance_id
end

Instance Attribute Details

#instance_idObject (readonly)

Returns the value of attribute instance_id.



4
5
6
# File 'lib/ec2/address.rb', line 4

def instance_id
  @instance_id
end

#public_ipObject (readonly)

Returns the value of attribute public_ip.



4
5
6
# File 'lib/ec2/address.rb', line 4

def public_ip
  @public_ip
end

Instance Method Details

#associate(instance_id) ⇒ Object

Will associate this address with an instance

Raises an error if the address is already associated with an instance



22
23
24
25
26
27
28
# File 'lib/ec2/address.rb', line 22

def associate(instance_id)
  if @instance_id.nil?
    @ec2.associate_address instance_id, @public_ip
  else
    raise 'Cannot associate with an already associated instance' #FIXME: Write a better Awsum error here'
  end
end

#disassociateObject

Will disassociate this address from it’s instance

Raises an error if the address is not associated with an instance



33
34
35
36
37
38
39
40
41
# File 'lib/ec2/address.rb', line 33

def disassociate
  if @instance_id.nil?
    raise 'Not associated' #FIXME: Write a better Awsum error here'
  else
    result = @ec2.disassociate_address @public_ip
    @instance_id = nil
    result
  end
end

#instanceObject

Get the Instance associated with this address.

Returns nil if no instance is associated.



15
16
17
# File 'lib/ec2/address.rb', line 15

def instance
  @ec2.instance(@instance_id) if @instance_id
end

#releaseObject

Will release this address

Raises an error if the address is associated with an instance



46
47
48
49
50
51
52
# File 'lib/ec2/address.rb', line 46

def release
  if @instance_id.nil?
    @ec2.release_address @public_ip
  else
    raise 'Associated with an instance' #FIXME: Write a better Awsum error here'
  end
end

#release!Object

Will release this address regardless of whether it is associated with an instance or not.



55
56
57
# File 'lib/ec2/address.rb', line 55

def release!
  @ec2.release_address! @public_ip
end