Class: Fog::OpenStack::Compute::Address
- Defined in:
- lib/fog/openstack/compute/models/address.rb
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(attributes = {}) ⇒ Address
constructor
A new instance of Address.
- #save ⇒ Object
- #server=(new_server) ⇒ Object
Methods inherited from Model
Constructor Details
#initialize(attributes = {}) ⇒ Address
Returns a new instance of Address.
14 15 16 17 18 |
# File 'lib/fog/openstack/compute/models/address.rb', line 14 def initialize(attributes = {}) # assign server first to prevent race condition with persisted? self.server = attributes.delete(:server) super end |
Instance Method Details
#destroy ⇒ Object
20 21 22 23 24 |
# File 'lib/fog/openstack/compute/models/address.rb', line 20 def destroy requires :id service.release_address(id) true end |
#save ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/openstack/compute/models/address.rb', line 34 def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? data = service.allocate_address(pool).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
26 27 28 29 30 31 32 |
# File 'lib/fog/openstack/compute/models/address.rb', line 26 def server=(new_server) if new_server associate(new_server) else disassociate end end |