Class: OpenStack::Nova::Compute::FloatingIp

Inherits:
Base show all
Defined in:
lib/open_stack/nova/compute/floating_ip.rb

Overview

An OpenStack Floating Ip

Attributes

  • ip - Floating IP(v4/v6) address

  • fixed_ip - Fixed IP(v4/V6) address

  • pool - The id of the pool this IP belongs to

  • instance_id - Identifier of server this IPis assigned to (if any)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

site, site=

Methods inherited from Common

collection_path, custom_method_collection_url, element_path

Methods inherited from Base

headers

Methods inherited from ActiveResource::Base

#load

Class Method Details

.find_all_by_pool(pool) ⇒ Object

List of addresses for a given pool

Attributes

  • pool - an instance of OpenStack::Nova::Compute::FloatingIpPool or a pool id



53
54
55
56
# File 'lib/open_stack/nova/compute/floating_ip.rb', line 53

def self.find_all_by_pool(pool)
  pool_id = pool.is_a?(OpenStack::Nova::Compute::FloatingIpPool) ? pool.id : pool
  all.reject! { |floating_ip| floating_ip.pool != pool_id }
end

Instance Method Details

#assign!(server) ⇒ Object

Assign the IP to a server

Attributes:

  • server - An instance of OpenStack::Nova::Compute::Server (or a server id) to assign the floating IP to



69
70
71
72
73
74
75
# File 'lib/open_stack/nova/compute/floating_ip.rb', line 69

def assign!(server)
  server_instance = server.is_a?(OpenStack::Nova::Compute::Server) ? server : Server.find(server)
  @instance = server_instance
  self.instance_id = server_instance.id

  server_instance.add_floating_ip(self)
end

#encode(options = {}) ⇒ Object

Overloads ActiveRecord::encode method



41
42
43
44
45
46
47
# File 'lib/open_stack/nova/compute/floating_ip.rb', line 41

def encode(options={}) # :nodoc: Custom encoding to deal with openstack API
  to_encode = {}
  # Optional attributes (openstack will not accept empty attribute for update/create)
  to_encode[:pool] = pool if pool.present?

  to_encode.send("to_#{self.class.format.extension}", options)
end

#instanceObject

The OpenStack::Nova::Compute::Server instance this address belongs to (if any)



59
60
61
62
63
# File 'lib/open_stack/nova/compute/floating_ip.rb', line 59

def instance
  if instance_id
    @instance ||= Server.find(instance_id)
  end
end