capistrano-elb 0.3.8 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,6 +18,8 @@ then just
18
18
 
19
19
  This will instantiate an instance of the CapELB class and add hooks to remove/readd before/after deploys
20
20
 
21
+ As of version 0.4.0 it looks for an 'elb' tag with value of the name of a loadbalancer to decide when to remove/readd servers.
22
+
21
23
  (Equivalent to having the following in your deploy.rb)
22
24
 
23
25
  require "capistrano-elb"
@@ -37,10 +39,6 @@ This will instantiate an instance of the CapELB class and add hooks to remove/re
37
39
  capELB.add servers
38
40
  end
39
41
 
40
- task :save do
41
- capELB.save_config
42
- end
43
-
44
42
  task :check do
45
43
  puts capELB.check_config
46
44
  end
@@ -49,11 +47,6 @@ This will instantiate an instance of the CapELB class and add hooks to remove/re
49
47
  before "deploy", "elb:remove"
50
48
  after "deploy", "elb:add"
51
49
 
52
- The first time you run it a record of the ELB setup is saved to config/lbs.yaml, you can check/update this with
53
- cap elb:check
54
- cap elb:save
55
-
56
-
57
50
  You can just require capistrano-elb and do whatever you want inside your deploy scripts of course
58
51
 
59
52
  If you want to hook after deploy but before the elb:add you can target
@@ -3,12 +3,17 @@ require 'yaml'
3
3
  require 'capistrano'
4
4
  require 'pp'
5
5
 
6
+ class Hash
7
+ def diff(h2)
8
+ dup.delete_if { |k, v| h2[k] == v }.merge!(h2.dup.delete_if { |k, v| has_key?(k) })
9
+ end
10
+ end
11
+
6
12
  class CapELB
7
13
  def initialize(configdir=File.join(Dir.pwd, 'config'))
8
14
  ec2credentials = YAML::load(File.open(File.join(configdir, 'ec2credentials.yaml')))
9
15
  aws = Fog::Compute.new(ec2credentials.merge({:provider=>'AWS'}))
10
16
  @regions = aws.describe_regions.body["regionInfo"].map {|region| region["regionName"]}
11
- @regions -= ['us-west-2']
12
17
  @compute = {}
13
18
  @regions.each do |region|
14
19
  @compute.merge!(region => Fog::Compute.new(ec2credentials.merge({:provider=>'AWS',:region=>region})))
@@ -19,40 +24,37 @@ class CapELB
19
24
  @elb.merge!(region => Fog::AWS::ELB.new(ec2credentials.merge(:region=>region)))
20
25
  end
21
26
 
22
- @lbsfile = File.join(configdir, 'lbs.yaml')
23
-
24
- @lbs = load_config
27
+ @lbs = config_from_tags
25
28
  end
26
29
 
27
- def config_from_aws
30
+ def config_from_tags
28
31
  lbs = {}
29
32
  @regions.each do |region|
30
- loadBalancerDescriptions =
31
- @elb[region].describe_load_balancers.body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"]
32
- loadBalancerDescriptions.each do |lb|
33
- lbs.merge!({region => {lb["LoadBalancerName"] => lb["Instances"]}})
33
+ @elb[region].load_balancers.each do |lb|
34
+ lbs.merge!({region => {lb.id => get_instances(region,lb.id)}})
34
35
  end
35
36
  end
36
37
  lbs
37
38
  end
38
39
 
39
- def save_config
40
- File.open( @lbsfile, 'w' ) do |file|
41
- YAML.dump( config_from_aws, file )
40
+ def config_from_lb
41
+ lbs = {}
42
+ @regions.each do |region|
43
+ @elb[region].load_balancers.each do |lb|
44
+ lbs.merge!({region => {lb.id => lb.instances}})
45
+ end
42
46
  end
47
+ lbs
43
48
  end
44
49
 
45
- def load_config
46
- unless File.exists? @lbsfile
47
- save_config
48
- end
49
- YAML::load(File.open(@lbsfile))
50
+ def get_instances(region,lbname)
51
+ @compute[region].tags.select{|tag| tag.key == 'elb' and tag.value==lbname}.map(&:resource_id)
50
52
  end
51
53
 
52
54
  def check_config
53
- current = config_from_aws
55
+ current = config_from_lb
54
56
  errors = []
55
- load_config.each_pair do |region,lbs|
57
+ @lbs.each_pair do |region,lbs|
56
58
  lbs.each_pair do |lbname, target_instances|
57
59
  missing = target_instances - current[region][lbname]
58
60
  extra = current[region][lbname] - target_instances
@@ -14,10 +14,6 @@ Capistrano::Configuration.instance(:must_exist).load do
14
14
  capELB.add servers
15
15
  end
16
16
 
17
- task :save do
18
- capELB.save_config
19
- end
20
-
21
17
  task :check do
22
18
  puts capELB.check_config
23
19
  end
@@ -25,5 +21,4 @@ Capistrano::Configuration.instance(:must_exist).load do
25
21
 
26
22
  before "deploy", "elb:remove"
27
23
  after "deploy", "elb:add"
28
-
29
24
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Elb
3
- VERSION = "0.3.8"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-elb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
12
+ date: 2012-01-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
16
- requirement: &2152996680 !ruby/object:Gem::Requirement
16
+ requirement: &2154279140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152996680
24
+ version_requirements: *2154279140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capistrano
27
- requirement: &2152995860 !ruby/object:Gem::Requirement
27
+ requirement: &2154278720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152995860
35
+ version_requirements: *2154278720
36
36
  description: Capistrano plugin for removing/readd servers to EC2 load balancers
37
37
  email:
38
38
  - tom.hall@forward.co.uk
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project: capistrano-elb
71
- rubygems_version: 1.8.10
71
+ rubygems_version: 1.8.12
72
72
  signing_key:
73
73
  specification_version: 3
74
74
  summary: Automagically remove/readd servers from EC2 load balancers as you cap deploy