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.
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/profitbricks/load_balancer.rb', line 118 def create( = {}) xml = "<arg0>" xml += get_xml_and_update_attributes , [:data_center_id, :lan_id, :ip, :name, :algorithm] unless [:servers].nil? [:servers].each do |server| xml += "<serverIds>#{server.id}</serverIds>" end end 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.
136 137 138 139 140 |
# File 'lib/profitbricks/load_balancer.rb', line 136 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.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/profitbricks/load_balancer.rb', line 67 def activate_servers(servers) raise "You have to provide at least one server" unless servers = {:load_balancer_id => self.id} xml = get_xml_and_update_attributes , [:load_balancer_id] servers.each do |server| xml += "<serverIds>#{server.id}</serverIds>" end 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.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/profitbricks/load_balancer.rb', line 82 def deactivate_servers(servers) raise "You have to provide at least one server" unless servers = {:load_balancer_id => self.id} xml = get_xml_and_update_attributes , [:load_balancer_id] servers.each do |server| xml += "<serverIds>#{server.id}</serverIds>" end 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.
98 99 100 101 |
# File 'lib/profitbricks/load_balancer.rb', line 98 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.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/profitbricks/load_balancer.rb', line 52 def deregister_servers(servers) raise "You have to provide at least one server" unless servers = {:load_balancer_id => self.id} xml = get_xml_and_update_attributes , [:load_balancer_id] servers.each do |server| xml += "<serverIds>#{server.id}</serverIds>" end 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 40 41 42 |
# File 'lib/profitbricks/load_balancer.rb', line 32 def register_servers(servers) raise "You have to provide at least one server" unless servers = {:load_balancer_id => self.id} xml = get_xml_and_update_attributes , [:load_balancer_id] servers.each do |server| xml += "<serverIds>#{server.id}</serverIds>" end 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 |