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

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Address

Returns a new instance of Address.



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

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

Instance Method Details

#change_scopeObject



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

def change_scope
  if self.domain == 'standard'
    service.move_address_to_vpc(self.identity)
    wait_for { self.domain == 'vpc' }
  else
    service.restore_address_to_classic(self.identity)
    wait_for { self.domain == 'standard' }
  end
end

#destroyObject



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

def destroy
  requires :public_ip

  service.release_address(allocation_id || public_ip)
  true
end

#saveObject

Raises:

  • (Fog::Errors::Error)


51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/aws/models/compute/address.rb', line 51

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



47
48
49
# File 'lib/fog/aws/models/compute/address.rb', line 47

def server
  service.servers.get(server_id)
end

#server=(new_server) ⇒ Object



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

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