Class: Fog::AWS::EC2::Addresses

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/aws/models/ec2/addresses.rb

Instance Method Summary collapse

Methods inherited from Collection

#_dump, _load, aliases, attribute, attributes, #attributes, #connection, #connection=, #create, #inspect, #merge_attributes, model, #model, #reload

Constructor Details

#initialize(attributes) ⇒ Addresses

Returns a new instance of Addresses.



18
19
20
21
# File 'lib/fog/aws/models/ec2/addresses.rb', line 18

def initialize(attributes)
  @public_ip ||= []
  super
end

Instance Method Details

#all(public_ip = @public_ip) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/aws/models/ec2/addresses.rb', line 23

def all(public_ip = @public_ip)
  @public_ip = public_ip
  if @loaded
    clear
  end
  @loaded = true
  data = connection.describe_addresses(public_ip).body
  addresses = []
  data['addressesSet'].each do |address|
    addresses << new(address.reject {|key, value| value.nil? || value.empty? })
  end
  if server
    addresses = addresses.select {|address| address.instance_id == server.id}
  end
  self.replace(addresses)
end

#get(public_ip) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fog/aws/models/ec2/addresses.rb', line 40

def get(public_ip)
  if public_ip
    all(public_ip).first
  end
rescue Excon::Errors::BadRequest
  nil
end

#new(attributes = {}) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/fog/aws/models/ec2/addresses.rb', line 48

def new(attributes = {})
  if server
    super({ :server => server }.merge!(attributes))
  else
    super(attributes)
  end
end