Sha256: 28c6dc7b20a70482c6f3e1b7663e21e9c5468c64d2c5f18f7a3eb7735ec2b432

Contents?: true

Size: 1.74 KB

Versions: 11

Compression:

Stored size: 1.74 KB

Contents

#!/usr/local/ruby-current/bin/ruby
# Copyright:: Copyright (c) 2014 eGlobalTech, Inc., all rights reserved
#
# Licensed under the BSD-3 license (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the root of the project or at
#
#     http://egt-labs.com/mu/LICENSE.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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::Cloud::AWS.credToAcct(credentials)]
  }
]


MU::Cloud::AWS.listRegions.each { | r|
  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 = []
			ami.block_device_mappings.each { |dev|
				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(region: r, credentials: credentials).deregister_image(image_id: ami.image_id)
 		  snaps.each { |snap_id|
			  MU::Cloud::AWS.ec2(region: r, credentials: credentials).delete_snapshot(snapshot_id: snap_id)
			}
		end
  }
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cloud-mu-3.1.5 extras/clean-stock-amis
cloud-mu-3.1.4 extras/clean-stock-amis
cloud-mu-3.1.3 extras/clean-stock-amis
cloud-mu-3.1.2 extras/clean-stock-amis
cloud-mu-3.1.2beta2 extras/clean-stock-amis
cloud-mu-3.1.1 extras/clean-stock-amis
cloud-mu-3.1.0 extras/clean-stock-amis
cloud-mu-3.0.2 extras/clean-stock-amis
cloud-mu-3.0.1 extras/clean-stock-amis
cloud-mu-3.0.0 extras/clean-stock-amis
cloud-mu-3.0.0beta extras/clean-stock-amis