Method: CloudLB::Balancer#create_nodes

Defined in:
lib/cloudlb/balancer.rb

#create_nodes(nodes) ⇒ Object

Add multiple nodes to a load balancer. Returns the new Node objects.

Use this if you’re adding multiple nodes to a load balancer, as adding subsequent nodes while the first one is queued may fail.

nodes is an array of options given to #create_node.



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cloudlb/balancer.rb', line 94

def create_nodes(nodes)
  nodes.each do |node|
    (raise CloudLB::Exception::MissingArgument, "Must provide :address for all nodes") if node[:address].to_s.empty?
    (raise CloudLB::Exception::MissingArgument, "Must provide :port for all nodes") if node[:port].to_s.empty?
    node[:condition] ||= "ENABLED"
  end
  body = {:nodes => nodes}.to_json
  response = @connection.lbreq("POST", @lbmgmthost, "#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@id.to_s)}/nodes",@lbmgmtport,@lbmgmtscheme,{},body)
  CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  JSON.parse(response.body)['nodes'].map { |node| get_node(node["id"]) }
end