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 +4 -4
- data/lib/automan.rb +1 -0
- data/lib/automan/elasticache/router.rb +79 -0
- data/lib/automan/mixins/aws_caller.rb +8 -0
- data/lib/automan/version.rb +1 -1
- data/spec/elasticache/router_spec.rb +29 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 118de08fcf9ce73a9ea6e2b54b288637f564cc7e
|
4
|
+
data.tar.gz: d0166e7b15c3cf92e286508a71661441f0f1fa6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/automan/version.rb
CHANGED
@@ -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.
|
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
|
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
|