olery-aws 1.2.1 → 1.3.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
2
  SHA256:
3
- metadata.gz: 4592a112c2bfde7e1fc50a21e6f06e6d5308de8ccb1c6c6291494df50184e732
4
- data.tar.gz: b6e2b32c49a1859ae05298850f081e55173b39ddb4605f122a63c03dc07ec4a2
3
+ metadata.gz: ac29fe4f4188601f1e6c5448b1559342f715ff959dfdd383416c515ede4b4136
4
+ data.tar.gz: 48b99d784fae2a65b917f5d938704228b8174fb607b7a981e3ba290c0da253e5
5
5
  SHA512:
6
- metadata.gz: 44679fc3c631095891f66d11369119512136e06d8d6df86616d5b68e7256cc89106bb53c28781394c0c89c569ff91cc62084d1d6922ac0db55d14e30f4eca8b3
7
- data.tar.gz: 7c6d2d6ddd2faf261fc64879759bd5cdf1cbbd1a95dbec7aba3834e4160dfa71b001ddeacc0dd977393bb294872a1a9b60bdaa5a05d32b95313b543bddc31cdd
6
+ metadata.gz: 438cb9bf859d8aca981836eda06b8b659df66c157dc3bdb16f341f19ee709e4070f82d3f2492aff09c411ab7dfaa11a249937a830cc2231d861aaf1ff77ebf37
7
+ data.tar.gz: 49c2c42bbd65b3df9b7808b32050bcd068e6f2bb340b5bada16453f32ace09ea1d7f207cbb1837e3bbbf67d11694884f50bfc0fd66e3925a86e3e77b94224293
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/olery/aws'
4
+
5
+ require'pry'
6
+ Pry.start
7
+
@@ -102,15 +102,23 @@ Examples:
102
102
  # @param [Struct] group
103
103
  #
104
104
  def rotate_elb(group)
105
- info 'Disabling terminating of instances'
105
+ if group.load_balancer_names.blank?
106
+ info 'Starting instance refresh'
107
+ auto_scaling.start_instance_refresh auto_scaling_group_name: group.auto_scaling_group_name
106
108
 
107
- suspend_processes(group.auto_scaling_group_name, 'Terminate')
109
+ info 'Waiting refresh to finish'
110
+ wait_until_refresh group
111
+ return
112
+ end
108
113
 
109
- new_size = group.max_size * 2
110
- new_desired = group.desired_capacity * 2
114
+ info 'Disabling terminating of instances'
115
+ suspend_processes group.auto_scaling_group_name, 'Terminate'
111
116
 
112
- info "Doubling autoscaling capacity to #{new_size}"
117
+ new_size = group.max_size * 2
118
+ new_desired = group.desired_capacity * 2
119
+ instance_ids = group.instances.map(&:instance_id)
113
120
 
121
+ info "Doubling autoscaling desired to #{new_desired} and capacity to #{new_size}"
114
122
  update_group(
115
123
  group.auto_scaling_group_name,
116
124
  max_size: new_size,
@@ -118,34 +126,26 @@ Examples:
118
126
  )
119
127
 
120
128
  info 'Waiting for ELBs to register instances'
121
-
122
- wait_for_elbs group.load_balancer_names, new_desired
129
+ wait_for_elbs group, new_desired
123
130
 
124
131
  info 'Waiting for all instances to be in service'
125
-
126
132
  group.load_balancer_names.each do |elb_name|
127
133
  wait_until_in_service(elb_name)
128
134
  end
129
135
 
130
- instance_ids = group.instances.map(&:instance_id)
131
-
132
136
  info 'Disabling launching of new instances'
133
-
134
137
  suspend_processes(group.auto_scaling_group_name, 'Launch')
135
138
 
136
139
  info 'Detaching old instances'
137
-
138
140
  detach_instances(group.auto_scaling_group_name, instance_ids)
139
141
 
140
142
  info 'Waiting for instances to be removed from autoscaling group'
141
-
142
143
  wait_until_removed_from_group(
143
144
  group.auto_scaling_group_name,
144
145
  instance_ids
145
146
  )
146
147
 
147
148
  info 'Terminating old instances'
148
-
149
149
  terminate_instances(instance_ids)
150
150
 
151
151
  wait_until_terminated(instance_ids)
@@ -302,22 +302,44 @@ Examples:
302
302
  # @param [Array] elb_names
303
303
  # @param [Struct] group
304
304
  #
305
- def wait_for_elbs(elb_names, instances)
305
+ def wait_for_elbs group, instances
306
306
  loop_with_limit do
307
307
  response = load_balancing.describe_load_balancers(
308
- :load_balancer_names => elb_names
308
+ :load_balancer_names => group.load_balancer_names
309
309
  )
310
310
 
311
311
  ok_elbs = response.load_balancer_descriptions.count do |elb|
312
312
  elb.instances.length == instances
313
313
  end
314
314
 
315
- break if ok_elbs == elb_names.length
315
+ break if ok_elbs == group.load_balancer_names.length
316
316
 
317
317
  sleep(5)
318
318
  end
319
319
  end
320
320
 
321
+ def wait_until_refresh group
322
+ loop_with_limit do
323
+ desc = auto_scaling.describe_instance_refreshes auto_scaling_group_name: group.auto_scaling_group_name
324
+ refresh = desc.instance_refreshes.first
325
+
326
+ break if refresh.percentage_complete == 100
327
+
328
+ sleep 10
329
+ end
330
+ end
331
+
332
+ def wait_until_healthy group, desired
333
+ loop_with_limit do
334
+ group = get_group group.auto_scaling_group_name
335
+
336
+ instances = group.instances.select{ |i| lifecycle_state == 'InService' and g.health_status == 'Healthy' }
337
+ break if instances.size == desired
338
+
339
+ sleep 5
340
+ end
341
+ end
342
+
321
343
  ##
322
344
  # @param [String] elb_name
323
345
  #
@@ -463,7 +485,7 @@ Examples:
463
485
  # @return [String|NilClass]
464
486
  #
465
487
  def group_locked_by(group_name)
466
- tag = get_group(group_name).tags.find { |tag| tag.key == LOCK_TAG }
488
+ tag = get_group(group_name).tags.find{ |t| t.key == LOCK_TAG }
467
489
 
468
490
  tag ? tag.value : nil
469
491
  end
@@ -1,7 +1,7 @@
1
1
  module Olery
2
2
  module AWS
3
3
 
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
 
6
6
  end
7
7
  end
data/lib/olery/aws.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'aws-sdk'
2
2
  require 'slop'
3
3
  require 'uuid'
4
+ require 'active_support/all'
4
5
 
5
6
  require 'logger'
6
7
 
data/olery-aws.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'aws-sdk', '~> 2.0'
23
23
  gem.add_dependency 'slop', '~> 4.0'
24
24
  gem.add_dependency 'uuid'
25
+ gem.add_dependency 'activesupport'
25
26
 
26
27
  gem.add_development_dependency 'pry'
27
28
  gem.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: olery-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olery B.V.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +131,7 @@ extensions: []
117
131
  extra_rdoc_files: []
118
132
  files:
119
133
  - README.md
134
+ - bin/console
120
135
  - bin/olery-aws
121
136
  - lib/olery/aws.rb
122
137
  - lib/olery/aws/command.rb