Class: Fog::Compute::Cloudstack::PublicIpAddress
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Cloudstack::PublicIpAddress
- Defined in:
- lib/fog/cloudstack/models/compute/public_ip_address.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(attributes = {}) ⇒ PublicIpAddress
constructor
A new instance of PublicIpAddress.
- #ready? ⇒ Boolean
- #save ⇒ Object
- #server ⇒ Object
- #server=(new_server) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ PublicIpAddress
Returns a new instance of PublicIpAddress.
37 38 39 40 41 |
# File 'lib/fog/cloudstack/models/compute/public_ip_address.rb', line 37 def initialize(attributes = {}) # assign server first to prevent race condition with persisted? self.server = attributes.delete(:server) super end |
Instance Method Details
#destroy ⇒ Object
47 48 49 50 51 |
# File 'lib/fog/cloudstack/models/compute/public_ip_address.rb', line 47 def destroy requires :identity service.disassociate_ip_address('id' => id) true end |
#ready? ⇒ Boolean
43 44 45 |
# File 'lib/fog/cloudstack/models/compute/public_ip_address.rb', line 43 def ready? state == 'Allocated' end |
#save ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fog/cloudstack/models/compute/public_ip_address.rb', line 75 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? = { 'account' => account, 'domainid' => domain_id, 'isportable' => is_portable, 'networkid' => network_id, 'projectid' => project_id, 'vpcid' => vpc_id, 'zoneid' => zone_id, } response = service.associate_ip_address() merge_attributes(response['associateipaddressresponse']) if @server self.server = @server end true end |
#server ⇒ Object
71 72 73 |
# File 'lib/fog/cloudstack/models/compute/public_ip_address.rb', line 71 def server service.servers.get(server_id) end |
#server=(new_server) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/cloudstack/models/compute/public_ip_address.rb', line 53 def server=(new_server) @server = new_server if persisted? if !server_id.nil? && (new_server.nil? || server_id != new_server.id) service.disable_static_nat('ipaddressid' => id) self.server_display_name = nil self.server_id = nil self.server_name = nil self.server_ip_address = nil self.is_static_nat = false end unless new_server.nil? service.enable_static_nat( 'ipaddressid' => id, 'virtualmachineid' => new_server.id) end end end |