Skip to content

Commit

Permalink
Add option to delete private AMIs
Browse files Browse the repository at this point in the history
  • Loading branch information
James Tan committed Oct 12, 2012
1 parent 22a7e6d commit 20cbbdf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ec2-janitor/ec2-janitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ def instances
end
end

desc "images", "Displays images in all regions"
desc "images", "Displays images in all regions. Optionally deletes all private AMIs."
method_option :'prune', :type => :boolean, :desc => "Delete all private AMIs."
def images
results = []
deleted = []
threaded_regions do |region|
region.images.with_owner('self').each do |image|
results << [ region.name, image.name, image.id,
(image.public? ? 'Public' : 'Private') ]
if options.prune? && !image.public?
deleted << image.id
image.delete
end
end
end
if results.empty?
Expand All @@ -77,6 +83,9 @@ def images
puts table(['Region', 'Name', 'AMI ID', 'Perms'],
*results.sort_by{ |k| [k[0], k[1]] })
end
unless deleted.empty?
puts "Deleted private AMIs: #{deleted.join(', ')}"
end
end

desc "textile VERSION ARCH", "Output matching openSUSE AMI IDs from all regions in Textile format. Useful for SUSE Gallery descriptions.\nVERSION is the openSUSE release version (eg. 12.2).\nARCH is the AMI architecture (i386, x86_64)."
Expand Down

0 comments on commit 20cbbdf

Please sign in to comment.