class Fog::Hetznercloud::Compute::FloatingIp

Public Instance Methods

assign(serverid) click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 72
def assign(serverid)
  requires :identity
  if serverid.nil?
    body = {}

    if (floating_ip = service.floating_ip_unassign(identity, body).body['floating_ip'])
      merge_attributes(floating_ip)
      true
    else
      false
    end
  else
    server_id = case serverid
                when Fog::Hetznercloud::Compute::Server
                  serverid.identity
                when String
                  service.servers.all(name: serverid).first.identity
                when Integer
                  serverid
                else
                  raise Fog::Hetznercloud::Error::InvalidInputError, 'ERROR: Need Fog::Hetznercloud::Compute::Server|String|Integer'
                              end

    body = {
      server: server_id
    }

    if (floating_ip = service.floating_ip_assign_to_server(identity, body).body['floating_ip'])
      merge_attributes(floating_ip)
      true
    else
      false
    end
  end
end
description=(value) click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 25
def description=(value)
  @lastdescription = attributes[:description]
  attributes[:description] = value
  if @lastdescription && @lastdescription != attributes[:description]
    @needsupdate = true
  else
    @needsupdate = false
  end
end
destroy() click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 57
def destroy
  requires :identity

  service.delete_floating_ip(identity)
  true
end
home_location=(value) click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 35
def home_location=(value)
  attributes[:home_location] = case value
                               when Hash
                                 service.locations.new(value)
                               when String
                                 service.locations.new(identity: value)
                               else
                                 value
                                end
end
save() click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 64
def save
  if persisted?
    reassign && unassign && update
  else
    create
  end
end
server=(value) click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 46
def server=(value)
  attributes[:server] = case value
                        when Hash
                          service.servers.new(value)
                        when Integer
                          service.servers.get(value)
                        else
                          value
                                end
end
type=(value) click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 16
def type=(value)
  valid = %w[ipv4 ipv6]
  if !valid.include? value
    raise Fog::Hetznercloud::Compute::InvalidInputError, "ERROR: floating_ip type must be one of #{valid}"
  else
    attributes[:type] = value
  end
end
unassign() click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 124
def unassign
  assign(nil) unless server.nil?
end
update_dns_ptr(newname) click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 108
def update_dns_ptr(newname)
  requires :identity

  body = {
    ip: ip,
    dns_ptr: newname
  }

  if (floating_ip = service.floating_ip_update_dns_ptr(identity, body).body['floating_ip'])
    merge_attributes(floating_ip)
    true
  else
    false
  end
end

Private Instance Methods

create() click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 130
def create
  requires :type
  requires_one :home_location, :server

  options = {}
  options[:description] = description unless description.nil?
  options[:home_location] = home_location.identity unless home_location.nil?
  options[:server] = server.identity unless server.nil?

  if (floating_ip = service.create_floating_ip(type, options).body['floating_ip'])
    merge_attributes(floating_ip)
    true
  else
    false
  end
end
update() click to toggle source
# File lib/fog/hetznercloud/models/compute/floating_ip.rb, line 147
def update
  return true unless @needsupdate
  requires :identity, :description

  body = attributes.dup

  body[:description] = description

  if (floating_ip = service.update_floating_ip(identity, body).body['floating_ip'])
    merge_attributes(floating_ip)
    true
  else
    false
  end
end