class Fog::Compute::Cloudstack::PublicIpAddress

Public Class Methods

new(attributes = {}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

destroy() click to toggle source
# 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?() click to toggle source
# File lib/fog/cloudstack/models/compute/public_ip_address.rb, line 43
def ready?
  state == 'Allocated'
end
save() click to toggle source
# 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?
  options = {
    '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(options)
  merge_attributes(response['associateipaddressresponse'])
  if @server
    self.server = @server
  end
  true
end
server() click to toggle source
# File lib/fog/cloudstack/models/compute/public_ip_address.rb, line 71
def server
  service.servers.get(server_id)
end
server=(new_server) click to toggle source
# 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