capistrano-autoscaling 0.0.7 → 0.0.8

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7363699523a99cdf60e981b3e759fffda434b8e5
4
+ data.tar.gz: 814e02ab14f068b077f4a13685cdfb06b0d5ab51
5
+ SHA512:
6
+ metadata.gz: 5570b9dcb3245e50d8f83f58cd8388dd102f717394554d27c7f41ca17359dd0f32038e3e26ccf906cbe4fdd4630d867f2b538557385b8c192d940d42be3d4510
7
+ data.tar.gz: 616cd32fc692b576a1b45b9307de9a4ce5e61105fd6f57a9f2ca9250d0732df91bd2db323a5d661563bbc9668ff3d24b6f71c4bd2c45cfffbe9d6fa09a9297c7
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency("capistrano", "< 3")
21
- gem.add_dependency("aws-sdk", ">= 1.5.4")
21
+ gem.add_dependency("aws-sdk", ">= 1.9.0")
22
22
  end
@@ -4,59 +4,12 @@ require "yaml"
4
4
 
5
5
  module Capistrano
6
6
  module AutoScaling
7
+
7
8
  def self.extended(configuration)
8
9
  configuration.load {
9
10
  namespace(:autoscaling) {
10
11
  ## AWS
11
- _cset(:autoscaling_region, nil)
12
- _cset(:autoscaling_autoscaling_endpoint) {
13
- case autoscaling_region
14
- when "us-east-1" then "autoscaling.us-east-1.amazonaws.com"
15
- when "us-west-1" then "autoscaling.us-west-1.amazonaws.com"
16
- when "us-west-2" then "autoscaling.us-west-2.amazonaws.com"
17
- when "sa-east-1" then "autoscaling.sa-east-1.amazonaws.com"
18
- when "eu-west-1" then "autoscaling.eu-west-1.amazonaws.com"
19
- when "ap-southeast-1" then "autoscaling.ap-southeast-1.amazonaws.com"
20
- when "ap-southeast-2" then "autoscaling.ap-southeast-2.amazonaws.com"
21
- when "ap-northeast-1" then "autoscaling.ap-northeast-1.amazonaws.com"
22
- end
23
- }
24
- _cset(:autoscaling_cloudwatch_endpoint) {
25
- case autoscaling_region
26
- when "us-east-1" then "monitoring.us-east-1.amazonaws.com"
27
- when "us-west-1" then "monitoring.us-west-1.amazonaws.com"
28
- when "us-west-2" then "monitoring.us-west-2.amazonaws.com"
29
- when "sa-east-1" then "monitoring.sa-east-1.amazonaws.com"
30
- when "eu-west-1" then "monitoring.eu-west-1.amazonaws.com"
31
- when "ap-southeast-1" then "monitoring.ap-southeast-1.amazonaws.com"
32
- when "ap-southeast-2" then "monitoring.ap-southeast-2.amazonaws.com"
33
- when "ap-northeast-1" then "monitoring.ap-northeast-1.amazonaws.com"
34
- end
35
- }
36
- _cset(:autoscaling_ec2_endpoint) {
37
- case autoscaling_region
38
- when "us-east-1" then "ec2.us-east-1.amazonaws.com"
39
- when "us-west-1" then "ec2.us-west-1.amazonaws.com"
40
- when "us-west-2" then "ec2.us-west-2.amazonaws.com"
41
- when "sa-east-1" then "ec2.sa-east-1.amazonaws.com"
42
- when "eu-west-1" then "ec2.eu-west-1.amazonaws.com"
43
- when "ap-southeast-1" then "ec2.ap-southeast-1.amazonaws.com"
44
- when "ap-southeast-2" then "ec2.ap-southeast-2.amazonaws.com"
45
- when "ap-northeast-1" then "ec2.ap-northeast-1.amazonaws.com"
46
- end
47
- }
48
- _cset(:autoscaling_elb_endpoint) {
49
- case autoscaling_region
50
- when "us-east-1" then "elasticloadbalancing.us-east-1.amazonaws.com"
51
- when "us-west-1" then "elasticloadbalancing.us-west-1.amazonaws.com"
52
- when "us-west-2" then "elasticloadbalancing.us-west-2.amazonaws.com"
53
- when "sa-east-1" then "elasticloadbalancing.sa-east-1.amazonaws.com"
54
- when "eu-west-1" then "elasticloadbalancing.eu-west-1.amazonaws.com"
55
- when "ap-southeast-1" then "elasticloadbalancing.ap-southeast-1.amazonaws.com"
56
- when "ap-southeast-2" then "elasticloadbalancing.ap-southeast-2.amazonaws.com"
57
- when "ap-northeast-1" then "elasticloadbalancing.ap-northeast-1.amazonaws.com"
58
- end
59
- }
12
+ _cset(:autoscaling_region, "us-east-1")
60
13
  _cset(:autoscaling_access_key_id) {
61
14
  fetch(:aws_access_key_id, ENV["AWS_ACCESS_KEY_ID"]) or abort("AWS_ACCESS_KEY_ID is not set")
62
15
  }
@@ -64,20 +17,18 @@ module Capistrano
64
17
  fetch(:aws_secret_access_key, ENV["AWS_SECRET_ACCESS_KEY"]) or abort("AWS_SECRET_ACCESS_KEY is not set")
65
18
  }
66
19
  _cset(:autoscaling_aws_options) {
67
- {
20
+ options = {
68
21
  :access_key_id => autoscaling_access_key_id,
69
22
  :secret_access_key => autoscaling_secret_access_key,
70
23
  :log_level => fetch(:autoscaling_log_level, :debug),
71
- :auto_scaling_endpoint => autoscaling_autoscaling_endpoint,
72
- :cloud_watch_endpoint => autoscaling_cloudwatch_endpoint,
73
- :ec2_endpoint => autoscaling_ec2_endpoint,
74
- :elb_endpoint => autoscaling_elb_endpoint,
24
+ :region => autoscaling_region,
75
25
  }.merge(fetch(:autoscaling_aws_extra_options, {}))
76
26
  }
77
- _cset(:autoscaling_autoscaling_client) { AWS::AutoScaling.new(fetch(:autoscaling_autoscaling_aws_options, autoscaling_aws_options)) }
78
- _cset(:autoscaling_cloudwatch_client) { AWS::CloudWatch.new(fetch(:autoscaling_cloudwatch_options, autoscaling_aws_options)) }
79
- _cset(:autoscaling_ec2_client) { AWS::EC2.new(fetch(:autoscaling_ec2_options, autoscaling_aws_options)) }
80
- _cset(:autoscaling_elb_client) { AWS::ELB.new(fetch(:autoscaling_elb_options, autoscaling_aws_options)) }
27
+ _cset(:autoscaling_aws) { AWS.tap { |aws| aws.config(autoscaling_aws_options) } }
28
+ _cset(:autoscaling_autoscaling_client) { autoscaling_aws.auto_scaling(fetch(:autoscaling_autoscaling_aws_options, {})) }
29
+ _cset(:autoscaling_cloudwatch_client) { autoscaling_aws.cloud_watch(fetch(:autoscaling_cloudwatch_options,{})) }
30
+ _cset(:autoscaling_ec2_client) { autoscaling_aws.ec2(fetch(:autoscaling_ec2_options, {})) }
31
+ _cset(:autoscaling_elb_client) { autoscaling_aws.elb(fetch(:autoscaling_elb_options, {})) }
81
32
 
82
33
  def autoscaling_name_mangling(s)
83
34
  s.to_s.gsub(/[^0-9A-Za-z]/, "-")
@@ -200,6 +151,11 @@ module Capistrano
200
151
  autoscaling_ec2_client.images.with_owner("self").filter("name", "#{autoscaling_image_name_prefix}*").to_a
201
152
  }
202
153
 
154
+ def self.proto_instance(task)
155
+ ec2_dns = (find_servers_for_task(current_task)[0]).host
156
+ autoscaling_ec2_instances.find { |instance| instance.public_dns_name == ec2_dns }
157
+ end
158
+
203
159
  ## LaunchConfiguration
204
160
  _cset(:autoscaling_launch_configuration) {
205
161
  autoscaling_autoscaling_client.launch_configurations[autoscaling_launch_configuration_name] rescue nil
@@ -242,16 +198,16 @@ module Capistrano
242
198
  _cset(:autoscaling_shrink_policy_name) { "#{autoscaling_shrink_policy_name_prefix}#{autoscaling_application}" }
243
199
  _cset(:autoscaling_expand_policy_options) {
244
200
  {
245
- :adjustment => fetch(:autoscaling_expand_policy_adjustment, 1),
201
+ :scaling_adjustment => fetch(:autoscaling_expand_policy_adjustment, 1),
246
202
  :cooldown => fetch(:autoscaling_expand_policy_cooldown, 300),
247
- :type => fetch(:autoscaling_expand_policy_type, "ChangeInCapacity"),
203
+ :adjustment_type => fetch(:autoscaling_expand_policy_type, "ChangeInCapacity"),
248
204
  }.merge(fetch(:autoscaling_expand_policy_extra_options, {}))
249
205
  }
250
206
  _cset(:autoscaling_shrink_policy_options) {
251
207
  {
252
- :adjustment => fetch(:autoscaling_shrink_policy_adjustment, -1),
208
+ :scaling_adjustment => fetch(:autoscaling_shrink_policy_adjustment, -1),
253
209
  :cooldown => fetch(:autoscaling_shrink_policy_cooldown, 300),
254
- :type => fetch(:autoscaling_shrink_policy_type, "ChangeInCapacity"),
210
+ :adjustment_type => fetch(:autoscaling_shrink_policy_type, "ChangeInCapacity"),
255
211
  }.merge(fetch(:autoscaling_shrink_policy_extra_options, {}))
256
212
  }
257
213
  _cset(:autoscaling_expand_policy) { autoscaling_group.scaling_policies[autoscaling_expand_policy_name] rescue nil }
@@ -304,6 +260,21 @@ module Capistrano
304
260
  end
305
261
  }
306
262
 
263
+ desc("Add the EC2 Instance used as the AMI prototype to the load balancer from :app")
264
+ task(:add_proto_instance, :roles => :app, :except => { :no_release => true }) {
265
+ # Find the host name for :app and get its instance
266
+ ec2_dns = (find_servers_for_task(current_task)[0]).host
267
+ app_instance = autoscaling_aws.ec2.instances.find { |instance| instance.public_dns_name == ec2_dns }
268
+
269
+ autoscaling_elb_instance.instances.register app_instance
270
+ }
271
+ _cset(:autoscaling_add_proto_instance_after_hooks, ["autoscaling:setup"])
272
+ on(:load) {
273
+ [ autoscaling_add_proto_instance_after_hooks ].flatten.each do |t|
274
+ after t, "autoscaling:add_proto_instance" if t
275
+ end
276
+ }
277
+
307
278
  desc("Remove AutoScaling settings.")
308
279
  task(:destroy, :roles => :app, :except => { :no_release => true }) {
309
280
  destroy_alarm
@@ -373,8 +344,9 @@ module Capistrano
373
344
  logger.debug("Creating AMI: #{autoscaling_image_name}")
374
345
  run("sync; sync; sync") # force flushing to disk
375
346
  set(:autoscaling_image, autoscaling_ec2_client.images.create(
376
- autoscaling_image_options.merge(:name => autoscaling_image_name, :instance_id => autoscaling_image_instance.id)))
377
- sleep(autoscaling_wait_interval) until autoscaling_image.exists?
347
+ autoscaling_image_options.merge(:name => autoscaling_image_name,
348
+ :instance_id => self.proto_instance(current_task).id)))
349
+ sleep(autoscaling_wait_interval) until autoscaling_image.state == :available
378
350
  logger.debug("Created AMI: #{autoscaling_image.name} (#{autoscaling_image.id})")
