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, #load, #merge_attributes, model, #model, #reload, #table

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
# File 'lib/fog/aws/models/ec2/addresses.rb', line 23

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

#get(public_ip) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/fog/aws/models/ec2/addresses.rb', line 36

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

#new(attributes = {}) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/fog/aws/models/ec2/addresses.rb', line 44

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