Class: Fog::Compute::AWS::Address

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/compute/address.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

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

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Address

Returns a new instance of Address.



18
19
20
21
22
# File 'lib/fog/aws/models/compute/address.rb', line 18

def initialize(attributes = {})
  # assign server first to prevent race condition with persisted?
  self.server = attributes.delete(:server)
  super
end

Instance Method Details

#destroyObject



24
25
26
27
28
29
# File 'lib/fog/aws/models/compute/address.rb', line 24

def destroy
  requires :public_ip

  service.release_address(allocation_id || public_ip)
  true
end

#saveObject

Raises:



43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/aws/models/compute/address.rb', line 43

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  data = service.allocate_address(domain).body
  new_attributes = data.reject {|key,value| key == 'requestId'}
  merge_attributes(new_attributes)
  if @server
    self.server = @server
  end
  true
end

#serverObject



39
40
41
# File 'lib/fog/aws/models/compute/address.rb', line 39

def server
  service.servers.get(server_id)
end

#server=(new_server) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/fog/aws/models/compute/address.rb', line 31

def server=(new_server)
  if new_server
    associate(new_server)
  else
    disassociate
  end
end