10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/cloud_formation_tool/cli/recycle.rb', line 10
def execute
st = CloudFormation::Stack.new(stack_name)
st.asgroups.select do |res|
asg_name.nil? or (res.logical_resource_id == asg_name)
end.collect do |res|
Thread.new do
grp = res.group
torecycle = cursize = grp.instances.size
puts "#{grp.name}: Recyclying #{cursize} instance" + (cursize > 1 ? "s" : "")
while torecycle > 0
grp.set_desired_capacity(desired_capacity: (cursize + 1))
while grp.instances.size != (cursize + 1)
sleep 5
grp.reload
end
grp.set_desired_capacity(desired_capacity: cursize)
while grp.instances.size != cursize
sleep 5
grp.reload
end
torecycle -= 1
puts "#{grp.name}: Left to recycle - #{torecycle}"
end
end
end.each(&:join).length > 0 or _error "No valid Autoscaling groups found named #{asg_name}"
end
|