awsutils 2.1.7 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2262e6b9cef6b2bef93be826382e6fa65adc757b
4
- data.tar.gz: e1b9b6749c152bb10a1236058eb628fbcc37e371
2
+ SHA256:
3
+ metadata.gz: f7be6a7b15199b892d2e54109ff3da6a684586b12abf22a9103764cdcee21c19
4
+ data.tar.gz: 0cc296c1b47c529ee5925f42e49d676cfe12c0527880b45bfe9edbb03d9c6a0b
5
5
  SHA512:
6
- metadata.gz: ae21d554f550a4e8a6bb71b6a54898b5035317532308dccbcf3aea0fee0d0e67600617f3898746462a9343b552311b4c988993f1d52aaadd0d6278d5e726be21
7
- data.tar.gz: 4999def64d2252d34bf876168a788450cf92483f376d9383c11310757378dc01d23da4c25cc8c657fddb09d4aacbbb65e24c44cc3e55c569ffc889f91bf12f04
6
+ metadata.gz: 972a9b9365e220317071483ccc34f8b740df251be2f14d4112beb5cee555ffaceded4a66f39391be86d724e498e73da7d737e96e755aa5d7ea901d9d76566239
7
+ data.tar.gz: 15b3ed991715a078fe8079a65c15c382374cd0bd2779750ffda433e60b84620f7bbb0911c48b472a3724fbd4302e7a9cc8cca7f543047f0d98deacac05db3686
@@ -7,15 +7,40 @@ module AwsUtils
7
7
  class Ec2LatestImage
8
8
  def releases
9
9
  @releases ||= begin
10
- resp = JSON.parse(
11
- Net::HTTP.get(
12
- URI("http://cloud-images.ubuntu.com/locator/ec2/releasesTable?_=#{(Time.now.to_f*1000).to_i}")
13
- ).sub(/\],\n\]/, "]\n]")
14
- )
15
- parse_releases_array(resp['aaData']).select do |rel|
16
- rel[:region] == 'us-east-1' &&
10
+ parsed_releases =
11
+ if opts[:ownedbyme]
12
+ fail 'AWS_OWNER_ID not defined' unless ENV['AWS_OWNER_ID']
13
+
14
+ require 'aws-sdk'
15
+
16
+ ubuntu_images =
17
+ connection.describe_images(owners: [ENV['AWS_OWNER_ID']]).images.select do |image|
18
+ image.name =~ %r{^ubuntu\/}
19
+ end
20
+
21
+ ubuntu_images.map do |image|
22
+ {
23
+ ami: image.image_id,
24
+ distro_version: image.name.split('/')[3].split('-')[2],
25
+ release: image.name.split('/')[3].split('-')[5..-1].join('-'),
26
+ type: image.name.split('/')[2] + ':' + image.root_device_type,
27
+ arch: image.architecture,
28
+ region: opts[:region] # overriding this because images API doesn't list a region
29
+ }
30
+ end
31
+ else
32
+ resp = JSON.parse(
33
+ Net::HTTP.get(
34
+ URI("http://cloud-images.ubuntu.com/locator/ec2/releasesTable?_=#{(Time.now.to_f*1000).to_i}")
35
+ ).sub(/\],\n\]/, "]\n]")
36
+ )
37
+ parse_releases_array(resp['aaData'])
38
+ end
39
+
40
+ parsed_releases.select do |rel|
41
+ rel[:region] == opts[:region] &&
17
42
  rel[:distro_version] == "#{opts[:release]}" &&
18
- rel[:arch] == 'amd64'
43
+ %w(amd64 x86_64).include?(rel[:arch])
19
44
  end
20
45
  end
21
46
  end
@@ -28,18 +53,18 @@ module AwsUtils
28
53
 
29
54
  def print_releases
30
55
  # Print a header
31
- printf("%-13s %-10s %-9s %-20s\n", 'ID', 'Version', 'Release', 'Type')
56
+ printf("%-13s %-10s %-20s %-9s\n", 'ID', 'Version', 'Type', 'Release')
32
57
 
33
- puts('-' * 53)
58
+ puts('-' * 72)
34
59
 
35
60
  # Print the releases
36
61
  releases.each do |rel|
37
62
  printf(
38
- "%-13s %-10s %-9s %-20s\n",
63
+ "%-13s %-10s %-20s %-9s\n",
39
64
  rel[:ami],
40
65
  rel[:distro_version],
41
- rel[:release],
42
- rel[:type]
66
+ rel[:type],
67
+ rel[:release]
43
68
  )
44
69
  end
45
70
  end
@@ -83,7 +108,11 @@ module AwsUtils
83
108
  end
84
109
 
85
110
  def opts
86
- @opts ||= Trollop.options { opt :release, 'Ubuntu release', short: 'r', default: '14.04 LTS' }
111
+ @opts ||= Trollop.options do
112
+ opt :release, 'Ubuntu release', short: 'r', default: '16.04 LTS'
113
+ opt :ownedbyme, 'Images owned by $AWS_OWNER_ID', short: 'o', default: false
114
+ opt :region, 'Image region', short: 'R', default: 'us-east-1'
115
+ end
87
116
  end
88
117
  end
89
118
  end
@@ -1,3 +1,3 @@
1
1
  module AwsUtils
2
- VERSION = '2.1.7'
2
+ VERSION = '2.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Herot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-14 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  version: '0'
247
247
  requirements: []
248
248
  rubyforge_project:
249
- rubygems_version: 2.5.1
249
+ rubygems_version: 2.7.7
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: A set of tools for interacting with AWS (summary)