Class: Awsum::Ec2::Address

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2, public_ip, instance_id) ⇒ Address

:nodoc:



8
9
10
11
12
# File 'lib/awsum/ec2/address.rb', line 8

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.



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

def instance_id
  @instance_id
end

#public_ipObject (readonly)

Returns the value of attribute public_ip.



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

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



24
25
26
27
28
29
30
# File 'lib/awsum/ec2/address.rb', line 24

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

#associate!(instance_id) ⇒ Object

Will associate this address with an instance (even if it is already associated with another instance)



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

def associate!(instance_id)
  @ec2.associate_address instance_id, @public_ip
end

#disassociateObject

Will disassociate this address from it’s instance

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



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

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.



17
18
19
# File 'lib/awsum/ec2/address.rb', line 17

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



53
54
55
56
57
58
59
# File 'lib/awsum/ec2/address.rb', line 53

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.



62
63
64
# File 'lib/awsum/ec2/address.rb', line 62

def release!
  @ec2.release_address! @public_ip
end