Class: Profitbricks::LoadBalancer
- Defined in:
- lib/profitbricks/load_balancer.rb
Class Method Summary collapse
-
.create(options = {}) ⇒ LoadBalancer
Creates a virtual Load Balancer within an existing virtual data center.
-
.find(options = {}) ⇒ LoadBalancer
Returns information about a virtual load balancer.
Instance Method Summary collapse
-
#activate_servers(servers) ⇒ Boolean
Enables the load balancer to distribute traffic to the specified servers.
-
#deactivate_servers(servers) ⇒ Boolean
Disables the load balancer to distribute traffic to the specified servers.
-
#delete ⇒ Boolean
Deletes an existing load balancer.
-
#deregister_servers(servers) ⇒ Boolean
Removes servers from the load balancer.
-
#register_servers(servers) ⇒ Boolean
Adds new servers to the Load Balancer within the respective LAN.
-
#update(options = {}) ⇒ Boolean
Changes the settings of an existing virtual load balancer.
Methods inherited from Model
#attributes, belongs_to, has_many, #initialize, #reload
Constructor Details
This class inherits a constructor from Profitbricks::Model
Class Method Details
.create(options = {}) ⇒ LoadBalancer
Creates a virtual Load Balancer within an existing virtual data center.
A Load Balancer connected to a LAN will not distribute traffic to any server, until it is specified to do so. In the current version, a Load Balancer cannot distribute traffic across multiple data centers or LANs. Load Balancer and servers must always be in the same LAN.
100 101 102 103 104 |
# File 'lib/profitbricks/load_balancer.rb', line 100 def create( = {}) [:server_ids] = .delete(:servers).collect(&:id) if [:servers] response = Profitbricks.request :create_load_balancer, self.find(:id => response[:load_balancer_id]) end |
.find(options = {}) ⇒ LoadBalancer
Returns information about a virtual load balancer.
111 112 113 114 115 |
# File 'lib/profitbricks/load_balancer.rb', line 111 def find( = {}) raise "Unable to locate the LoadBalancer named '#{[:name]}'" unless [:id] response = Profitbricks.request :get_load_balancer, load_balancer_id: [:id] PB::LoadBalancer.new(response) end |
Instance Method Details
#activate_servers(servers) ⇒ Boolean
Enables the load balancer to distribute traffic to the specified servers.
57 58 59 60 61 62 |
# File 'lib/profitbricks/load_balancer.rb', line 57 def activate_servers(servers) raise "You have to provide at least one server" unless servers = {load_balancer_id: self.id, server_ids: servers.collect(&:id)} response = Profitbricks.request :activate_load_balancing_on_servers, return true end |
#deactivate_servers(servers) ⇒ Boolean
Disables the load balancer to distribute traffic to the specified servers.
68 69 70 71 72 73 |
# File 'lib/profitbricks/load_balancer.rb', line 68 def deactivate_servers(servers) raise "You have to provide at least one server" unless servers = {load_balancer_id: self.id, server_ids: servers.collect(&:id)} response = Profitbricks.request :deactivate_load_balancing_on_servers, return true end |
#delete ⇒ Boolean
Deletes an existing load balancer. Primary IP addresses of the server’s previously balanced NICs are reset and replaced with ProfitBricks assigned IP address. If a load balancer has been deleted, all servers will still be connected to the same LAN though.
80 81 82 83 |
# File 'lib/profitbricks/load_balancer.rb', line 80 def delete Profitbricks.request :delete_load_balancer, load_balancer_id: self.id return true end |
#deregister_servers(servers) ⇒ Boolean
Removes servers from the load balancer
By deregistering a server, the server is being removed from the load balancer but still remains connected to the same LAN. The primary IP address of the NIC, through which the load balancer distributed traffic to the server before, is reset and replaced by a ProfitBricks assigned IP address.
46 47 48 49 50 51 |
# File 'lib/profitbricks/load_balancer.rb', line 46 def deregister_servers(servers) raise "You have to provide at least one server" unless servers = {load_balancer_id: self.id, server_ids: servers.collect(&:id)} response = Profitbricks.request :deregister_servers_on_load_balancer, return true end |
#register_servers(servers) ⇒ Boolean
Adds new servers to the Load Balancer within the respective LAN.
If the server is not yet a member of the LAN, a new NIC is created, connected to the LAN and registered with the Load Balancer. The load balancer will distribute traffic to the server through this balanced NIC. If the server is already a member of the LAN, the appropriate NIC is used as balanced NIC. A server can be registered to more than one Load Balancer.
30 31 32 33 34 35 36 |
# File 'lib/profitbricks/load_balancer.rb', line 30 def register_servers(servers) raise "You have to provide at least one server" unless servers = {load_balancer_id: self.id, server_ids: servers.collect(&:id)} response = Profitbricks.request :register_servers_on_load_balancer, self.reload return true end |
#update(options = {}) ⇒ Boolean
Changes the settings of an existing virtual load balancer.
13 14 15 16 17 18 19 |
# File 'lib/profitbricks/load_balancer.rb', line 13 def update( = {}) .merge!(:load_balancer_id=> self.id) [:load_balancer_name] = .delete :name response = Profitbricks.request :update_load_balancer, self.reload return true end |