Class: CloudFormationTool::CLI::Scale
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- CloudFormationTool::CLI::Scale
show all
- Includes:
- CloudFormationTool
- Defined in:
- lib/cloud_formation_tool/cli/scale.rb
Constant Summary
VERSION
Instance Method Summary
collapse
#aws_config, #awsas, #awscdn, #awscf, #awscreds, #awsec2, #awsecs, #awss3, #cf_bucket_name, #find_profile, #profile, #region, #s3_bucket_name
Instance Method Details
#execute ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# 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) ⇒ Object
11
12
13
|
# 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) ⇒ Object
15
16
17
|
# 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) ⇒ Object
19
20
21
22
|
# 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
|