Created
February 10, 2012 19:54
-
-
Save mitchellh/1792217 to your computer and use it in GitHub Desktop.
Prune old clients.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'set' | |
def knife_list(type) | |
Set.new(`knife #{type} list`.split("\n").map { |a| a.strip.chomp }) | |
end | |
nodes = knife_list(:node) | |
clients = knife_list(:client) | |
# We want to remove the clients that aren't nodes. | |
bad_clients = clients - nodes | |
bad_clients = bad_clients.to_a.sort | |
puts "Deleting #{bad_clients.length} stale clients." | |
bad_clients.each_index do |index| | |
bad_client = bad_clients[index] | |
puts "Deleting client #{index + 1}/#{bad_clients.length}: #{bad_client}" | |
`knife client delete #{bad_client} -y` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment