MovableInkAWS 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/movable_ink/aws/autoscaling.rb +43 -17
- data/lib/movable_ink/aws/ec2.rb +13 -15
- data/lib/movable_ink/version.rb +1 -1
- data/spec/autoscaling_spec.rb +59 -2
- data/spec/ec2_spec.rb +10 -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: f85b7a7cacd3d56c98e276a780730187b57d96beea4197e972858e093ff8b5b6
|
4
|
+
data.tar.gz: 0edf31bf91bbc3498f2336df122eaa70631b2e4d62c4b3dbc373365dea9b4209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5834796db467a574a0ce7f9cb88c6bb1f6995ebb54292d543881c23884de2733ff41a1729fa49e0d40056e89959e49e84e6347bb1ecaaea1ee718f54ad039f3e
|
7
|
+
data.tar.gz: 8ced1573db88a51ded5905888e01bac2a606dbffb1811e2dbd9ea5c230872711febc0867f5ba4380c8fd45d7c51dc9f87c4e5064c9d1c5c10532e38b89e6642c
|
data/Gemfile.lock
CHANGED
@@ -44,33 +44,59 @@ module MovableInk
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token:)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
def complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil)
|
48
|
+
raise ArgumentError.new('lifecycle_action_token or instance_id required') if lifecycle_action_token.nil? && instance_id.nil?
|
49
|
+
|
50
|
+
if lifecycle_action_token
|
51
|
+
run_with_backoff do
|
52
|
+
autoscaling.complete_lifecycle_action({
|
53
|
+
lifecycle_hook_name: lifecycle_hook_name,
|
54
|
+
auto_scaling_group_name: auto_scaling_group_name,
|
55
|
+
lifecycle_action_token: lifecycle_action_token,
|
56
|
+
lifecycle_action_result: 'CONTINUE'
|
57
|
+
})
|
58
|
+
end
|
59
|
+
else
|
60
|
+
run_with_backoff do
|
61
|
+
autoscaling.complete_lifecycle_action({
|
62
|
+
instance_id: instance_id,
|
63
|
+
lifecycle_hook_name: lifecycle_hook_name,
|
64
|
+
auto_scaling_group_name: auto_scaling_group_name,
|
65
|
+
lifecycle_action_result: 'CONTINUE'
|
66
|
+
})
|
67
|
+
end
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
58
|
-
def record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token:)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
71
|
+
def record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil)
|
72
|
+
raise ArgumentError.new('lifecycle_action_token or instance_id required') if lifecycle_action_token.nil? && instance_id.nil?
|
73
|
+
|
74
|
+
if lifecycle_action_token
|
75
|
+
run_with_backoff do
|
76
|
+
autoscaling.record_lifecycle_action_heartbeat({
|
77
|
+
lifecycle_hook_name: lifecycle_hook_name,
|
78
|
+
auto_scaling_group_name: auto_scaling_group_name,
|
79
|
+
lifecycle_action_token: lifecycle_action_token
|
80
|
+
})
|
81
|
+
end
|
82
|
+
else
|
83
|
+
run_with_backoff do
|
84
|
+
autoscaling.record_lifecycle_action_heartbeat({
|
85
|
+
instance_id: instance_id,
|
86
|
+
lifecycle_hook_name: lifecycle_hook_name,
|
87
|
+
auto_scaling_group_name: auto_scaling_group_name,
|
88
|
+
})
|
89
|
+
end
|
65
90
|
end
|
66
91
|
end
|
67
92
|
|
68
|
-
def keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token:)
|
93
|
+
def keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil)
|
69
94
|
24.downto(1) do |hours|
|
70
95
|
record_lifecycle_action_heartbeat(
|
71
96
|
lifecycle_hook_name: lifecycle_hook_name,
|
72
97
|
auto_scaling_group_name: auto_scaling_group_name,
|
73
|
-
lifecycle_action_token: lifecycle_action_token
|
98
|
+
lifecycle_action_token: lifecycle_action_token,
|
99
|
+
instance_id: instance_id
|
74
100
|
)
|
75
101
|
sleep 3600
|
76
102
|
end
|
data/lib/movable_ink/aws/ec2.rb
CHANGED
@@ -11,21 +11,11 @@ module MovableInk
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def load_mi_env
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
values: [instance_id]
|
20
|
-
}
|
21
|
-
])
|
22
|
-
.tags
|
23
|
-
.detect { |tag| tag.key == 'mi:env' }
|
24
|
-
.value
|
25
|
-
rescue NoMethodError
|
26
|
-
raise MovableInk::AWS::Errors::NoEnvironmentTagError
|
27
|
-
end
|
28
|
-
end
|
14
|
+
instance_tags
|
15
|
+
.detect { |tag| tag.key == 'mi:env' }
|
16
|
+
.value
|
17
|
+
rescue NoMethodError
|
18
|
+
raise MovableInk::AWS::Errors::NoEnvironmentTagError
|
29
19
|
end
|
30
20
|
|
31
21
|
def thopter_filter
|
@@ -81,6 +71,14 @@ module MovableInk
|
|
81
71
|
end
|
82
72
|
end
|
83
73
|
|
74
|
+
def instance_tags
|
75
|
+
@instance_tags ||= run_with_backoff(quiet: true) do
|
76
|
+
ec2.describe_tags({
|
77
|
+
filters: [{ name: 'resource-id', values: [instance_id] } ]
|
78
|
+
}).tags
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
84
82
|
def private_ipv4
|
85
83
|
@ipv4 ||= begin
|
86
84
|
ipv4 = `ec2metadata --local-ipv4 2>/dev/null`.chomp
|
data/lib/movable_ink/version.rb
CHANGED
data/spec/autoscaling_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe MovableInk::AWS::Autoscaling do
|
|
10
10
|
let(:create_tags_data) { ec2.stub_data(:create_tags, {}) }
|
11
11
|
let(:delete_tags_data) { ec2.stub_data(:delete_tags, {}) }
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'should mark an instance as unhealthy' do
|
14
14
|
autoscaling.stub_responses(:set_instance_health, set_instance_health_data)
|
15
15
|
allow(aws).to receive(:my_region).and_return('us-east-1')
|
16
16
|
allow(aws).to receive(:instance_id).and_return('i-12345')
|
@@ -37,19 +37,76 @@ describe MovableInk::AWS::Autoscaling do
|
|
37
37
|
expect(aws.delete_role_tag(role: 'some_role')).to eq(Aws::EmptyStructure.new)
|
38
38
|
end
|
39
39
|
|
40
|
+
it 'raises an ArgumentError when instance_id and lifecycle_action_token are not provided' do
|
41
|
+
autoscaling.stub_responses(:complete_lifecycle_action, complete_lifecycle_action_data)
|
42
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
43
|
+
allow(aws).to receive(:autoscaling).and_return(autoscaling)
|
44
|
+
expect {
|
45
|
+
aws.complete_lifecycle_action(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group')
|
46
|
+
}.to raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
40
49
|
it "should complete lifecycle actions" do
|
41
50
|
autoscaling.stub_responses(:complete_lifecycle_action, complete_lifecycle_action_data)
|
42
51
|
allow(aws).to receive(:my_region).and_return('us-east-1')
|
43
52
|
allow(aws).to receive(:autoscaling).and_return(autoscaling)
|
44
53
|
|
54
|
+
expect(autoscaling).to receive(:complete_lifecycle_action).with({
|
55
|
+
lifecycle_action_result: 'CONTINUE',
|
56
|
+
lifecycle_action_token: 'token',
|
57
|
+
lifecycle_hook_name: 'hook',
|
58
|
+
auto_scaling_group_name: 'group',
|
59
|
+
}).and_call_original
|
45
60
|
expect(aws.complete_lifecycle_action(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', lifecycle_action_token: 'token')).to eq(Aws::EmptyStructure.new)
|
46
61
|
end
|
47
62
|
|
48
|
-
it
|
63
|
+
it 'allows passing the instance_id to complete a lifecycle action' do
|
64
|
+
autoscaling.stub_responses(:complete_lifecycle_action, complete_lifecycle_action_data)
|
65
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
66
|
+
allow(aws).to receive(:autoscaling).and_return(autoscaling)
|
67
|
+
|
68
|
+
expect(autoscaling).to receive(:complete_lifecycle_action).with({
|
69
|
+
lifecycle_action_result: 'CONTINUE',
|
70
|
+
lifecycle_hook_name: 'hook',
|
71
|
+
instance_id: 'i-987654321',
|
72
|
+
auto_scaling_group_name: 'group'
|
73
|
+
}).and_call_original
|
74
|
+
expect(aws.complete_lifecycle_action(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', instance_id: 'i-987654321')).to eq(Aws::EmptyStructure.new)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should record lifecycle action heartbeats' do
|
49
78
|
autoscaling.stub_responses(:record_lifecycle_action_heartbeat, record_lifecycle_action_heartbeat_data)
|
50
79
|
allow(aws).to receive(:my_region).and_return('us-east-1')
|
51
80
|
allow(aws).to receive(:autoscaling).and_return(autoscaling)
|
52
81
|
|
82
|
+
expect(autoscaling).to receive(:record_lifecycle_action_heartbeat).with({
|
83
|
+
lifecycle_action_token: 'token',
|
84
|
+
lifecycle_hook_name: 'hook',
|
85
|
+
auto_scaling_group_name: 'group'
|
86
|
+
}).and_call_original
|
53
87
|
expect(aws.record_lifecycle_action_heartbeat(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', lifecycle_action_token: 'token')).to eq(Aws::EmptyStructure.new)
|
54
88
|
end
|
89
|
+
|
90
|
+
it 'allows passing the instance_id to record lifecycle action heartbeats' do
|
91
|
+
autoscaling.stub_responses(:record_lifecycle_action_heartbeat, record_lifecycle_action_heartbeat_data)
|
92
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
93
|
+
allow(aws).to receive(:autoscaling).and_return(autoscaling)
|
94
|
+
|
95
|
+
expect(autoscaling).to receive(:record_lifecycle_action_heartbeat).with({
|
96
|
+
instance_id: 'i-987654321',
|
97
|
+
lifecycle_hook_name: 'hook',
|
98
|
+
auto_scaling_group_name: 'group'
|
99
|
+
}).and_call_original
|
100
|
+
expect(aws.record_lifecycle_action_heartbeat(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', instance_id: 'i-987654321')).to eq(Aws::EmptyStructure.new)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'raises an ArgumentError when instance_id and lifecycle_action_token are not provided' do
|
104
|
+
autoscaling.stub_responses(:record_lifecycle_action_heartbeat, record_lifecycle_action_heartbeat_data)
|
105
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
106
|
+
allow(aws).to receive(:autoscaling).and_return(autoscaling)
|
107
|
+
|
108
|
+
expect {
|
109
|
+
aws.record_lifecycle_action_heartbeat(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group')
|
110
|
+
}.to raise_error(ArgumentError)
|
111
|
+
end
|
55
112
|
end
|
data/spec/ec2_spec.rb
CHANGED
@@ -47,6 +47,16 @@ describe MovableInk::AWS::EC2 do
|
|
47
47
|
expect(aws.private_ipv4).to eq('10.0.0.1')
|
48
48
|
end
|
49
49
|
|
50
|
+
context 'instance_tags' do
|
51
|
+
it 'returns the tags of the current instance' do
|
52
|
+
ec2.stub_responses(:describe_tags, tag_data)
|
53
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
54
|
+
allow(aws).to receive(:instance_id).and_return('i-12345')
|
55
|
+
allow(aws).to receive(:ec2).and_return(ec2)
|
56
|
+
expect(aws.instance_tags).to eq(tag_data.tags)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
context "thopter" do
|
51
61
|
let(:thopter_data) { ec2.stub_data(:describe_instances, reservations: [
|
52
62
|
instances: [
|
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: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Chesler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|