Class: Fog::Rackspace::LoadBalancers::Real
- Inherits:
-
Object
- Object
- Fog::Rackspace::LoadBalancers::Real
- Includes:
- Shared
- Defined in:
- lib/fog/rackspace/load_balancers.rb,
lib/fog/rackspace/requests/load_balancers/get_node.rb,
lib/fog/rackspace/requests/load_balancers/get_usage.rb,
lib/fog/rackspace/requests/load_balancers/list_nodes.rb,
lib/fog/rackspace/requests/load_balancers/create_node.rb,
lib/fog/rackspace/requests/load_balancers/delete_node.rb,
lib/fog/rackspace/requests/load_balancers/get_monitor.rb,
lib/fog/rackspace/requests/load_balancers/set_monitor.rb,
lib/fog/rackspace/requests/load_balancers/update_node.rb,
lib/fog/rackspace/requests/load_balancers/delete_nodes.rb,
lib/fog/rackspace/requests/load_balancers/list_protocols.rb,
lib/fog/rackspace/requests/load_balancers/remove_monitor.rb,
lib/fog/rackspace/requests/load_balancers/list_algorithms.rb,
lib/fog/rackspace/requests/load_balancers/list_virtual_ips.rb,
lib/fog/rackspace/requests/load_balancers/create_virtual_ip.rb,
lib/fog/rackspace/requests/load_balancers/delete_virtual_ip.rb,
lib/fog/rackspace/requests/load_balancers/get_load_balancer.rb,
lib/fog/rackspace/requests/load_balancers/list_access_rules.rb,
lib/fog/rackspace/requests/load_balancers/create_access_rule.rb,
lib/fog/rackspace/requests/load_balancers/delete_access_rule.rb,
lib/fog/rackspace/requests/load_balancers/list_load_balancers.rb,
lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb,
lib/fog/rackspace/requests/load_balancers/delete_load_balancer.rb,
lib/fog/rackspace/requests/load_balancers/update_load_balancer.rb,
lib/fog/rackspace/requests/load_balancers/get_connection_logging.rb,
lib/fog/rackspace/requests/load_balancers/set_connection_logging.rb,
lib/fog/rackspace/requests/load_balancers/delete_all_access_rules.rb,
lib/fog/rackspace/requests/load_balancers/get_load_balancer_usage.rb,
lib/fog/rackspace/requests/load_balancers/get_session_persistence.rb,
lib/fog/rackspace/requests/load_balancers/set_session_persistence.rb,
lib/fog/rackspace/requests/load_balancers/get_connection_throttling.rb,
lib/fog/rackspace/requests/load_balancers/set_connection_throttling.rb,
lib/fog/rackspace/requests/load_balancers/remove_session_persistence.rb,
lib/fog/rackspace/requests/load_balancers/remove_connection_throttling.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #create_access_rule(load_balancer_id, address, type) ⇒ Object
- #create_load_balancer(name, protocol, port, virtual_ips, nodes) ⇒ Object
- #create_node(load_balancer_id, address, port, condition, options = {}) ⇒ Object
- #create_virtual_ip(load_balancer_id, type) ⇒ Object
- #delete_access_rule(load_balancer_id, access_rule_id) ⇒ Object
- #delete_all_access_rules(load_balancer_id) ⇒ Object
- #delete_load_balancer(load_balancer_id) ⇒ Object
- #delete_node(load_balancer_id, node_id) ⇒ Object
- #delete_nodes(load_balancer_id, *node_ids) ⇒ Object
- #delete_virtual_ip(load_balancer_id, virtual_ip_id) ⇒ Object
- #get_connection_logging(load_balancer_id) ⇒ Object
- #get_connection_throttling(load_balancer_id) ⇒ Object
- #get_load_balancer(load_balancer_id) ⇒ Object
- #get_load_balancer_usage(load_balancer_id, options = {}) ⇒ Object
- #get_monitor(load_balancer_id) ⇒ Object
- #get_node(load_balancer_id, node_id) ⇒ Object
- #get_session_persistence(load_balancer_id) ⇒ Object
- #get_usage(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_access_rules(load_balancer_id) ⇒ Object
- #list_algorithms ⇒ Object
- #list_load_balancers ⇒ Object
- #list_nodes(load_balancer_id) ⇒ Object
- #list_protocols ⇒ Object
- #list_virtual_ips(load_balancer_id) ⇒ Object
- #remove_connection_throttling(load_balancer_id) ⇒ Object
- #remove_monitor(load_balancer_id) ⇒ Object
- #remove_session_persistence(load_balancer_id) ⇒ Object
- #request(params) ⇒ Object
- #set_connection_logging(load_balancer_id, value) ⇒ Object
- #set_connection_throttling(load_balancer_id, max_connections, min_connections, max_connection_rate, rate_interval) ⇒ Object
- #set_monitor(load_balancer_id, type, delay, timeout, attempsBeforeDeactivation, options = {}) ⇒ Object
- #set_session_persistence(load_balancer_id, persistence_type) ⇒ Object
- #update_load_balancer(load_balancer_id, options = {}) ⇒ Object
- #update_node(load_balancer_id, node_id, options = {}) ⇒ Object
Methods included from Shared
#algorithms, #protocols, #usage
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fog/rackspace/load_balancers.rb', line 95 def initialize(={}) require 'multi_json' @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @rackspace_auth_url = [:rackspace_auth_url] @rackspace_must_reauthenticate = false @connection_options = [:connection_options] || {} uri = URI.parse([:rackspace_lb_endpoint] || DFW_ENDPOINT) @host = uri.host @persistent = [:persistent] || false @path = uri.path @port = uri.port @scheme = uri.scheme authenticate @connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options) end |
Instance Method Details
#authenticate ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/fog/rackspace/load_balancers.rb', line 140 def authenticate = { :rackspace_api_key => @rackspace_api_key, :rackspace_username => @rackspace_username, :rackspace_auth_url => @rackspace_auth_url } credentials = Fog::Rackspace.authenticate(, @connection_options) @auth_token = credentials['X-Auth-Token'] account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1] @path = "#{@path}/#{account_id}" end |
#create_access_rule(load_balancer_id, address, type) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/rackspace/requests/load_balancers/create_access_rule.rb', line 5 def create_access_rule(load_balancer_id, address, type) #TODO - This can actually support adding multiple access rules. data = { 'accessList' => [ { 'address' => address, 'type' => type } ]} request( :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "loadbalancers/#{load_balancer_id}/accesslist" ) end |
#create_load_balancer(name, protocol, port, virtual_ips, nodes) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb', line 5 def create_load_balancer(name, protocol, port, virtual_ips, nodes) data = { 'loadBalancer' => { 'name' => name, 'port' => port, 'protocol' => protocol, 'virtualIps' => virtual_ips, 'nodes' => nodes #Is algorithm allowed on create? } } request( :body => MultiJson.encode(data), :expects => 202, :method => 'POST', :path => 'loadbalancers.json' ) end |
#create_node(load_balancer_id, address, port, condition, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/rackspace/requests/load_balancers/create_node.rb', line 5 def create_node(load_balancer_id, address, port, condition, = {}) data = { 'nodes' => [ { 'address' => address, 'port' => port, 'condition' => condition } ]} if .has_key?(:weight) data['nodes'][0]['weight'] = [:weight] end request( :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "loadbalancers/#{load_balancer_id}/nodes.json" ) end |
#create_virtual_ip(load_balancer_id, type) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/rackspace/requests/load_balancers/create_virtual_ip.rb', line 5 def create_virtual_ip(load_balancer_id, type) data = { 'type' => type, 'ipVersion' => 'IPV6' } request( :body => MultiJson.encode(data), :expects => [200, 202], :method => 'POST', :path => "loadbalancers/#{load_balancer_id}/virtualips.json" ) end |
#delete_access_rule(load_balancer_id, access_rule_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/delete_access_rule.rb', line 5 def delete_access_rule(load_balancer_id, access_rule_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/accesslist/#{access_rule_id}", :method => 'DELETE' ) end |
#delete_all_access_rules(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/delete_all_access_rules.rb', line 5 def delete_all_access_rules(load_balancer_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/accesslist", :method => 'DELETE' ) end |
#delete_load_balancer(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/delete_load_balancer.rb', line 5 def delete_load_balancer(load_balancer_id) request( :expects => 202, :path => "loadbalancers/#{load_balancer_id}.json", :method => 'DELETE' ) end |
#delete_node(load_balancer_id, node_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/delete_node.rb', line 5 def delete_node(load_balancer_id, node_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}", :method => 'DELETE' ) end |
#delete_nodes(load_balancer_id, *node_ids) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/rackspace/requests/load_balancers/delete_nodes.rb', line 5 def delete_nodes(load_balancer_id, *node_ids) query_string = node_ids.collect { |node_id| "id=#{node_id}" }.join('&') puts query_string request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/nodes?#{node_ids}", :method => 'DELETE' ) end |
#delete_virtual_ip(load_balancer_id, virtual_ip_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/delete_virtual_ip.rb', line 5 def delete_virtual_ip(load_balancer_id, virtual_ip_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/virtualips/#{virtual_ip_id}", :method => 'DELETE' ) end |
#get_connection_logging(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/get_connection_logging.rb', line 5 def get_connection_logging(load_balancer_id) request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}/connectionlogging", :method => 'GET' ) end |
#get_connection_throttling(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/get_connection_throttling.rb', line 5 def get_connection_throttling(load_balancer_id) request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}/connectionthrottle", :method => 'GET' ) end |
#get_load_balancer(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/get_load_balancer.rb', line 5 def get_load_balancer(load_balancer_id) request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}.json", :method => 'GET' ) end |
#get_load_balancer_usage(load_balancer_id, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/rackspace/requests/load_balancers/get_load_balancer_usage.rb', line 5 def get_load_balancer_usage(load_balancer_id, = {}) #TODO - Didn't implement usage/current. Not sure if it is needed if .has_key? :start_time and .has_key? :end_time query = "?startTime=#{[:start_time]}&endTime=#{[:end_time]}" else query = '' end request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}/usage#{query}", :method => 'GET' ) end |
#get_monitor(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/get_monitor.rb', line 5 def get_monitor(load_balancer_id) request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}/healthmonitor", :method => 'GET' ) end |
#get_node(load_balancer_id, node_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/get_node.rb', line 5 def get_node(load_balancer_id, node_id) request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}.json", :method => 'GET' ) end |
#get_session_persistence(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/get_session_persistence.rb', line 5 def get_session_persistence(load_balancer_id) request( :expects => 200, :path => "loadbalancers/#{load_balancer_id}/sessionpersistence", :method => 'GET' ) end |
#get_usage(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/rackspace/requests/load_balancers/get_usage.rb', line 5 def get_usage( = {}) if .has_key? :start_time and .has_key? :end_time query = "?startTime=#{[:start_time]}&endTime=#{[:end_time]}" else query = '' end request( :expects => 200, :path => "loadbalancers/usage#{query}", :method => 'GET' ) end |
#list_access_rules(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/list_access_rules.rb', line 5 def list_access_rules(load_balancer_id) request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/accesslist" ) end |
#list_algorithms ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/list_algorithms.rb', line 5 def list_algorithms request( :expects => 200, :method => 'GET', :path => 'loadbalancers/algorithms' ) end |
#list_load_balancers ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/list_load_balancers.rb', line 5 def list_load_balancers request( :expects => 200, :method => 'GET', :path => 'loadbalancers.json' ) end |
#list_nodes(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/list_nodes.rb', line 5 def list_nodes(load_balancer_id) request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/nodes.json" ) end |
#list_protocols ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/list_protocols.rb', line 5 def list_protocols request( :expects => 200, :method => 'GET', :path => 'loadbalancers/protocols' ) end |
#list_virtual_ips(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/list_virtual_ips.rb', line 5 def list_virtual_ips(load_balancer_id) request( :expects => 200, :method => 'GET', :path => "loadbalancers/#{load_balancer_id}/virtualips.json" ) end |
#remove_connection_throttling(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/remove_connection_throttling.rb', line 5 def remove_connection_throttling(load_balancer_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/connectionthrottle", :method => 'DELETE' ) end |
#remove_monitor(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/remove_monitor.rb', line 5 def remove_monitor(load_balancer_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/healthmonitor", :method => 'DELETE' ) end |
#remove_session_persistence(load_balancer_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/load_balancers/remove_session_persistence.rb', line 5 def remove_session_persistence(load_balancer_id) request( :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/sessionpersistence", :method => 'DELETE' ) end |
#request(params) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/fog/rackspace/load_balancers.rb', line 114 def request(params) #TODO - Unify code with other rackspace services begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}" })) rescue Excon::Errors::NotFound => error raise NotFound.slurp error rescue Excon::Errors::BadRequest => error raise BadRequest.slurp error rescue Excon::Errors::InternalServerError => error raise InternalServerError.slurp error rescue Excon::Errors::HTTPStatusError => error raise ServiceError.slurp error end unless response.body.empty? response.body = MultiJson.decode(response.body) end response end |
#set_connection_logging(load_balancer_id, value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/rackspace/requests/load_balancers/set_connection_logging.rb', line 5 def set_connection_logging(load_balancer_id, value) data = { 'connectionLogging' => { 'enabled' => value.to_s } } request( :body => MultiJson.encode(data), :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/connectionlogging", :method => 'PUT' ) end |
#set_connection_throttling(load_balancer_id, max_connections, min_connections, max_connection_rate, rate_interval) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fog/rackspace/requests/load_balancers/set_connection_throttling.rb', line 5 def set_connection_throttling(load_balancer_id, max_connections, min_connections, max_connection_rate, rate_interval) data = { 'maxConnections' => max_connections, 'minConnections' => min_connections, 'maxConnectionRate' => max_connection_rate, 'rateInterval' => rate_interval } request( :body => MultiJson.encode(data), :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/connectionthrottle", :method => 'PUT' ) end |
#set_monitor(load_balancer_id, type, delay, timeout, attempsBeforeDeactivation, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/rackspace/requests/load_balancers/set_monitor.rb', line 5 def set_monitor(load_balancer_id, type, delay, timeout, attempsBeforeDeactivation, = {}) data = { 'type' => type, 'delay' => delay, 'timeout' => timeout, 'attemptsBeforeDeactivation' => attempsBeforeDeactivation } if .has_key? :path data['path'] = [:path] end if .has_key? :body_regex data['bodyRegex'] = [:body_regex] end if .has_key? :status_regex data['statusRegex'] = [:status_regex] end request( :body => MultiJson.encode(data), :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/healthmonitor", :method => 'PUT' ) end |
#set_session_persistence(load_balancer_id, persistence_type) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/rackspace/requests/load_balancers/set_session_persistence.rb', line 5 def set_session_persistence(load_balancer_id, persistence_type) data = { 'sessionPersistence' => { 'persistenceType' => persistence_type } } request( :body => MultiJson.encode(data), :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/sessionpersistence", :method => 'PUT' ) end |
#update_load_balancer(load_balancer_id, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/rackspace/requests/load_balancers/update_load_balancer.rb', line 5 def update_load_balancer(load_balancer_id, = {}) data = { 'loadBalancer' => { 'name' => [:name], 'port' => [:port], 'protocol' => [:protocol], 'algorithm' => [:algorithm] } } request( :body => MultiJson.encode(data), :expects => 202, :method => 'PUT', :path => "loadbalancers/#{load_balancer_id}.json" ) end |
#update_node(load_balancer_id, node_id, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/load_balancers/update_node.rb', line 5 def update_node(load_balancer_id, node_id, = {}) data = { 'node' => {} } if .has_key? :weight data['node']['weight'] = [:weight] end if .has_key? :condition data['node']['condition'] = [:condition] end #TODO - Do anything if no valid options are passed in? request( :body => MultiJson.encode(data), :expects => [200, 202], :method => 'PUT', :path => "loadbalancers/#{load_balancer_id}/nodes/#{node_id}.json" ) end |