MovableInkAWS 2.11.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9318b421bc139e87f2e723fdbba3360d952273bd0c01f8667d4cb8788f0b8ae1
4
- data.tar.gz: b2b481971587694e25571e53c7a514b2f2ac68e3176ad641b821eef2395e5d9d
3
+ metadata.gz: 6b512cd51997315bd6fb546d10f60f6ac434a48cd5bb0f7cb6a3e530b5215fda
4
+ data.tar.gz: 2551f3560ddf52873bfa7b1a80ce330844effde2765ac0bee8fad9ab87eaa651
5
5
  SHA512:
6
- metadata.gz: f103f6f8518ed20318e4fb08faf4f31cab1f94eae8e60c74b545548257d80f664337c5091f5323a1d9b41457f5821b17087693a5fefec7d9f4f46a0c0bf59dc1
7
- data.tar.gz: ce2104a04e8d1bae248a4e5cfbdd72fda580d4f95b5bc349f9b4c33d6978efb6915a72ff8881d451c2f737e569758b340124d8a414accb69334eb478a6f84fb5
6
+ metadata.gz: a7b4ed079987785359a3f7b29af63a60fe8dfb999d4871d6166d1483505030f687a04c13999315759c84d3e8b6d4d4943216da0c6479e13bec3b233417fc6cc5
7
+ data.tar.gz: e9b53f15118613fe8fd48a0502d0eed1b7d2af79829678bc99ab86543dff06f8541a64fe573b01a9424afb666951654fbf251cc290fed6a6cd1f77e92d85aa6d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- MovableInkAWS (2.11.2)
4
+ MovableInkAWS (2.11.4)
5
5
  aws-sdk-athena (~> 1)
6
6
  aws-sdk-autoscaling (~> 1)
7
7
  aws-sdk-cloudwatch (~> 1)
@@ -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,11 +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(role:)
278
+ def assign_ip_address_with_retries(role:, allow_reassociation: false)
279
+ response = nil
280
+ run_with_backoff do
281
+ response = ec2_with_retries.associate_address({
282
+ instance_id: instance_id,
283
+ allocation_id: available_elastic_ips(role: role).sample.allocation_id,
284
+ allow_reassociation: allow_reassociation
285
+ })
286
+ end
287
+ response
288
+ end
289
+
290
+ def assign_ip_address(role:, allow_reassociation: false)
262
291
  run_with_backoff do
263
292
  ec2.associate_address({
264
293
  instance_id: instance_id,
265
- 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
266
296
  })
267
297
  end
268
298
  end
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '2.11.2'
3
+ VERSION = '2.11.4'
4
4
  end
5
5
  end
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.2
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-07-28 00:00:00.000000000 Z
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