Class: Rackspace::Scaling::LoadBalancerOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-scaling/load_balancer_operation.rb

Instance Method Summary collapse

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(options = {})
  load_balancer_id = options[:load_balancer_id]
  body = {
    :nodes => [
      {
        :address => options[:node_ip],
        :port => (options[:port] || 80),
        :condition => (options[:condition] || 'ENABLED'),
        :type => (options[: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

#listObject



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(options = {})
  load_balancer_id = options[:load_balancer_id]
  node_id = options[: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