Created
May 9, 2013 02:07
-
-
Save mrowe/5545068 to your computer and use it in GitHub Desktop.
The genesis of the zombie apocalypse.
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
def ec2 | |
Fog::Compute.new(:provider => 'AWS', | |
:aws_secret_access_key => ENV['EC2_SECRET_KEY'], | |
:aws_access_key_id => ENV['EC2_ACCESS_KEY']) | |
end | |
def tenured? (instance) | |
instance.created_at && (instance.created_at < Chronic.parse('50 minutes ago')) | |
end | |
def alive? (instance) | |
instance.state == 'running' or instance.state == 'stopped' | |
end | |
zombies = ec2.servers.select { |i| i.tags.empty? && tenured?(i) && alive?(i) } | |
Parallel.each(zombies, :in_threads => 15) do |zombie| | |
begin | |
puts "Terminating zombie node #{zombie.id}" | |
ec2.servers.get(zombie.id).destroy | |
end | |
end |
Like that would ever happen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
on line 15 what happens if the tag list fails to load?