Class: Standup::EC2::ElasticIP

Inherits:
Base
  • Object
show all
Defined in:
lib/standup/ec2/elastic_ip.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#exists?, info_reader

Constructor Details

#initialize(ip, info = false) ⇒ ElasticIP

Returns a new instance of ElasticIP.



4
5
6
7
# File 'lib/standup/ec2/elastic_ip.rb', line 4

def initialize ip, info = false
  @ip = ip
  super info
end

Class Method Details

.createObject



22
23
24
25
# File 'lib/standup/ec2/elastic_ip.rb', line 22

def self.create
  ip = api.allocate_address.publicIp
  list[ip] = ElasticIP.new ip
end

.list(reload = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/standup/ec2/elastic_ip.rb', line 11

def self.list reload = false
  if !class_variable_defined?(:@@list) || reload
    @@list = {}
    result = api.describe_addresses
    result.addressesSet.item.each do |item|
      @@list[item.publicIp] = new item.publicIp, :attached_to => Instance.new(item.instanceId)
    end if result.addressesSet
  end
  @@list
end

Instance Method Details

#attach_to(instance) ⇒ Object



32
33
34
35
36
# File 'lib/standup/ec2/elastic_ip.rb', line 32

def attach_to instance
  api.associate_address :instance_id => instance.id,
                        :public_ip => @ip
  @attached_to = instance
end

#destroyObject



27
28
29
30
# File 'lib/standup/ec2/elastic_ip.rb', line 27

def destroy
  api.release_address :public_ip => @ip
  list.delete @ip
end

#detachObject



38
39
40
41
# File 'lib/standup/ec2/elastic_ip.rb', line 38

def detach
  api.disassociate_address :public_ip => @ip
  @attached_to = nil
end

#load_infoObject



43
44
45
46
# File 'lib/standup/ec2/elastic_ip.rb', line 43

def load_info
  result = api.describe_addresses :public_ip => @ip
  @attached_to = Instance.new(result.addressesSet.item[0].instanceId)
end