Class: Capistrano::Autoscale::AWS::AutoscaleGroup
- Inherits:
-
Base
- Object
- Base
- Capistrano::Autoscale::AWS::AutoscaleGroup
show all
- Defined in:
- lib/capistrano/autoscale/aws/autoscale_group.rb
Constant Summary
collapse
- SUSPEND_PROCESSES =
%w[Launch Terminate].freeze
- LIFECYCLE_STATE_IN_SERVICE =
'InService'
- LIFECYCLE_STATE_STANDBY =
'Standby'
- AMI_PREFIX_TAG =
'Autoscale-Ami-Prefix'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#autoscaling_client, #aws_access_key_id, #aws_autoscale_ami_tags, #aws_autoscale_snapshot_tags, #aws_credentials, #aws_options, #aws_region, #aws_secret_access_key, #ec2_client
Constructor Details
Returns a new instance of AutoscaleGroup.
16
17
18
19
20
21
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 16
def initialize(name)
@name = name
@aws_counterpart = Aws::AutoScaling::AutoScalingGroup.new name: name, client: autoscaling_client
raise Capistrano::Autoscale::Errors::NoAutoScalingGroup, name unless @aws_counterpart.exists?
end
|
Instance Attribute Details
#aws_counterpart ⇒ Object
Returns the value of attribute aws_counterpart.
14
15
16
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 14
def aws_counterpart
@aws_counterpart
end
|
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 14
def name
@name
end
|
Instance Method Details
#ami_prefix ⇒ Object
62
63
64
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 62
def ami_prefix
tags[AMI_PREFIX_TAG]
end
|
#enter_standby(instance) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 66
def enter_standby(instance)
instance = aws_counterpart.instances.select { |i| i.id == instance.id }.first
instance.enter_standby(should_decrement_desired_capacity: true)
loop do
break if instance.lifecycle_state == LIFECYCLE_STATE_STANDBY
sleep 1
instance.load
end
end
|
#exit_standby(instance) ⇒ Object
78
79
80
81
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 78
def exit_standby(instance)
instance = aws_counterpart.instances.select { |i| i.id == instance.id }.first
instance.exit_standby
end
|
#instances ⇒ Object
23
24
25
26
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 23
def instances
instance_ids = aws_counterpart.instances.map(&:instance_id)
InstanceCollection.new(instance_ids)
end
|
#instances_in_service ⇒ Object
28
29
30
31
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 28
def instances_in_service
instance_ids = aws_counterpart.instances.select { |i| i.lifecycle_state == LIFECYCLE_STATE_IN_SERVICE }.map(&:instance_id)
InstanceCollection.new(instance_ids)
end
|
#launch_template ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 33
def launch_template
lts = aws_launch_template || aws_launch_template_specification
raise Capistrano::Autoscale::Errors::NoLaunchTemplate unless lts
LaunchTemplate.new(
lts.launch_template_id,
lts.launch_template_name,
lts.version,
false,
nil
)
end
|
#resume ⇒ Object
50
51
52
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 50
def resume
aws_counterpart.resume_processes(scaling_processes: SUSPEND_PROCESSES)
end
|
#suspend ⇒ Object
46
47
48
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 46
def suspend
aws_counterpart.suspend_processes(scaling_processes: SUSPEND_PROCESSES)
end
|
#suspended? ⇒ Boolean
54
55
56
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 54
def suspended?
aws_counterpart.suspended_processes.map(&:process_name).any? { |name| SUSPEND_PROCESSES.include?(name) }
end
|
58
59
60
|
# File 'lib/capistrano/autoscale/aws/autoscale_group.rb', line 58
def tags
aws_counterpart.tags.map { |tag| [tag.key, tag.value] }.to_h
end
|