379
351
  [["Name", {:value => autoscaling_image_name}], [autoscaling_image_tag_name]].each do |tag_name, tag_options|
380
352
  begin
@@ -418,8 +390,11 @@ module Capistrano
418
390
  logger.debug("Found AutoScalingGroup: #{autoscaling_group.name} (#{autoscaling_group.launch_configuration_name})")
419
391
  autoscaling_group.update(autoscaling_group_options.merge(:launch_configuration => autoscaling_launch_configuration))
420
392
  else
393
+ logger.debug("autoscaling_elb_instance name is #{autoscaling_elb_instance.name}")
394
+ logger.debug("autoscaling_launch_configuration name is #{autoscaling_launch_configuration.name}")
421
395
  if autoscaling_elb_instance.exists? and autoscaling_launch_configuration.exists?
422
396
  logger.debug("Creating AutoScalingGroup: #{autoscaling_group_name} (#{autoscaling_launch_configuration.name})")
397
+ logger.debug("autoscaling_group_options = #{autoscaling_group_options.inspect}")
423
398
  set(:autoscaling_group, autoscaling_autoscaling_client.groups.create(autoscaling_group_name,
424
399
  autoscaling_group_options.merge(:launch_configuration => autoscaling_launch_configuration,
425
400
  :load_balancers => [ autoscaling_elb_instance ])))
