Class: Rackspace::Scaling::LoadBalancerOperation
- Inherits:
-
Object
- Object
- Rackspace::Scaling::LoadBalancerOperation
- Defined in:
- lib/rackspace-scaling/load_balancer_operation.rb
Instance Method Summary collapse
- #add_node(options = {}) ⇒ Object
-
#initialize(auth, region = 'DFW') ⇒ LoadBalancerOperation
constructor
A new instance of LoadBalancerOperation.
- #list ⇒ Object
- #nodes(load_balancer_id) ⇒ Object
- #remove_node(options = {}) ⇒ Object
Constructor Details
#initialize(auth, region = 'DFW') ⇒ LoadBalancerOperation
Returns a new instance of LoadBalancerOperation.
4 5 6 7 |
# File 'lib/rackspace-scaling/load_balancer_operation.rb', line 4 def initialize(auth, region = 'DFW') @auth = auth @endpoint = @auth.endpoints['cloudLoadBalancers']['endpoints'][region]['publicURL']+"/loadbalancers" end |
Instance Method Details
#add_node(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rackspace-scaling/load_balancer_operation.rb', line 24 def add_node( = {}) load_balancer_id = [:load_balancer_id] body = { :nodes => [ { :address => [:node_ip], :port => ([:port] || 80), :condition => ([:condition] || 'ENABLED'), :type => ([:type] || 'PRIMARY') } ] } path = "#{@endpoint}/#{load_balancer_id}/nodes" resp = Typhoeus::Request.post(path, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json', 'Content-Type' => 'application/json'}, :body => body.to_json) JSON.parse(resp.body)['nodes'] end |
#list ⇒ Object
9 10 11 12 13 14 |
# File 'lib/rackspace-scaling/load_balancer_operation.rb', line 9 def list @list ||= begin resp = Typhoeus::Request.get(@endpoint, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'}) parsed_response = JSON.parse(resp.body)['loadBalancers'] end end |
#nodes(load_balancer_id) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rackspace-scaling/load_balancer_operation.rb', line 16 def nodes(load_balancer_id) path = "#{@endpoint}/#{load_balancer_id}/nodes" @images ||= begin resp = Typhoeus::Request.get(path, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'}) parsed_response = JSON.parse(resp.body)['nodes'] end end |
#remove_node(options = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rackspace-scaling/load_balancer_operation.rb', line 41 def remove_node( = {}) load_balancer_id = [:load_balancer_id] node_id = [:node_id] path = "#{@endpoint}/#{load_balancer_id}/nodes/#{node_id}" resp = Typhoeus::Request.delete(path, :headers => { 'X-Auth-Token' => @auth.token, 'Accept' => 'application/json'}) resp.success? end |