hiera-aws 0.0.4 → 0.0.5
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.
- checksums.yaml +7 -7
- data/README.md +26 -0
- data/lib/hiera/backend/aws/elasticache.rb +64 -4
- data/lib/hiera/backend/aws/version.rb +1 -1
- data/spec/aws_elasticache_spec.rb +79 -35
- metadata +70 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db0800685a66b940ed05671f7b7e6ef30c44d561
|
4
|
+
data.tar.gz: 39bd81a8d5ec926b3388f4f115a13e18c7f499d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c15a81ed1e10cc95e8b10738707480bcf8814b9760cf3235bb35b5365cdef783742338f2b833ac5fd4f898e51ae9af9176fb65c756e4c66abb59302efe7972e
|
7
|
+
data.tar.gz: 567661b4d8c7973c9d9e3b995bb15d9f3b2f25c94cd26a652090182a580388469dd6bf77f3cd5cb2aacbacda07349957bf1cf22a94d32cca7f72ac52f42e519e
|
data/README.md
CHANGED
@@ -57,12 +57,38 @@ identified by its physical ID which must be passed to the backend via the Puppet
|
|
57
57
|
fact `$cache_cluster_id`. The returned array has the format `["host1:port",
|
58
58
|
"host2:port"]`.
|
59
59
|
|
60
|
+
Usage:
|
61
|
+
|
60
62
|
```
|
61
63
|
$cache_cluster_id = "your_cluster_id"
|
62
64
|
|
63
65
|
cluster_nodes = hiera("cache_nodes_by_cache_cluster_id")
|
64
66
|
```
|
65
67
|
|
68
|
+
### redis_cluster_nodes_for_cfn_stack
|
69
|
+
|
70
|
+
Returns an array of all Redis cluster nodes for the CloudFormation stack of an
|
71
|
+
EC2 instance. The instance is identified by the Puppet fact `$ec2_instance_id`.
|
72
|
+
The returned array has the format `["host1", "host2"]`.
|
73
|
+
|
74
|
+
Usage:
|
75
|
+
|
76
|
+
```
|
77
|
+
cluster_nodes = hiera("redis_cluster_nodes_for_cfn_stack")
|
78
|
+
```
|
79
|
+
|
80
|
+
### memcached_cluster_nodes_for_cfn_stack
|
81
|
+
|
82
|
+
Returns an array of all Memcached cluster nodes for the CloudFormation stack of
|
83
|
+
an EC2 instance. The instance is identified by the Puppet fact
|
84
|
+
`$ec2_instance_id`. The returned array has the format `["host1", "host2"]`.
|
85
|
+
|
86
|
+
Usage:
|
87
|
+
|
88
|
+
```
|
89
|
+
cluster_nodes = hiera("memcached_cluster_nodes_for_cfn_stack")
|
90
|
+
```
|
91
|
+
|
66
92
|
## License and Authors
|
67
93
|
|
68
94
|
* Author:: Mathias Lafeldt (mathias.lafeldt@jimdo.com)
|
@@ -4,18 +4,78 @@ class Hiera
|
|
4
4
|
module Backend
|
5
5
|
module Aws
|
6
6
|
class ElastiCache < Base
|
7
|
-
def
|
7
|
+
def cache_nodes_by_cache_cluster_id
|
8
8
|
region = scope["location"] || "eu-west-1"
|
9
|
-
AWS::ElastiCache::Client.new :region => region
|
10
|
-
end
|
9
|
+
client = AWS::ElastiCache::Client.new :region => region
|
11
10
|
|
12
|
-
def cache_nodes_by_cache_cluster_id
|
13
11
|
cache_cluster_id = scope["cache_cluster_id"]
|
14
12
|
raise MissingFactError, "cache_cluster_id not found" unless cache_cluster_id
|
15
13
|
options = { :cache_cluster_id => cache_cluster_id, :show_cache_node_info => true }
|
16
14
|
nodes = client.describe_cache_clusters(options)[:cache_clusters].first[:cache_nodes]
|
17
15
|
nodes.map { |node| "#{node[:endpoint][:address]}:#{node[:endpoint][:port]}" }
|
18
16
|
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# XXX: Lots of spiked code ahead that MUST be refactored.
|
20
|
+
#
|
21
|
+
def cfn_stack_name(instance_id)
|
22
|
+
region = scope["location"] || "eu-west-1"
|
23
|
+
client = AWS::EC2.new :region => region
|
24
|
+
|
25
|
+
instances = client.instances[instance_id]
|
26
|
+
instances.tags["aws:cloudformation:stack-name"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def cache_cluster_info(cluster_id)
|
30
|
+
region = scope["location"] || "eu-west-1"
|
31
|
+
client = AWS::ElastiCache::Client.new :region => region
|
32
|
+
|
33
|
+
options = { :cache_cluster_id => cluster_id, :show_cache_node_info => true }
|
34
|
+
info = client.describe_cache_clusters(options)
|
35
|
+
info.fetch(:cache_clusters).first
|
36
|
+
end
|
37
|
+
|
38
|
+
def cache_clusters_in_cfn_stack(stack_name, cluster_engine=nil)
|
39
|
+
region = scope["location"] || "eu-west-1"
|
40
|
+
client = AWS::CloudFormation.new :region => region
|
41
|
+
|
42
|
+
stack = client.stacks[stack_name]
|
43
|
+
stack.resources.select do |r|
|
44
|
+
r.resource_type == "AWS::ElastiCache::CacheCluster"
|
45
|
+
end.map do |r|
|
46
|
+
cluster_id = r.physical_resource_id
|
47
|
+
cache_cluster_info(cluster_id)
|
48
|
+
end.select do |cluster|
|
49
|
+
# Filter by engine type if provided
|
50
|
+
if cluster_engine
|
51
|
+
cluster.fetch(:engine) == cluster_engine.to_s
|
52
|
+
else
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def cluster_nodes_for_cfn_stack(cluster_engine=nil)
|
59
|
+
ec2_instance_id = scope["ec2_instance_id"]
|
60
|
+
raise MissingFactError, "ec2_instance_id not found" unless ec2_instance_id
|
61
|
+
|
62
|
+
stack_name = cfn_stack_name(ec2_instance_id)
|
63
|
+
endpoints = []
|
64
|
+
clusters = cache_clusters_in_cfn_stack(stack_name, cluster_engine)
|
65
|
+
clusters.each do |cluster|
|
66
|
+
nodes = cluster.fetch(:cache_nodes)
|
67
|
+
endpoints += nodes.map { |node| node[:endpoint][:address] }
|
68
|
+
end
|
69
|
+
endpoints
|
70
|
+
end
|
71
|
+
|
72
|
+
def redis_cluster_nodes_for_cfn_stack
|
73
|
+
cluster_nodes_for_cfn_stack(:redis)
|
74
|
+
end
|
75
|
+
|
76
|
+
def memcached_cluster_nodes_for_cfn_stack
|
77
|
+
cluster_nodes_for_cfn_stack(:memcached)
|
78
|
+
end
|
19
79
|
end
|
20
80
|
end
|
21
81
|
end
|
@@ -3,56 +3,100 @@ require "hiera/backend/aws/elasticache"
|
|
3
3
|
class Hiera
|
4
4
|
module Backend
|
5
5
|
describe Aws::ElastiCache do
|
6
|
-
|
7
|
-
|
6
|
+
let(:ec_redis_client) { double(
|
7
|
+
:describe_cache_clusters => {
|
8
|
+
:cache_clusters => [{
|
9
|
+
:cache_nodes => [
|
10
|
+
{ :endpoint => { :address => "1.1.1.1", :port => 1234 } },
|
11
|
+
{ :endpoint => { :address => "2.2.2.2", :port => 1234 } },
|
12
|
+
|
13
|
+
],
|
14
|
+
:engine => "redis"
|
15
|
+
}]
|
16
|
+
}
|
17
|
+
)}
|
18
|
+
let(:ec_memcached_client) { double(
|
19
|
+
:describe_cache_clusters => {
|
20
|
+
:cache_clusters => [{
|
21
|
+
:cache_nodes => [
|
22
|
+
{ :endpoint => { :address => "3.3.3.3", :port => 5678 } },
|
23
|
+
{ :endpoint => { :address => "4.4.4.4", :port => 5678 } },
|
24
|
+
|
25
|
+
],
|
26
|
+
:engine => "memcached"
|
27
|
+
}]
|
28
|
+
}
|
29
|
+
)}
|
30
|
+
let(:ec2_client) { double(
|
31
|
+
:instances => {
|
32
|
+
"some-ec2-instance-id" => double(
|
33
|
+
:tags => { "aws:cloudformation:stack-name" => "some-stack-name" }
|
34
|
+
)
|
35
|
+
}
|
36
|
+
)}
|
37
|
+
let(:cfn_client) { double(
|
38
|
+
:stacks => {
|
39
|
+
"some-stack-name" => double(
|
40
|
+
:resources => [
|
41
|
+
double(
|
42
|
+
:resource_type => "AWS::ElastiCache::CacheCluster",
|
43
|
+
:physical_resource_id => "some-cluster-id"
|
44
|
+
)
|
45
|
+
]
|
46
|
+
)
|
47
|
+
}
|
48
|
+
)}
|
49
|
+
|
50
|
+
before do
|
51
|
+
AWS::EC2.stub(:new => ec2_client)
|
52
|
+
AWS::CloudFormation.stub(:new => cfn_client)
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#cache_nodes_by_cache_cluster_id" do
|
56
|
+
it "raises an exception when called without cache_cluster_id set" do
|
8
57
|
elasticache = Aws::ElastiCache.new
|
9
|
-
|
10
|
-
|
11
|
-
|
58
|
+
expect do
|
59
|
+
elasticache.cache_nodes_by_cache_cluster_id
|
60
|
+
end.to raise_error Aws::MissingFactError
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns all nodes in cache cluster" do
|
64
|
+
scope = { "cache_cluster_id" => "some-cluster-id" }
|
65
|
+
elasticache = Aws::ElastiCache.new scope
|
66
|
+
AWS::ElastiCache::Client.stub(:new => ec_redis_client)
|
67
|
+
expect(elasticache.cache_nodes_by_cache_cluster_id).to eq ["1.1.1.1:1234", "2.2.2.2:1234"]
|
12
68
|
end
|
69
|
+
end
|
13
70
|
|
14
|
-
|
71
|
+
describe "#redis_cluster_nodes_for_cfn_stack" do
|
72
|
+
it "raises an exception when ec2_instance_id fact is missing" do
|
15
73
|
elasticache = Aws::ElastiCache.new
|
16
|
-
expect
|
17
|
-
|
74
|
+
expect do
|
75
|
+
elasticache.redis_cluster_nodes_for_cfn_stack
|
76
|
+
end.to raise_error Aws::MissingFactError
|
18
77
|
end
|
19
78
|
|
20
|
-
it "
|
21
|
-
scope = { "
|
79
|
+
it "returns all Redis cluster nodes for CloudFormation stack of EC2 instance" do
|
80
|
+
scope = { "ec2_instance_id" => "some-ec2-instance-id" }
|
22
81
|
elasticache = Aws::ElastiCache.new scope
|
23
|
-
|
24
|
-
elasticache.
|
82
|
+
AWS::ElastiCache::Client.stub(:new => ec_redis_client)
|
83
|
+
expect(elasticache.redis_cluster_nodes_for_cfn_stack).to eq ["1.1.1.1", "2.2.2.2"]
|
25
84
|
end
|
26
85
|
end
|
27
86
|
|
28
|
-
describe "#
|
29
|
-
it "raises an exception when
|
30
|
-
|
31
|
-
elasticache = Aws::ElastiCache.new scope
|
87
|
+
describe "#memcached_cluster_nodes_for_cfn_stack" do
|
88
|
+
it "raises an exception when ec2_instance_id fact is missing" do
|
89
|
+
elasticache = Aws::ElastiCache.new
|
32
90
|
expect do
|
33
|
-
elasticache.
|
91
|
+
elasticache.memcached_cluster_nodes_for_cfn_stack
|
34
92
|
end.to raise_error Aws::MissingFactError
|
35
93
|
end
|
36
94
|
|
37
|
-
it "returns all nodes
|
38
|
-
|
39
|
-
scope = { "cache_cluster_id" => cluster_id }
|
95
|
+
it "returns all Memcached cluster nodes for CloudFormation stack of EC2 instance" do
|
96
|
+
scope = { "ec2_instance_id" => "some-ec2-instance-id" }
|
40
97
|
elasticache = Aws::ElastiCache.new scope
|
41
|
-
|
42
|
-
|
43
|
-
:cache_clusters => [{
|
44
|
-
:cache_nodes => [
|
45
|
-
{ :endpoint => { :address => "1.2.3.4", :port => 1234 } },
|
46
|
-
{ :endpoint => { :address => "5.6.7.8", :port => 5678 } },
|
47
|
-
]
|
48
|
-
}]
|
49
|
-
}
|
50
|
-
options = { :cache_cluster_id => cluster_id, :show_cache_node_info => true }
|
51
|
-
client = Object.new
|
52
|
-
client.stub(:describe_cache_clusters).with(options).and_return(cluster_info)
|
53
|
-
AWS::ElastiCache::Client.stub(:new => client)
|
54
|
-
|
55
|
-
expect(elasticache.cache_nodes_by_cache_cluster_id).to eq ["1.2.3.4:1234", "5.6.7.8:5678"]
|
98
|
+
AWS::ElastiCache::Client.stub(:new => ec_memcached_client)
|
99
|
+
expect(elasticache.memcached_cluster_nodes_for_cfn_stack).to eq ["3.3.3.3", "4.4.4.4"]
|
56
100
|
end
|
57
101
|
end
|
58
102
|
end
|
metadata
CHANGED
@@ -1,63 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-aws
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Mathias Lafeldt
|
8
8
|
- Deniz Adrian
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: aws-sdk
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
24
21
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: bundler
|
28
22
|
prerelease: false
|
29
|
-
|
30
|
-
requirements:
|
31
|
-
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
32
35
|
type: :development
|
33
|
-
version_requirements: *id003
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: rake
|
36
36
|
prerelease: false
|
37
|
-
|
38
|
-
requirements:
|
39
|
-
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
40
49
|
type: :development
|
41
|
-
version_requirements: *id004
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rspec
|
44
50
|
prerelease: false
|
45
|
-
|
46
|
-
requirements:
|
47
|
-
-
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
48
63
|
type: :development
|
49
|
-
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
50
70
|
description: Hiera AWS Backend
|
51
|
-
email:
|
71
|
+
email:
|
52
72
|
- mathias.lafeldt@jimdo.com
|
53
73
|
- deniz.adrian@jimdo.com
|
54
74
|
executables: []
|
55
|
-
|
56
75
|
extensions: []
|
57
|
-
|
58
76
|
extra_rdoc_files: []
|
59
|
-
|
60
|
-
files:
|
77
|
+
files:
|
61
78
|
- .gitignore
|
62
79
|
- .travis.yml
|
63
80
|
- Gemfile
|
@@ -73,29 +90,30 @@ files:
|
|
73
90
|
- spec/aws_base_spec.rb
|
74
91
|
- spec/aws_elasticache_spec.rb
|
75
92
|
homepage: https://github.com/Jimdo/hiera-aws
|
76
|
-
licenses:
|
93
|
+
licenses:
|
77
94
|
- Apache 2.0
|
78
95
|
metadata: {}
|
79
|
-
|
80
96
|
post_install_message:
|
81
97
|
rdoc_options: []
|
82
|
-
|
83
|
-
require_paths:
|
98
|
+
require_paths:
|
84
99
|
- lib
|
85
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
-
|
88
|
-
|
89
|
-
|
90
|
-
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
91
110
|
requirements: []
|
92
|
-
|
93
111
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.1.9
|
95
113
|
signing_key:
|
96
114
|
specification_version: 4
|
97
115
|
summary: Hiera AWS Backend
|
98
|
-
test_files:
|
116
|
+
test_files:
|
99
117
|
- spec/aws_backend_spec.rb
|
100
118
|
- spec/aws_base_spec.rb
|
101
119
|
- spec/aws_elasticache_spec.rb
|