MovableInkAWS 2.11.3 → 2.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/movable_ink/aws/ec2.rb +26 -5
- data/lib/movable_ink/version.rb +1 -1
- data/spec/ec2_spec.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b512cd51997315bd6fb546d10f60f6ac434a48cd5bb0f7cb6a3e530b5215fda
|
|
4
|
+
data.tar.gz: 2551f3560ddf52873bfa7b1a80ce330844effde2765ac0bee8fad9ab87eaa651
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a7b4ed079987785359a3f7b29af63a60fe8dfb999d4871d6166d1483505030f687a04c13999315759c84d3e8b6d4d4943216da0c6479e13bec3b233417fc6cc5
|
|
7
|
+
data.tar.gz: e9b53f15118613fe8fd48a0502d0eed1b7d2af79829678bc99ab86543dff06f8541a64fe573b01a9424afb666951654fbf251cc290fed6a6cd1f77e92d85aa6d
|
data/Gemfile.lock
CHANGED
data/lib/movable_ink/aws/ec2.rb
CHANGED
|
@@ -244,6 +244,23 @@ module MovableInk
|
|
|
244
244
|
redis_instances.flatten.shuffle
|
|
245
245
|
end
|
|
246
246
|
|
|
247
|
+
def describe_ip(public_ip:)
|
|
248
|
+
expected_errors = [
|
|
249
|
+
MovableInk::AWS::Errors::ExpectedError.new(Aws::EC2::Errors::InvalidAddressNotFound, [/Address \'#{public_ip}\' not found./])
|
|
250
|
+
]
|
|
251
|
+
begin
|
|
252
|
+
run_with_backoff(expected_errors: expected_errors) do
|
|
253
|
+
response = ec2_with_retries.describe_addresses({
|
|
254
|
+
public_ips: [public_ip]
|
|
255
|
+
})
|
|
256
|
+
raise MovableInk::AWS::Errors::ServiceError if response.length > 1
|
|
257
|
+
return response[0]
|
|
258
|
+
end
|
|
259
|
+
rescue MovableInk::AWS::Errors::ServiceError, Aws::EC2::Errors::InvalidAddressNotFound
|
|
260
|
+
return nil
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
247
264
|
def elastic_ips
|
|
248
265
|
@all_elastic_ips ||= run_with_backoff do
|
|
249
266
|
ec2.describe_addresses.addresses
|
|
@@ -258,20 +275,24 @@ module MovableInk
|
|
|
258
275
|
unassigned_elastic_ips.select { |address| address.tags.detect { |t| t.key == 'mi:roles' && t.value == role } }
|
|
259
276
|
end
|
|
260
277
|
|
|
261
|
-
def assign_ip_address_with_retries(role:)
|
|
278
|
+
def assign_ip_address_with_retries(role:, allow_reassociation: false)
|
|
279
|
+
response = nil
|
|
262
280
|
run_with_backoff do
|
|
263
|
-
ec2_with_retries.associate_address({
|
|
281
|
+
response = ec2_with_retries.associate_address({
|
|
264
282
|
instance_id: instance_id,
|
|
265
|
-
allocation_id: available_elastic_ips(role: role).sample.allocation_id
|
|
283
|
+
allocation_id: available_elastic_ips(role: role).sample.allocation_id,
|
|
284
|
+
allow_reassociation: allow_reassociation
|
|
266
285
|
})
|
|
267
286
|
end
|
|
287
|
+
response
|
|
268
288
|
end
|
|
269
289
|
|
|
270
|
-
def assign_ip_address(role:)
|
|
290
|
+
def assign_ip_address(role:, allow_reassociation: false)
|
|
271
291
|
run_with_backoff do
|
|
272
292
|
ec2.associate_address({
|
|
273
293
|
instance_id: instance_id,
|
|
274
|
-
allocation_id: available_elastic_ips(role: role).sample.allocation_id
|
|
294
|
+
allocation_id: available_elastic_ips(role: role).sample.allocation_id,
|
|
295
|
+
allow_reassociation: allow_reassociation
|
|
275
296
|
})
|
|
276
297
|
end
|
|
277
298
|
end
|
data/lib/movable_ink/version.rb
CHANGED
data/spec/ec2_spec.rb
CHANGED
|
@@ -692,6 +692,40 @@ describe MovableInk::AWS::EC2 do
|
|
|
692
692
|
|
|
693
693
|
expect(aws.assign_ip_address(role: 'some_role').association_id).to eq('eipassoc-3')
|
|
694
694
|
end
|
|
695
|
+
|
|
696
|
+
it "should assign an elastic IP with allow_reassociation flag" do
|
|
697
|
+
ec2.stub_responses(:describe_addresses, elastic_ip_data)
|
|
698
|
+
ec2.stub_responses(:associate_address, associate_address_data)
|
|
699
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
|
700
|
+
allow(aws).to receive(:instance_id).and_return('i-12345')
|
|
701
|
+
allow(aws).to receive(:ec2).and_return(ec2)
|
|
702
|
+
|
|
703
|
+
expect(aws.assign_ip_address(role: 'some_role', allow_reassociation: true).association_id).to eq('eipassoc-3')
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
it "should assign an elastic IP with retries and return response" do
|
|
707
|
+
ec2.stub_responses(:describe_addresses, elastic_ip_data)
|
|
708
|
+
ec2.stub_responses(:associate_address, associate_address_data)
|
|
709
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
|
710
|
+
allow(aws).to receive(:instance_id).and_return('i-12345')
|
|
711
|
+
allow(aws).to receive(:ec2).and_return(ec2)
|
|
712
|
+
allow(aws).to receive(:ec2_with_retries).and_return(ec2)
|
|
713
|
+
|
|
714
|
+
response = aws.assign_ip_address_with_retries(role: 'some_role')
|
|
715
|
+
expect(response.association_id).to eq('eipassoc-3')
|
|
716
|
+
end
|
|
717
|
+
|
|
718
|
+
it "should assign an elastic IP with retries and allow_reassociation flag" do
|
|
719
|
+
ec2.stub_responses(:describe_addresses, elastic_ip_data)
|
|
720
|
+
ec2.stub_responses(:associate_address, associate_address_data)
|
|
721
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
|
722
|
+
allow(aws).to receive(:instance_id).and_return('i-12345')
|
|
723
|
+
allow(aws).to receive(:ec2).and_return(ec2)
|
|
724
|
+
allow(aws).to receive(:ec2_with_retries).and_return(ec2)
|
|
725
|
+
|
|
726
|
+
response = aws.assign_ip_address_with_retries(role: 'some_role', allow_reassociation: true)
|
|
727
|
+
expect(response.association_id).to eq('eipassoc-3')
|
|
728
|
+
end
|
|
695
729
|
end
|
|
696
730
|
|
|
697
731
|
context 'elastic ips' do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: MovableInkAWS
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.11.
|
|
4
|
+
version: 2.11.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- MI SRE
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aws-sdk-core
|