automan 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d5223742567c1e2f6a4d8d4acce6b217b5274b4
4
- data.tar.gz: ee52d65bf8bc91b45e6252ecc1c166f214182c35
3
+ metadata.gz: 118de08fcf9ce73a9ea6e2b54b288637f564cc7e
4
+ data.tar.gz: d0166e7b15c3cf92e286508a71661441f0f1fa6e
5
5
  SHA512:
6
- metadata.gz: 8243eb955f0b5c3d4fd01c029767454dc4964cc3eb47cd805237e12ebd02bdfecf6a9329cbf5c38d07bfe40aecda27c5f5ea6160e1f11748588208e11b08a4e1
7
- data.tar.gz: 406c82dd210f316967ae942c17b6151c57aeb2c372944612632a5e4f851b412e91b9ecf966255d4ff6c6fd56ba343a447889701ea777074d6a1638543f3a73bb
6
+ metadata.gz: 527cf0bc65acc51f1859c860a66e9995bb30e0e1c5dc2e586ae277036af610df6a02bddd0a4b338df56cc29869119b0c755bcf797fdef5128af8004b03168ab8
7
+ data.tar.gz: 7340e6559f341bc1caeca419a6d6d6d245bf1971e62dc6bad44443991cec6cd0a92ab939b179bac842b4b44677cd963dab69a036ff09c6a66e6d359880d12a1b
data/lib/automan.rb CHANGED
@@ -19,6 +19,7 @@ require 'automan/cloudformation/terminator'
19
19
  require 'automan/cloudformation/replacer'
20
20
  require 'automan/cloudformation/uploader'
21
21
  require 'automan/cloudformation/errors'
22
+ require 'automan/elasticache/router'
22
23
  require 'automan/rds/snapshot'
23
24
  require 'automan/rds/errors'
24
25
  require 'automan/ec2/instance'
@@ -0,0 +1,79 @@
1
+ require 'automan'
2
+
3
+ module Automan::ElastiCache
4
+ class Router < Automan::Base
5
+
6
+ add_option :environment,
7
+ :hosted_zone_name,
8
+ :redis_host
9
+
10
+ def node_name_from_elasticache_environment(env)
11
+
12
+ opts = {
13
+ cache_cluster_id: "redis-#{env}",
14
+ show_cache_node_info: true
15
+ }
16
+
17
+ response = ec.client.describe_cache_clusters opts
18
+
19
+ unless response.successful?
20
+ raise RequestFailedError, "describe_cache_clusters failed: #{response.error}"
21
+ end
22
+
23
+ cluster=response.data[:cache_clusters]
24
+ if cluster.empty?
25
+ return nil
26
+ end
27
+
28
+ nodes=Hash[*cluster][:cache_nodes]
29
+ if nodes.empty?
30
+ return nil
31
+ end
32
+
33
+ endpoint=Hash[*nodes][:endpoint]
34
+ if endpoint.empty?
35
+ return nil
36
+ end
37
+
38
+ logger.info "found redis endpoint at #{endpoint[:address]}"
39
+ endpoint[:address]
40
+ end
41
+
42
+ # be sure alias_name ends in period
43
+ def update_dns_alias(zone_name, redis_cname, primary_endpoint)
44
+ zone = r53.hosted_zones.select {|z| z.name == zone_name}.first
45
+ rrset = zone.rrsets[redis_cname + '.', 'CNAME']
46
+
47
+ if rrset.exists?
48
+ logger.info "removing old record at #{redis_cname}"
49
+ rrset.delete
50
+ end
51
+
52
+ logger.info "creating record #{redis_cname} -> #{primary_endpoint}"
53
+ zone.rrsets.create(
54
+ redis_cname + '.',
55
+ 'CNAME',
56
+ :ttl => 300,
57
+ :resource_records => [{:value => primary_endpoint}]
58
+ )
59
+ end
60
+
61
+ def run
62
+ log_options
63
+
64
+ logger.info "getting redis primary node name..."
65
+ primary_endpoint = node_name_from_elasticache_environment environment
66
+
67
+ if primary_endpoint.nil?
68
+ false
69
+ else
70
+ update_dns_alias(
71
+ hosted_zone_name,
72
+ redis_host,
73
+ primary_endpoint
74
+ )
75
+ true
76
+ end
77
+ end
78
+ end
79
+ end
@@ -108,6 +108,14 @@ module Automan
108
108
  @rds
109
109
  end
110
110
 
111
+ attr_writer :ec
112
+ def ec
113
+ if @ec.nil?
114
+ @ec = AWS::ElastiCache.new
115
+ end
116
+ @ec
117
+ end
118
+
111
119
  attr_writer :ec2
112
120
  def ec2
113
121
  if @ec2.nil?
@@ -1,3 +1,3 @@
1
1
  module Automan
2
- VERSION = "2.3.2"
2
+ VERSION = "2.3.3"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'automan'
2
+
3
+ describe Automan::ElastiCache::Router do
4
+ it { is_expected.to respond_to :run }
5
+ it { is_expected.to respond_to :environment_name }
6
+ it { is_expected.to respond_to :hosted_zone_name }
7
+ it { is_expected.to respond_to :redis_host }
8
+
9
+ describe '#run' do
10
+ subject() do
11
+ AWS.stub!
12
+ r = Automan::ElastiCache::Router.new
13
+ r.ec = AWS::ElastiCache::Client.new
14
+ r.environment_name = 'foo'
15
+ r.hosted_zone_name = 'foo.com'
16
+ r.redis_host = 'redis.foo.com'
17
+ r.logger = Logger.new('/dev/null')
18
+ r
19
+ end
20
+
21
+ it "raises error if it never finds a name" do
22
+ allow(subject).to receive(:node_name_from_elasticache_environment).and_return(nil)
23
+ expect {
24
+ subject.run
25
+ }.not_to raise_error
26
+ end
27
+
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automan
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Chalfant
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-19 00:00:00.000000000 Z
12
+ date: 2015-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -207,6 +207,7 @@ files:
207
207
  - lib/automan/ec2/errors.rb
208
208
  - lib/automan/ec2/image.rb
209
209
  - lib/automan/ec2/instance.rb
210
+ - lib/automan/elasticache/router.rb
210
211
  - lib/automan/mixins/aws_caller.rb
211
212
  - lib/automan/mixins/utils.rb
212
213
  - lib/automan/rds/errors.rb
@@ -231,6 +232,7 @@ files:
231
232
  - spec/cloudformation/uploader_spec.rb
232
233
  - spec/ec2/image_spec.rb
233
234
  - spec/ec2/instance_spec.rb
235
+ - spec/elasticache/router_spec.rb
234
236
  - spec/mixins/aws_caller_spec.rb
235
237
  - spec/mixins/utils_spec.rb
236
238
  - spec/rds/snapshot_spec.rb
@@ -281,6 +283,7 @@ test_files:
281
283
  - spec/cloudformation/uploader_spec.rb
282
284
  - spec/ec2/image_spec.rb
283
285
  - spec/ec2/instance_spec.rb
286
+ - spec/elasticache/router_spec.rb
284
287
  - spec/mixins/aws_caller_spec.rb
285
288
  - spec/mixins/utils_spec.rb
286
289
  - spec/rds/snapshot_spec.rb