module Wombat::Aws
Public Instance Methods
find_latest_amis()
click to toggle source
# File lib/wombat/aws.rb, line 12 def find_latest_amis client = ::Aws::EC2::Client.new(:region => wombat["aws"]["region"]) # static list of images desc_hash = { "ubuntu-16.04" => ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*", "099720109477"], "ubuntu-14.04" => ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*", "099720109477"], "centos-7" => ["CentOS Linux 7 x86_64 HVM EBS*", "679593333241"], "windows-2012r2" => ["Windows_Server-2012-R2_RTM-English-64Bit-Base-*", "801119661308"] } desc_hash.each do |k, v| resp = client.describe_images({ dry_run: false, filters: [ { name: "name", values: [v[0]], }, { name: "owner-id", values: [v[1]], }, ], }) images = sort_images(resp.images) puts "#{k}: #{images[:image_id]}" end end
prefer(images, &block)
click to toggle source
# File lib/wombat/aws.rb, line 42 def prefer(images, &block) # Put the matching ones *before* the non-matching ones. matching, non_matching = images.partition(&block) matching + non_matching end
sort_images(images)
click to toggle source
# File lib/wombat/aws.rb, line 48 def sort_images(images) # P5: We prefer more recent images over older ones images = images.sort_by(&:creation_date).reverse # P4: We prefer x86_64 over i386 (if available) images = prefer(images) { |image| image.architecture == :x86_64 } # P3: We prefer gp2 (SSD) (if available) images = prefer(images) do |image| image.block_device_mappings.any? do |b| b.device_name == image.root_device_name && b.ebs && b.ebs.volume_type == "gp2" end end # P2: We prefer ebs over instance_store (if available) images = prefer(images) { |image| image.root_device_type == "ebs" } # P1: We prefer hvm (the modern standard) images = prefer(images) { |image| image.virtualization_type == "hvm" } # Grab the image from the top of the stack images.first end