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, get_xml_and_update_attributes, #get_xml_and_update_attributes, 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.
106 107 108 109 110 111 112 113 |
# File 'lib/profitbricks/load_balancer.rb', line 106 def create( = {}) [:server_ids] = [:servers].collect { |s| s.id }.join(',') xml = "<arg0>" xml += get_xml_and_update_attributes , [:data_center_id, :lan_id, :ip, :name, :algorithm, :server_ids] xml += "</arg0>" response = Profitbricks.request :create_load_balancer, xml self.find(:id => response.to_hash[:create_load_balancer_response][:return][:load_balancer_id]) end |
.find(options = {}) ⇒ LoadBalancer
Returns information about a virtual load balancer.
120 121 122 123 124 |
# File 'lib/profitbricks/load_balancer.rb', line 120 def find( = {}) raise "Unable to locate the LoadBalancer named '#{[:name]}'" unless [:id] response = Profitbricks.request :get_load_balancer, "<loadBalancerId>#{[:id]}</loadBalancerId>" PB::LoadBalancer.new(response.to_hash[:get_load_balancer_response][:return]) end |
Instance Method Details
#activate_servers(servers) ⇒ Boolean
Enables the load balancer to distribute traffic to the specified servers.
61 62 63 64 65 66 67 |
# File 'lib/profitbricks/load_balancer.rb', line 61 def activate_servers(servers) raise "You have to provide at least one server" unless servers = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id} xml = get_xml_and_update_attributes , [:server_ids, :load_balancer_id] response = Profitbricks.request :activate_load_balancing_on_servers, xml return true if response.to_hash[:activate_load_balancing_on_servers_response][:return] end |
#deactivate_servers(servers) ⇒ Boolean
Disables the load balancer to distribute traffic to the specified servers.
73 74 75 76 77 78 79 |
# File 'lib/profitbricks/load_balancer.rb', line 73 def deactivate_servers(servers) raise "You have to provide at least one server" unless servers = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id} xml = get_xml_and_update_attributes , [:server_ids, :load_balancer_id] response = Profitbricks.request :deactivate_load_balancing_on_servers, xml return true if response.to_hash[:deactivate_load_balancing_on_servers_response][:return] 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.
86 87 88 89 |
# File 'lib/profitbricks/load_balancer.rb', line 86 def delete response = Profitbricks.request :delete_load_balancer, "<loadBalancerId>#{self.id}</loadBalancerId>" return true if response.to_hash[:delete_load_balancer_response][:return] 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.
49 50 51 52 53 54 55 |
# File 'lib/profitbricks/load_balancer.rb', line 49 def deregister_servers(servers) raise "You have to provide at least one server" unless servers = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id} xml = get_xml_and_update_attributes , [:server_ids, :load_balancer_id] response = Profitbricks.request :deregister_servers_on_load_balancer, xml return true if response.to_hash[:deregister_servers_on_load_balancer_response][:return] 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.
32 33 34 35 36 37 38 39 |
# File 'lib/profitbricks/load_balancer.rb', line 32 def register_servers(servers) raise "You have to provide at least one server" unless servers = {:server_ids => servers.collect { |s| s.id }.join(','), :load_balancer_id=> self.id} xml = get_xml_and_update_attributes , [:server_ids, :load_balancer_id] response = Profitbricks.request :register_servers_on_load_balancer, xml update_attributes(response.to_hash[:register_servers_on_load_balancer_response][:return]) return true if response.to_hash[:register_servers_on_load_balancer_response][:return] end |
#update(options = {}) ⇒ Boolean
Changes the settings of an existing virtual load balancer.
13 14 15 16 17 18 19 20 21 |
# File 'lib/profitbricks/load_balancer.rb', line 13 def update( = {}) .merge!(:load_balancer_id=> self.id) xml = "<arg0>" xml += get_xml_and_update_attributes , [:load_balancer_id, :ip, :name, :algorithm] xml += "</arg0>" response = Profitbricks.request :update_load_balancer, xml self.reload return true if response.to_hash[:update_load_balancer_response][:return] end |