extras/clean-stock-amis in cloud-mu-2.0.4 vs extras/clean-stock-amis in cloud-mu-2.1.0beta
- old
+ new
@@ -16,20 +16,26 @@
require 'optimist'
require 'json'
require File.realpath(File.expand_path(File.dirname(__FILE__)+"/../bin/mu-load-config.rb"))
require 'mu'
+credentials = if ARGV[0] and !ARGV[0].empty?
+ ARGV[0]
+else
+ nil
+end
+
filters = [
{
name: "owner-id",
- values: [MU.account_number]
+ values: [MU::Cloud::AWS.credToAcct(credentials)]
}
]
MU::Cloud::AWS.listRegions.each { | r|
- images = MU::Cloud::AWS.ec2(r).describe_images(
+ images = MU::Cloud::AWS.ec2(region: r, credentials: credentials).describe_images(
filters: filters + [{ "name" => "state", "values" => ["available"]}]
).images
images.each { |ami|
if (DateTime.now.to_time - DateTime.parse(ami.creation_date).to_time) > 15552000 and ami.name.match(/^MU-(PROD|DEV)/)
snaps = []
@@ -37,12 +43,12 @@
if !dev.ebs.nil?
snaps << dev.ebs.snapshot_id
end
}
MU.log "Deregistering #{ami.name} (#{ami.creation_date})", MU::WARN, details: snaps
- MU::Cloud::AWS.ec2(r).deregister_image(image_id: ami.image_id)
+ MU::Cloud::AWS.ec2(region: r, credentials: credentials).deregister_image(image_id: ami.image_id)
snaps.each { |snap_id|
- MU::Cloud::AWS.ec2(r).delete_snapshot(snapshot_id: snap_id)
+ MU::Cloud::AWS.ec2(region: r, credentials: credentials).delete_snapshot(snapshot_id: snap_id)
}
end
}
}