class CloudFormationTool::CLI::Scale
Public Instance Methods
execute()
click to toggle source
# File lib/cloud_formation_tool/cli/scale.rb, line 24 def execute debug "Starting scale operations" st = CloudFormation::Stack.new(stack_name) st.asgroups.select do |res| debug "Checking group #{res.logical_resource_id}" asg_name.nil? or (res.logical_resource_id == asg_name) end.collect do |res| debug "Scaling #{res.logical_resource_id}" Thread.new do grp = res.group debug "Current capacity: #{grp.desired_capacity}, setting to #{scale}" grp.set_desired_capacity(desired_capacity: scale) last_state = nil until stable_scale(grp, scale) log "Current scaling status: #{last_state = grpstatedesc(grp)}" unless last_state.eql? grpstatedesc(grp) sleep 3 grp.reload end log "Done updating - current scale: #{grpstatedesc(grp)}" end end.each(&:join) end
grpstate(grp)
click to toggle source
# File lib/cloud_formation_tool/cli/scale.rb, line 11 def grpstate(grp) grp.instances.collect { |i| i.lifecycle_state }.reduce({}) { |m,s| m[s] = (m[s] || 0) + 1; m } end
grpstatedesc(grp)
click to toggle source
# File lib/cloud_formation_tool/cli/scale.rb, line 15 def grpstatedesc(grp) grpstate(grp).collect{|s,c|"#{c} #{s}"}.join(", ") end
stable_scale(grp, scale)
click to toggle source
# File lib/cloud_formation_tool/cli/scale.rb, line 19 def stable_scale(grp, scale) state = grpstate(grp) state["InService"].eql? scale.to_i and state.delete_if{|k|k.eql? "InService"}.empty? end