capistrano-autoscaling 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -1
- data/lib/capistrano-autoscaling.rb +107 -76
- data/lib/capistrano-autoscaling/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -76,8 +76,10 @@ The following options are preserved to manage AutoScaling.
|
|
76
76
|
### EC2 options
|
77
77
|
|
78
78
|
* `:autoscaling_ec2_instances` - The EC2 instances behind ELB.
|
79
|
-
* `:
|
79
|
+
* `:autoscaling_ec2_instance_public_dns_names` - The DNS name of EC2 instances behind ELB.
|
80
|
+
* `:autoscaling_ec2_instance_public_ip_addresses` - The IP address of EC2 instances behind ELB.
|
80
81
|
* `:autoscaling_ec2_instance_private_dns_names` - The private DNS name of EC2 instances behind ELB.
|
82
|
+
* `:autoscaling_ec2_instance_private_ip_addresses` - The private IP address of EC2 instances behind ELB.
|
81
83
|
|
82
84
|
### AMI options
|
83
85
|
|
@@ -109,9 +109,9 @@ module Capistrano
|
|
109
109
|
_cset(:autoscaling_create_alarm) { autoscaling_create_policy }
|
110
110
|
|
111
111
|
## ELB
|
112
|
-
_cset(:autoscaling_elb_instance_name_prefix, "
|
112
|
+
_cset(:autoscaling_elb_instance_name_prefix, "")
|
113
113
|
_cset(:autoscaling_elb_instance_name) { "#{autoscaling_elb_instance_name_prefix}#{autoscaling_application}" }
|
114
|
-
_cset(:autoscaling_elb_instance) { autoscaling_elb_client.load_balancers[autoscaling_elb_instance_name] }
|
114
|
+
_cset(:autoscaling_elb_instance) { autoscaling_elb_client.load_balancers[autoscaling_elb_instance_name] rescue nil }
|
115
115
|
_cset(:autoscaling_elb_port, 80)
|
116
116
|
_cset(:autoscaling_elb_protocol, :http)
|
117
117
|
_cset(:autoscaling_elb_listeners) {
|
@@ -174,6 +174,10 @@ module Capistrano
|
|
174
174
|
}
|
175
175
|
_cset(:autoscaling_ec2_instance_dns_names) { autoscaling_ec2_instances.map { |instance| instance.dns_name } }
|
176
176
|
_cset(:autoscaling_ec2_instance_private_dns_names) { autoscaling_ec2_instances.map { |instance| instance.private_dns_name } }
|
177
|
+
_cset(:autoscaling_ec2_instance_public_dns_names) { autoscaling_ec2_instances.map { |instance| instance.public_dns_name } }
|
178
|
+
_cset(:autoscaling_ec2_instance_ip_addresses) { autoscaling_ec2_instances.map { |instance| instance.ip_address } }
|
179
|
+
_cset(:autoscaling_ec2_instance_private_ip_addresses) { autoscaling_ec2_instances.map { |instance| instance.private_ip_address } }
|
180
|
+
_cset(:autoscaling_ec2_instance_public_ip_addresses) { autoscaling_ec2_instances.map { |instance| instance.public_ip_address } }
|
177
181
|
|
178
182
|
## AMI
|
179
183
|
_cset(:autoscaling_image_name_prefix) { "#{autoscaling_application}/" }
|
@@ -198,9 +202,9 @@ module Capistrano
|
|
198
202
|
|
199
203
|
## LaunchConfiguration
|
200
204
|
_cset(:autoscaling_launch_configuration) {
|
201
|
-
autoscaling_autoscaling_client.launch_configurations[autoscaling_launch_configuration_name]
|
205
|
+
autoscaling_autoscaling_client.launch_configurations[autoscaling_launch_configuration_name] rescue nil
|
202
206
|
}
|
203
|
-
_cset(:autoscaling_launch_configuration_name_prefix, "
|
207
|
+
_cset(:autoscaling_launch_configuration_name_prefix, "")
|
204
208
|
_cset(:autoscaling_launch_configuration_name) { "#{autoscaling_launch_configuration_name_prefix}#{autoscaling_image_name}" }
|
205
209
|
_cset(:autoscaling_launch_configuration_instance_type) { autoscaling_instance_type }
|
206
210
|
_cset(:autoscaling_launch_configuration_security_groups) { autoscaling_security_groups }
|
@@ -211,7 +215,7 @@ module Capistrano
|
|
211
215
|
}
|
212
216
|
|
213
217
|
## AutoScalingGroup
|
214
|
-
_cset(:autoscaling_group_name_prefix, "
|
218
|
+
_cset(:autoscaling_group_name_prefix, "")
|
215
219
|
_cset(:autoscaling_group_name) { "#{autoscaling_group_name_prefix}#{autoscaling_application}" }
|
216
220
|
_cset(:autoscaling_group_availability_zones) { autoscaling_availability_zones }
|
217
221
|
_cset(:autoscaling_group_subnets) { autoscaling_subnets } # VPC only
|
@@ -229,7 +233,7 @@ module Capistrano
|
|
229
233
|
end
|
230
234
|
options.merge(fetch(:autoscaling_group_extra_options, {}))
|
231
235
|
}
|
232
|
-
_cset(:autoscaling_group) { autoscaling_autoscaling_client.groups[autoscaling_group_name] }
|
236
|
+
_cset(:autoscaling_group) { autoscaling_autoscaling_client.groups[autoscaling_group_name] rescue nil }
|
233
237
|
|
234
238
|
## ScalingPolicy
|
235
239
|
_cset(:autoscaling_expand_policy_name_prefix, "expand-")
|
@@ -250,8 +254,8 @@ module Capistrano
|
|
250
254
|
:type => fetch(:autoscaling_shrink_policy_type, "ChangeInCapacity"),
|
251
255
|
}.merge(fetch(:autoscaling_shrink_policy_extra_options, {}))
|
252
256
|
}
|
253
|
-
_cset(:autoscaling_expand_policy) { autoscaling_group.scaling_policies[autoscaling_expand_policy_name] }
|
254
|
-
_cset(:autoscaling_shrink_policy) { autoscaling_group.scaling_policies[autoscaling_shrink_policy_name] }
|
257
|
+
_cset(:autoscaling_expand_policy) { autoscaling_group.scaling_policies[autoscaling_expand_policy_name] rescue nil }
|
258
|
+
_cset(:autoscaling_shrink_policy) { autoscaling_group.scaling_policies[autoscaling_shrink_policy_name] rescue nil }
|
255
259
|
|
256
260
|
## Alarm
|
257
261
|
_cset(:autoscaling_expand_alarm_options) {
|
@@ -275,8 +279,8 @@ module Capistrano
|
|
275
279
|
:statistic => fetch(:autoscaling_expand_alarm_evaluation_statistic, "Average"),
|
276
280
|
:namespace => fetch(:autoscaling_expand_alarm_namespace, "AWS/EC2"),
|
277
281
|
:metric_name => fetch(:autoscaling_expand_alarm_metric_name, "CPUUtilization"),
|
278
|
-
:comparison_operator => fetch(:autoscaling_expand_alarm_comparison_operator, "
|
279
|
-
:threshold => fetch(:autoscaling_expand_alarm_threshold,
|
282
|
+
:comparison_operator => fetch(:autoscaling_expand_alarm_comparison_operator, "GreaterThanThreshold"),
|
283
|
+
:threshold => fetch(:autoscaling_expand_alarm_threshold, 60),
|
280
284
|
},
|
281
285
|
}}
|
282
286
|
_cset(:autoscaling_shrink_alarm_definitions) {{
|
@@ -325,7 +329,7 @@ module Capistrano
|
|
325
329
|
end
|
326
330
|
else
|
327
331
|
logger.debug("Creating ELB instance: #{autoscaling_elb_instance_name}")
|
328
|
-
set(:autoscaling_elb_instance,
|
332
|
+
set(:autoscaling_elb_instance, autoscaling_elb_client.load_balancers.create(
|
329
333
|
autoscaling_elb_instance_name, autoscaling_elb_instance_options))
|
330
334
|
sleep(autoscaling_wait_interval) unless autoscaling_elb_instance.exists?
|
331
335
|
logger.debug("Created ELB instance: #{autoscaling_elb_instance.name}")
|
@@ -340,7 +344,7 @@ module Capistrano
|
|
340
344
|
|
341
345
|
task(:destroy_elb, :roles => :app, :except => { :no_release => true }) {
|
342
346
|
if autoscaling_elb_instance and autoscaling_elb_instance.exists?
|
343
|
-
if 0 < autoscaling_elb_instance.length
|
347
|
+
if 0 < autoscaling_elb_instance.instances.length
|
344
348
|
abort("ELB is not empty.")
|
345
349
|
end
|
346
350
|
logger.debug("Deleting ELB: #{autoscaling_elb_instance.name}")
|
@@ -486,7 +490,7 @@ module Capistrano
|
|
486
490
|
task(:update_alarm, :roles => :app, :except => { :no_release => true }) {
|
487
491
|
if autoscaling_create_alarm
|
488
492
|
autoscaling_expand_alarm_definitions.each do |alarm_name, alarm_options|
|
489
|
-
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
493
|
+
alarm = ( autoscaling_cloudwatch_client.alarms[alarm_name] rescue nil )
|
490
494
|
if alarm and alarm.exists?
|
491
495
|
logger.debug("Found Alarm for expansion: #{alarm.name}")
|
492
496
|
else
|
@@ -504,7 +508,7 @@ module Capistrano
|
|
504
508
|
|
505
509
|
if autoscaling_create_alarm
|
506
510
|
autoscaling_shrink_alarm_definitions.each do |alarm_name, alarm_options|
|
507
|
-
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
511
|
+
alarm = ( autoscaling_cloudwatch_client.alarms[alarm_name] rescue nil )
|
508
512
|
if alarm and alarm.exists?
|
509
513
|
logger.debug("Found Alarm for shrinking: #{alarm.name}")
|
510
514
|
else
|
@@ -523,7 +527,7 @@ module Capistrano
|
|
523
527
|
|
524
528
|
task(:destroy_alarm, :roles => :app, :except => { :no_release => true }) {
|
525
529
|
autoscaling_expand_alarm_definitions.each do |alarm_name, alarm_options|
|
526
|
-
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
530
|
+
alarm = ( autoscaling_cloudwatch_client.alarms[alarm_name] rescue nil)
|
527
531
|
if alarm and alarm.exists?
|
528
532
|
logger.debug("Deleting Alarm for expansion: #{alarm.name}")
|
529
533
|
alarm.delete()
|
@@ -532,7 +536,7 @@ module Capistrano
|
|
532
536
|
end
|
533
537
|
|
534
538
|
autoscaling_shrink_alarm_definitions.each do |alarm_name, alarm_options|
|
535
|
-
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
539
|
+
alarm = ( autoscaling_cloudwatch_client.alarms[alarm_name] rescue nil )
|
536
540
|
if alarm and alarm.exists?
|
537
541
|
logger.debug("Deleting Alarm for shrinking: #{alarm.name}")
|
538
542
|
alarm.delete()
|
@@ -563,61 +567,86 @@ module Capistrano
|
|
563
567
|
|
564
568
|
desc("Show AutoScaling status.")
|
565
569
|
task(:status, :roles => :app, :except => { :no_release => true }) {
|
570
|
+
status = {}
|
571
|
+
|
572
|
+
if autoscaling_group and autoscaling_group.exists?
|
573
|
+
status[:name] = autoscaling_group.name
|
574
|
+
status[:availability_zone_names] = autoscaling_group.availability_zone_names.to_a
|
575
|
+
status[:desired_capacity] = autoscaling_group.desired_capacity
|
576
|
+
status[:max_size] = autoscaling_group.max_size
|
577
|
+
status[:min_size] = autoscaling_group.min_size
|
578
|
+
end
|
579
|
+
|
580
|
+
launch_configuration = nil
|
581
|
+
if autoscaling_group and autoscaling_group.exists?
|
582
|
+
launch_configuration = autoscaling_gruop.launch_configuration
|
583
|
+
elsif autoscaling_launch_configuration and autoscaling_launch_configuration.exists?
|
584
|
+
launch_configuration = autoscaling_launch_configuration
|
585
|
+
end
|
586
|
+
if launch_configuration
|
587
|
+
status[:launch_configuration] = {
|
588
|
+
:name => launch_configuration.name,
|
589
|
+
:iam_instance_profile => launch_configuration.iam_instance_profile,
|
590
|
+
:instance_type => launch_configuration.instance_type,
|
591
|
+
:security_groups => launch_configuration.security_groups.map { |sg| sg.name },
|
592
|
+
:image => {
|
593
|
+
:id => launch_configuration.image.id,
|
594
|
+
:name => launch_configuration.image.name,
|
595
|
+
:state => launch_configuration.image.state,
|
596
|
+
}
|
597
|
+
}
|
598
|
+
end
|
599
|
+
|
600
|
+
load_balancers = nil
|
566
601
|
if autoscaling_group and autoscaling_group.exists?
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
:name =>
|
575
|
-
:
|
576
|
-
:
|
577
|
-
:
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
602
|
+
load_balancers = autoscaling_group.load_balancers.to_a
|
603
|
+
elsif autoscaling_elb_instance and autoscaling_elb_instance.exists?
|
604
|
+
load_balancers = [ autoscaling_elb_instance ]
|
605
|
+
end
|
606
|
+
if load_balancers
|
607
|
+
status[:load_balancers] = load_balancers.map { |lb|
|
608
|
+
{
|
609
|
+
:name => lb.name,
|
610
|
+
:availability_zone_names => lb.availability_zone_names.to_a,
|
611
|
+
:dns_name => lb.dns_name,
|
612
|
+
:instances => lb.instances.map { |i|
|
613
|
+
{
|
614
|
+
:id => i.id,
|
615
|
+
:private_ip_address => i.private_ip_address,
|
616
|
+
:private_dns_name => i.private_dns_name,
|
617
|
+
:public_ip_address => i.public_ip_address,
|
618
|
+
:public_dns_name => i.public_dns_name,
|
619
|
+
:status => i.status,
|
620
|
+
}
|
582
621
|
},
|
583
|
-
}
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
:scheduled_actions => autoscaling_group.scheduled_actions.map { |action|
|
609
|
-
{
|
610
|
-
:name => action.name,
|
611
|
-
:desired_capacity => action.desired_capacity,
|
612
|
-
:end_time => action.end_time,
|
613
|
-
:max_size => action.max_size,
|
614
|
-
:min_size => action.min_size,
|
615
|
-
:start_time => action.start_time,
|
616
|
-
}
|
617
|
-
},
|
618
|
-
:suspended_processes => autoscaling_group.suspended_processes.to_hash,
|
619
|
-
}.to_yaml)
|
622
|
+
}
|
623
|
+
}
|
624
|
+
end
|
625
|
+
|
626
|
+
if autoscaling_group and autoscaling_group.exists?
|
627
|
+
status[:scaling_policies] = autoscaling_group.scaling_policies.map { |policy|
|
628
|
+
{
|
629
|
+
:name => policy.name,
|
630
|
+
:adjustment_type => policy.adjustment_type,
|
631
|
+
:alarms => policy.alarms.to_hash.keys,
|
632
|
+
:cooldown => policy.cooldown,
|
633
|
+
:scaling_adjustment => policy.scaling_adjustment,
|
634
|
+
}
|
635
|
+
}
|
636
|
+
status[:scheduled_actions] = autoscaling_group.scheduled_actions.map { |action|
|
637
|
+
{
|
638
|
+
:name => action.name,
|
639
|
+
:desired_capacity => action.desired_capacity,
|
640
|
+
:end_time => action.end_time,
|
641
|
+
:max_size => action.max_size,
|
642
|
+
:min_size => action.min_size,
|
643
|
+
:start_time => action.start_time,
|
644
|
+
}
|
645
|
+
}
|
646
|
+
status[:suspended_processes] = autoscaling_group.suspended_processes.to_hash
|
620
647
|
end
|
648
|
+
|
649
|
+
STDOUT.puts(status.to_yaml)
|
621
650
|
}
|
622
651
|
|
623
652
|
desc("Show AutoScaling history.")
|
@@ -625,14 +654,16 @@ module Capistrano
|
|
625
654
|
if autoscaling_group and autoscaling_group.exists?
|
626
655
|
autoscaling_group.scaling_policies.each do |policy|
|
627
656
|
policy.alarms.each do |alarm_name, alarm_arn|
|
628
|
-
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
657
|
+
alarm = ( autoscaling_cloudwatch_client.alarms[alarm_name] rescue nil )
|
658
|
+
if alarm and alarm.exists?
|
659
|
+
start_date = Time.now - fetch(:autoscaling_history_days, 3) * 86400
|
660
|
+
history_items = alarm.history_items.with_start_date(start_date)
|
661
|
+
|
662
|
+
STDOUT.puts("--")
|
663
|
+
STDOUT.puts("Alarm: #{alarm_name} (ScalingPolicy: #{policy.name})")
|
664
|
+
history_items.each do |hi|
|
665
|
+
STDOUT.puts("#{hi.timestamp}: #{hi.type}: #{hi.summary}")
|
666
|
+
end
|
636
667
|
end
|
637
668
|
end
|
638
669
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-autoscaling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -85,3 +85,4 @@ specification_version: 3
|
|
85
85
|
summary: A Capistrano recipe that configures AutoScaling on Amazon Web Services infrastructure
|
86
86
|
for your application.
|
87
87
|
test_files: []
|
88
|
+
has_rdoc:
|