infopark-aws_utils 0.8.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/infopark/aws_utils.rb +3 -4
- data/lib/infopark/aws_utils/env.rb +29 -15
- data/lib/infopark/aws_utils/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3e7e356a45fa25bf635a55425020ea0b6a05af17731565e996ac52d444eec87
|
4
|
+
data.tar.gz: 138f8b6bf8e7266956756eca4511544d6386eb4e41de0c1887c3fc642910ba88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e162493fcf4a2de9eb0a68f1cf5781d40a586f6a12e6d49f379002d65dc4009a7aae5b2a5016489b71fe301e24ad587b0343b79e20846adc267f99976e766a5d
|
7
|
+
data.tar.gz: 8e74fb1c214710bc22201e59e3da2d71fc8a68dd0a6ed7e8afd8c3e1e0310736ed1a5d736ac622169899445fc3cd4e190294d67da6fa40b0a3023da3258996b8
|
data/lib/infopark/aws_utils.rb
CHANGED
@@ -6,7 +6,7 @@ module Infopark
|
|
6
6
|
AWS_AMI_OWNER = "137112412989"
|
7
7
|
|
8
8
|
class << self
|
9
|
-
def gather_all(client
|
9
|
+
def gather_all(client:, method:, response_key:, **options)
|
10
10
|
unless block_given?
|
11
11
|
@gather_cache ||= {}
|
12
12
|
cache_key = [client, method, options]
|
@@ -16,14 +16,13 @@ module Infopark
|
|
16
16
|
result = []
|
17
17
|
loop do
|
18
18
|
response = retry_on_throttle { client.send(method, **options) }
|
19
|
-
key = (response.members - [:next_token, :failures]).first
|
20
19
|
if response.members.include?(:failures) && !response.failures.empty?
|
21
20
|
raise "Failed gathering all #{method}: #{response.failures}"
|
22
21
|
end
|
23
22
|
if block_given?
|
24
|
-
response[
|
23
|
+
response[response_key].each {|entity| retry_on_throttle { yield entity } }
|
25
24
|
else
|
26
|
-
result += response[
|
25
|
+
result += response[response_key]
|
27
26
|
end
|
28
27
|
unless options[:next_token] = response.members.include?(:next_token) && response.next_token
|
29
28
|
break
|
@@ -110,18 +110,22 @@ class Env
|
|
110
110
|
else
|
111
111
|
raise "invalid root_device_type: #{root_device_type}"
|
112
112
|
end
|
113
|
-
available_images = AwsUtils.gather_all(
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
]
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
113
|
+
available_images = AwsUtils.gather_all(
|
114
|
+
client: ec2,
|
115
|
+
method: :describe_images,
|
116
|
+
response_key: :image_details,
|
117
|
+
owners: [AWS_AMI_OWNER],
|
118
|
+
filters: [
|
119
|
+
{name: "root-device-type", values: root_device_filter_value},
|
120
|
+
{name: "ena-support", values: ["true"]},
|
121
|
+
{name: "image-type", values: ["machine"]},
|
122
|
+
{name: "virtualization-type", values: ["hvm"]},
|
123
|
+
],
|
124
|
+
)
|
125
|
+
.reject {|image| image.name.include?(".rc-") }
|
126
|
+
.reject {|image| image.name.include?("-minimal-") }
|
127
|
+
.reject {|image| image.name.include?("-test") }
|
128
|
+
.reject {|image| image.name.include?("amzn-ami-vpc-nat-") }
|
125
129
|
(reject_image_name_patterns || []).each do |pattern|
|
126
130
|
available_images.reject! {|image| image.name =~ pattern }
|
127
131
|
end
|
@@ -129,12 +133,22 @@ class Env
|
|
129
133
|
end
|
130
134
|
|
131
135
|
def find_image_by_id(id)
|
132
|
-
AwsUtils.gather_all(
|
136
|
+
AwsUtils.gather_all(
|
137
|
+
client: ec2,
|
138
|
+
method: :describe_images,
|
139
|
+
response_key: :image_details,
|
140
|
+
image_ids: [id],
|
141
|
+
).first
|
133
142
|
end
|
134
143
|
|
135
144
|
def find_image_by_name(name)
|
136
|
-
AwsUtils.gather_all(
|
137
|
-
|
145
|
+
AwsUtils.gather_all(
|
146
|
+
client: ec2,
|
147
|
+
method: :describe_images,
|
148
|
+
response_key: :image_details,
|
149
|
+
owners: [DEV_ACCOUNT_ID],
|
150
|
+
filters: [{name: "name", values: [name]}],
|
151
|
+
).first
|
138
152
|
end
|
139
153
|
|
140
154
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark-aws_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tilo Prütz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-applicationautoscaling
|
@@ -200,8 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: '0'
|
202
202
|
requirements: []
|
203
|
-
|
204
|
-
rubygems_version: 2.6.13
|
203
|
+
rubygems_version: 3.0.3
|
205
204
|
signing_key:
|
206
205
|
specification_version: 4
|
207
206
|
summary: A utility lib to ease the use of the AWS SDK
|