Module: Wombat::Aws
Instance Method Summary
collapse
Methods included from Common
#audio?, #azure_provider_tag, #banner, #bootstrap_aws, #build_nodes, #calculate_templates, #conf, #connect_azure, #create_infranodes_json, #create_resource_group, #deployment_state, #duration, #follow_azure_deployment, #info, #infranodes, #is_mac?, #is_valid_json?, #linux, #list_outstanding_deployment_operations, #lock, #logs, #parse_log, #update_lock, #update_template, #warn, #wombat, #workstations
Instance Method Details
#find_latest_amis ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/wombat/aws.rb', line 12
def find_latest_amis
client = ::Aws::EC2::Client.new(:region => wombat["aws"]["region"])
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) ⇒ Object
42
43
44
45
46
|
# File 'lib/wombat/aws.rb', line 42
def prefer(images, &block)
matching, non_matching = images.partition(&block)
matching + non_matching
end
|
#sort_images(images) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/wombat/aws.rb', line 48
def sort_images(images)
images = images.sort_by(&:creation_date).reverse
images = prefer(images) { |image| image.architecture == :x86_64 }
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
images = prefer(images) { |image| image.root_device_type == "ebs" }
images = prefer(images) { |image| image.virtualization_type == "hvm" }
images.first
end
|