Sha256: 2c2069bda9cd50786e5a9e304b5ccbbaedcf89916318396f0436065a8061d923

Contents?: true

Size: 1.54 KB

Versions: 17

Compression:

Stored size: 1.54 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'

filters = [
  {
    name: "owner-id",
    values: [MU.account_number]
  }
]


MU::Cloud::AWS.listRegions.each { | r|
  images = MU::Cloud::AWS.ec2(r).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(r).deregister_image(image_id: ami.image_id)
			snaps.each { |snap_id|
				MU::Cloud::AWS.ec2(r).delete_snapshot(snapshot_id: snap_id)
			}
		end
  }
}

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
cloud-mu-2.0.4 extras/clean-stock-amis
cloud-mu-2.0.3 extras/clean-stock-amis
cloud-mu-2.0.2 extras/clean-stock-amis
cloud-mu-2.0.1 extras/clean-stock-amis
cloud-mu-2.0.0.pre.beta3 extras/clean-stock-amis
cloud-mu-2.0.0.pre.beta2 extras/clean-stock-amis
cloud-mu-2.0.0.pre.beta1 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha9 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha8 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha7 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha6 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha5 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha4 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha3 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha2 extras/clean-stock-amis
cloud-mu-2.0.0.pre.alpha extras/clean-stock-amis
cloud-mu-1.9.0.pre.beta extras/clean-stock-amis