Created
July 26, 2012 18:46
-
-
Save pbyrne/3183751 to your computer and use it in GitHub Desktop.
first draft, untested, and doing terrible things with negative indexes
This file contains 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
# desired_cluster is a hash of roles and their counts (e.g., {web: 2, redis: 1} | |
def equalize_servers fog, app, environment, desired_cluster | |
current_cluster = filtered_servers(fog, app, environment).group_by { |server| server.tags["role"] } | |
to_build = {} | |
to_destroy = [] | |
current_cluster.each do |role, servers| | |
if desired_cluster.has_key? role | |
# we want some, but do we have the right amount? | |
difference = desired_cluster[role] - servers.count | |
if difference > 0 | |
to_build[role] = difference | |
elsif difference < 0 | |
to_destroy += servers[difference..-1] | |
end | |
else | |
# we don't want any | |
to_destroy += servers | |
end | |
end | |
fork { build_servers fog, app, environment, to_build } | |
fork { kill fog, app, environment, to_destroy } | |
Process.waitall | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment