Permalink
Browse files

Support for bulk deletion of nodes from a load balancer.

  • Loading branch information...
1 parent 24a354d commit 6e4d7ed23fd19fc18f5cce6ed80fdeae13d233e8 @oggy oggy committed Jul 31, 2012
Showing with 16 additions and 7 deletions.
  1. +16 −7 lib/chef/knife/rackspace_load_balancer_delete_node.rb
@@ -100,16 +100,25 @@ def run
balancer = lb_connection.get_load_balancer(lb[:id])
lb_nodes = balancer.list_nodes
- lb_nodes.each do |lb_node_hash|
- if node_ips.include? lb_node_hash[:address].to_s
- lb_node = balancer.get_node(lb_node_hash[:id])
- ui.output("Removing node #{lb_node.address}")
- if lb_node.destroy!
- ui.output(ui.color("Success", :green))
- end
+
+ nodes_to_remove = []
+ already_removed = []
+ nodes.each do |node|
+ if (lb_node = lb_nodes.find{|lb_node| lb_node[:address] == node[:address]})
+ nodes_to_remove << lb_node
+ else
+ already_removed << node
end
end
+ if !already_removed.empty?
+ removed_names = already_removed.map { |node| node[:address] }
+ ui.warn "Already out of load balancer - skipping: #{removed_names.join(', ')}"
+ end
+ unless nodes_to_remove.empty?
+ ui.output("Removing #{nodes_to_remove.size} node(s) from #{lb[:name]}")
+ balancer.destroy_nodes(nodes_to_remove)
+ end
rescue CloudLB::Exception::Other => e
ui.error("Failed on #{lb[:name]}: CloudLB::Exception [#{e.class.name}] - #{e.message}")
end

0 comments on commit 6e4d7ed

Please sign in to comment.