@@ -581,6 +556,8 @@ module Capistrano
581
556
  task(:status, :roles => :app, :except => { :no_release => true }) {
582
557
  status = {}
583
558
 
559
+ logger.info("Autoscaling Group: #{autoscaling_group.name}") if autoscaling_group
560
+
584
561
  if autoscaling_group and autoscaling_group.exists?
585
562
  status[:name] = autoscaling_group.name
586
563
  status[:availability_zone_names] = autoscaling_group.availability_zone_names.to_a
@@ -591,7 +568,7 @@ module Capistrano
591
568
 
592
569
  launch_configuration = nil
593
570
  if autoscaling_group and autoscaling_group.exists?
594
- launch_configuration = autoscaling_gruop.launch_configuration
571
+ launch_configuration = autoscaling_group.launch_configuration
595
572
  elsif autoscaling_launch_configuration and autoscaling_launch_configuration.exists?
596
573
  launch_configuration = autoscaling_launch_configuration
597
574
  end
@@ -616,6 +593,7 @@ module Capistrano
616
593
  load_balancers = [ autoscaling_elb_instance ]
617
594
  end
618
595
  if load_balancers
596
+ logger.info("Value of load_balancers: #{load_balancers.to_s}")
619
597
  status[:load_balancers] = load_balancers.map { |lb|
620
598
  {
621
599
  :name => lb.name,
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module AutoScaling
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,48 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-autoscaling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Yamashita Yuu
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-26 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: capistrano
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - <
17
+ - - "<"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - <
24
+ - - "<"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: aws-sdk
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: 1.5.4
33
+ version: 1.9.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
- version: 1.5.4
40
+ version: 1.9.0
46
41
  description: A Capistrano recipe that configures AutoScaling on Amazon Web Services
47
42
  infrastructure for your application.
48
43
  email:
@@ -51,7 +46,7 @@ executables: []
51
46
  extensions: []
52
47
  extra_rdoc_files: []
53
48
  files:
54
- - .gitignore
49
+ - ".gitignore"
55
50
  - Gemfile
56
51
  - LICENSE.txt
57
52
  - README.md
@@ -61,27 +56,26 @@ files:
61
56
  - lib/capistrano-autoscaling/version.rb
62
57
  homepage: https://github.com/yyuu/capistrano-autoscaling
63
58
  licenses: []
59
+ metadata: {}
64
60
  post_install_message:
65
61
  rdoc_options: []
66
62
  require_paths:
67
63
  - lib
68
64
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
65
  requirements:
71
- - - ! '>='
66
+ - - ">="
72
67
  - !ruby/object:Gem::Version
73
68
  version: '0'
74
69
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
70
  requirements:
77
- - - ! '>='
71
+ - - ">="
78
72
  - !ruby/object:Gem::Version
79
73
  version: '0'
80
74
  requirements: []
81
75
  rubyforge_project:
82
- rubygems_version: 1.8.23
76
+ rubygems_version: 2.2.2
83
77
  signing_key:
84
- specification_version: 3
78
+ specification_version: 4
85
79
  summary: A Capistrano recipe that configures AutoScaling on Amazon Web Services infrastructure
86
80
  for your application.
87
81
  test_files: []