lib/aws_ec2/cleaner/ami.rb in aws-ec2-1.3.1 vs lib/aws_ec2/cleaner/ami.rb in aws-ec2-1.3.2
- old
+ new
@@ -11,17 +11,22 @@
images = search_ami(query)
images = images.sort_by { |i| i.name }.reverse
delete_list = images[keep..-1] || []
puts "Deleting #{delete_list.size} images."
delete_list.each do |i|
- puts "Deleting image: #{i.image_id} #{i.name}"
- # delete(i.image_id)
+ delete(i)
end
end
private
- def delete(image_id)
- ec2.deregister_image(image_id: image_id)
+ def delete(image)
+ message = "Deleting image: #{image.image_id} #{image.name}"
+ if @options[:noop]
+ puts "NOOP: #{message}"
+ else
+ puts message
+ ec2.deregister_image(image_id: image.image_id)
+ end
rescue Aws::EC2::Errors::InvalidAMIIDUnavailable
# happens when image was just deleted but its still
# showing up as available when calling describe_images
puts "WARN: #{e.message}"
end