add a MAX keyword to simply bring up as many instances as are already running

This commit is contained in:
Anuj Biyani 2014-01-22 11:34:39 -08:00
parent 03b826dbe1
commit 6cc88eb9aa
2 changed files with 31 additions and 4 deletions

View File

@ -21,6 +21,8 @@ module AwsMissingTools
raise ArgumentError, "The Auto Scaling Group named #{@opts[:as_group_name]} does not exist in #{@opts[:region]}." raise ArgumentError, "The Auto Scaling Group named #{@opts[:as_group_name]} does not exist in #{@opts[:region]}."
end end
@opts[:num_simultaneous_instances] = Integer(@opts[:num_simultaneous_instances]) rescue @group.auto_scaling_instances.count
@max_size_change = 0 @max_size_change = 0
@time_spent_inservice = 0 @time_spent_inservice = 0
end end
@ -64,7 +66,7 @@ module AwsMissingTools
end end
opts.on('-n', '--num-simultaneous-instances NUM', 'Number of instances to simultaneously bring up per iteration') do |v| opts.on('-n', '--num-simultaneous-instances NUM', 'Number of instances to simultaneously bring up per iteration') do |v|
options[:num_simultaneous_instances] = v.to_i options[:num_simultaneous_instances] = v
end end
end.parse!(arguments) end.parse!(arguments)
@ -98,6 +100,7 @@ module AwsMissingTools
@group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances]) @group.update(desired_capacity: @group.desired_capacity + @opts[:num_simultaneous_instances])
puts "The list of instances in Auto Scaling Group #{@group.name} that will be terminated is:\n#{@group.auto_scaling_instances.map{ |i| i.ec2_instance.id }.to_ary}" puts "The list of instances in Auto Scaling Group #{@group.name} that will be terminated is:\n#{@group.auto_scaling_instances.map{ |i| i.ec2_instance.id }.to_ary}"
puts "The number of instances that will be brought up simultaneously is: #{@opts[:num_simultaneous_instances]}"
@group.auto_scaling_instances.to_a.each_slice(@opts[:num_simultaneous_instances]) do |instances| @group.auto_scaling_instances.to_a.each_slice(@opts[:num_simultaneous_instances]) do |instances|
time_taken = 0 time_taken = 0

View File

@ -28,6 +28,22 @@ describe 'aws-ha-release' do
AwsMissingTools::AwsHaRelease.new(opts) AwsMissingTools::AwsHaRelease.new(opts)
}.should raise_error }.should raise_error
end end
context 'number of simultaneous instances' do
before do
as.groups.create opts[1]
opts.push('--num-simultaneous-instances')
end
it 'with MAX, sets the option to the number of active instances' do
opts.push('MAX')
expect(AwsMissingTools::AwsHaRelease.new(opts).instance_variable_get('@opts')[:num_simultaneous_instances]).to eq 2
end
it 'with an integer, sets the option to that integer' do
opts.push('1')
expect(AwsMissingTools::AwsHaRelease.new(opts).instance_variable_get('@opts')[:num_simultaneous_instances]).to eq 1
end
end
end end
describe '#parse_options' do describe '#parse_options' do
@ -82,9 +98,17 @@ describe 'aws-ha-release' do
end end
end end
it 'number of instances to simultaneously bring up' do context 'number of instances to simultaneously bring up' do
it 'recognizes integer inputs' do
[%w(-a test_group -n 2), %w(-a test_group --num-simultaneous-instances 2)].each do |options| [%w(-a test_group -n 2), %w(-a test_group --num-simultaneous-instances 2)].each do |options|
expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq 2 expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq '2'
end
end
it 'recognizes the MAX keyword' do
[%w(-a test_group -n MAX), %w(-a test_group --num-simultaneous-instances MAX)].each do |options|
expect(AwsMissingTools::AwsHaRelease.parse_options(options)[:num_simultaneous_instances]).to eq 'MAX'
end
end end
end end
end end