Class: Fog::Compute::HPV2::Address

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Address

Returns a new instance of Address.



13
14
15
16
17
# File 'lib/fog/hp/models/compute_v2/address.rb', line 13

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

Instance Method Details

#destroyObject



19
20
21
22
23
# File 'lib/fog/hp/models/compute_v2/address.rb', line 19

def destroy
  requires :id
  service.release_address(id)
  true
end

#saveObject

Raises:

  • (Fog::Errors::Error)


33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/hp/models/compute_v2/address.rb', line 33

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  data = service.allocate_address.body['floating_ip']
  new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
  merge_attributes(new_attributes)
  if @server
    self.server = @server
  end
  true
end

#server=(new_server) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/fog/hp/models/compute_v2/address.rb', line 25

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