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

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

Instance Attribute Summary

Attributes inherited from Collection

#connection

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #inspect, #load, model, #model, #reload, #table, #to_json

Methods included from Fog::Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Attributes::InstanceMethods

#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes) ⇒ Addresses

Returns a new instance of Addresses.



23
24
25
26
# File 'lib/fog/aws/models/ec2/addresses.rb', line 23

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

Instance Method Details

#all(public_ip = @public_ip) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/aws/models/ec2/addresses.rb', line 28

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.server_id == server.id})
  end
  self
end

#get(public_ip) ⇒ Object



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

def get(public_ip)
  if public_ip
    all(public_ip).first
  end
rescue Fog::Errors::NotFound
  nil
end

#new(attributes = {}) ⇒ Object



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

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