cluster-discovery 0.1.0

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.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +9 -0
  5. data/.rubocop_todo.yml +62 -0
  6. data/Gemfile +26 -0
  7. data/Gemfile.lock +141 -0
  8. data/Guardfile +47 -0
  9. data/LICENSE +22 -0
  10. data/README.md +89 -0
  11. data/Rakefile +51 -0
  12. data/Thorfile +3 -0
  13. data/cluster-discovery.gemspec +26 -0
  14. data/lib/cluster/discovery/consul.rb +46 -0
  15. data/lib/cluster/discovery/ec2/auto_scaling.rb +27 -0
  16. data/lib/cluster/discovery/ec2/tag.rb +64 -0
  17. data/lib/cluster/discovery/errors.rb +21 -0
  18. data/lib/cluster/discovery/version.rb +6 -0
  19. data/lib/cluster/discovery.rb +38 -0
  20. data/spec/cassettes/Cluster_Discovery/_discover/can_discover_nodes/discovery_with_consul.yml +38 -0
  21. data/spec/cassettes/Cluster_Discovery_Consul/_discover/can_discover_all_nodes/can_discover_nodes_with_tags.yml +38 -0
  22. data/spec/cassettes/Cluster_Discovery_Consul/_discover/can_discover_all_nodes/can_discover_nodes_without_tags.yml +38 -0
  23. data/spec/cassettes/Cluster_Discovery_Consul/_discover/can_discover_leader_node/can_discover_nodes_with_tags.yml +38 -0
  24. data/spec/cassettes/Cluster_Discovery_Consul/_discover/can_discover_leader_node/can_discover_nodes_without_tags.yml +38 -0
  25. data/spec/cassettes/Cluster_Discovery_EC2_AutoScaling/_discover/can_reuse_the_tag_provider/can_find_instances_by_aws_auto_scaling_group.yml +191 -0
  26. data/spec/cassettes/Cluster_Discovery_EC2_Tag/_discover/passing_aws_region_arg/can_find_instances_by_tag.yml +862 -0
  27. data/spec/lib/cluster/discovery/consul_spec.rb +119 -0
  28. data/spec/lib/cluster/discovery/ec2/auto_scaling_spec.rb +19 -0
  29. data/spec/lib/cluster/discovery/ec2/tag_spec.rb +81 -0
  30. data/spec/lib/cluster/discovery_spec.rb +23 -0
  31. data/spec/spec_helper.rb +111 -0
  32. metadata +144 -0
@@ -0,0 +1,38 @@
1
+ require_relative 'discovery/ec2/tag'
2
+ require_relative 'discovery/ec2/auto_scaling'
3
+ require_relative 'discovery/consul'
4
+ require_relative 'discovery/errors'
5
+
6
+ module Cluster
7
+ module Discovery
8
+ class << self
9
+ def discover(discovery_service, *args)
10
+ Cluster::Discovery.send(discovery_service.to_sym, :discover, args)
11
+ end
12
+
13
+ def ec2_tag(action, *args)
14
+ args = args.first.first
15
+ c = Cluster::Discovery::EC2::Tag.new(aws_region: args[:aws_region])
16
+ c.send(action, aws_tags: args[:aws_tags])
17
+ end
18
+
19
+ def ec2_asg(action, *args)
20
+ args = args.first.first
21
+ c = Cluster::Discovery::EC2::AutoScaling.new(
22
+ aws_region: args[:aws_region])
23
+ c.send(action, aws_asg: args[:aws_asg])
24
+ end
25
+
26
+ def consul(action, args)
27
+ args = args.first
28
+ consul_url = args.delete(:consul_url) if args.key?(:consul_url)
29
+ if consul_url
30
+ c = Cluster::Discovery::Consul.new(consul_url: consul_url)
31
+ else
32
+ c = Cluster::Discovery::Consul.new
33
+ end
34
+ c.send(action, args)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://172.28.128.104:8500/v1/catalog/service/redis?tag=master
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ X-Consul-Index:
24
+ - '156'
25
+ X-Consul-Knownleader:
26
+ - 'true'
27
+ X-Consul-Lastcontact:
28
+ - '0'
29
+ Date:
30
+ - Tue, 19 Jan 2016 17:09:23 GMT
31
+ Content-Length:
32
+ - '499'
33
+ body:
34
+ encoding: UTF-8
35
+ string: '[{"Node":"foobar1","Address":"192.168.10.10","ServiceID":"redis1","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar5","Address":"192.168.10.14","ServiceID":"redis5","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar3","Address":"192.168.10.12","ServiceID":"redis3","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000}]'
36
+ http_version:
37
+ recorded_at: Tue, 19 Jan 2016 17:09:22 GMT
38
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://172.28.128.104:8500/v1/catalog/service/redis?tag=master
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ X-Consul-Index:
24
+ - '161'
25
+ X-Consul-Knownleader:
26
+ - 'true'
27
+ X-Consul-Lastcontact:
28
+ - '0'
29
+ Date:
30
+ - Tue, 19 Jan 2016 17:10:41 GMT
31
+ Content-Length:
32
+ - '499'
33
+ body:
34
+ encoding: UTF-8
35
+ string: '[{"Node":"foobar1","Address":"192.168.10.10","ServiceID":"redis1","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar5","Address":"192.168.10.14","ServiceID":"redis5","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar3","Address":"192.168.10.12","ServiceID":"redis3","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000}]'
36
+ http_version:
37
+ recorded_at: Tue, 19 Jan 2016 17:10:41 GMT
38
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://172.28.128.104:8500/v1/catalog/service/redis
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ X-Consul-Index:
24
+ - '161'
25
+ X-Consul-Knownleader:
26
+ - 'true'
27
+ X-Consul-Lastcontact:
28
+ - '0'
29
+ Date:
30
+ - Tue, 19 Jan 2016 17:10:41 GMT
31
+ Content-Length:
32
+ - '994'
33
+ body:
34
+ encoding: UTF-8
35
+ string: '[{"Node":"foobar1","Address":"192.168.10.10","ServiceID":"redis1","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar2","Address":"192.168.10.11","ServiceID":"redis2","ServiceName":"redis","ServiceTags":["slave","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar3","Address":"192.168.10.12","ServiceID":"redis3","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar4","Address":"192.168.10.13","ServiceID":"redis4","ServiceName":"redis","ServiceTags":["slave","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar5","Address":"192.168.10.14","ServiceID":"redis5","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar6","Address":"192.168.10.15","ServiceID":"redis6","ServiceName":"redis","ServiceTags":["slave","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000}]'
36
+ http_version:
37
+ recorded_at: Tue, 19 Jan 2016 17:10:41 GMT
38
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://172.28.128.104:8500/v1/catalog/service/redis?tag=master
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ X-Consul-Index:
24
+ - '161'
25
+ X-Consul-Knownleader:
26
+ - 'true'
27
+ X-Consul-Lastcontact:
28
+ - '0'
29
+ Date:
30
+ - Tue, 19 Jan 2016 17:10:41 GMT
31
+ Content-Length:
32
+ - '499'
33
+ body:
34
+ encoding: UTF-8
35
+ string: '[{"Node":"foobar1","Address":"192.168.10.10","ServiceID":"redis1","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar5","Address":"192.168.10.14","ServiceID":"redis5","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar3","Address":"192.168.10.12","ServiceID":"redis3","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000}]'
36
+ http_version:
37
+ recorded_at: Tue, 19 Jan 2016 17:10:41 GMT
38
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://172.28.128.104:8500/v1/catalog/service/redis
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ X-Consul-Index:
24
+ - '161'
25
+ X-Consul-Knownleader:
26
+ - 'true'
27
+ X-Consul-Lastcontact:
28
+ - '0'
29
+ Date:
30
+ - Tue, 19 Jan 2016 17:10:41 GMT
31
+ Content-Length:
32
+ - '994'
33
+ body:
34
+ encoding: UTF-8
35
+ string: '[{"Node":"foobar1","Address":"192.168.10.10","ServiceID":"redis1","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar2","Address":"192.168.10.11","ServiceID":"redis2","ServiceName":"redis","ServiceTags":["slave","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar3","Address":"192.168.10.12","ServiceID":"redis3","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar4","Address":"192.168.10.13","ServiceID":"redis4","ServiceName":"redis","ServiceTags":["slave","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar5","Address":"192.168.10.14","ServiceID":"redis5","ServiceName":"redis","ServiceTags":["master","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000},{"Node":"foobar6","Address":"192.168.10.15","ServiceID":"redis6","ServiceName":"redis","ServiceTags":["slave","v1"],"ServiceAddress":"127.0.0.1","ServicePort":8000}]'
36
+ http_version:
37
+ recorded_at: Tue, 19 Jan 2016 17:10:41 GMT
38
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,191 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://ec2.us-east-1.amazonaws.com/
6
+ body:
7
+ encoding: UTF-8
8
+ string: Action=DescribeInstances&Filter.1.Name=tag%3Aaws%3Aautoscaling%3AgroupName&Filter.1.Value.1=foo-prod-v000&Filter.2.Name=instance-state-name&Filter.2.Value.1=running&Version=2015-10-01
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded; charset=utf-8
12
+ Accept-Encoding:
13
+ - ''
14
+ User-Agent:
15
+ - aws-sdk-ruby2/2.2.9 ruby/2.1.5 x86_64-darwin12.0
16
+ X-Amz-Date:
17
+ - 20160111T214109Z
18
+ Host:
19
+ - ec2.us-east-1.amazonaws.com
20
+ X-Amz-Security-Token:
21
+ - AQoDYXdzEPb//////////wEakAOUV7KTlmOApJ5r79wLVozMAi40JMnm3xffLMY4yIL6qrzDoWRoXQidbD6FSuy9AlXS3GqTNUH9kYwdJN3OUgVxLewyqM5xeanf3a+eNscOH9gPwyy918MAREq2av7prXkiKssOOHGhXNrZdGLMHcnyjssIiXQgxwrLrVuwrnxl1OcWOniPb52GPnZcAwlubqSHxeN4XVAnhja3CwXLUqqmNCAYstlC0KSw0iO4Y9Ombe9qjMF4+PmGsa2FvSriIWjY/YOE43nWn6HSTiJsZEIymv2R8hTzQs796OdlWOEkyMBhWqii4vkiyX7iaH5ayM7LD5k7LbwZXZcD77bvBRChhI4qPLiKKTiH+MdWT6P626riRuVqheI/rudSvlsuUzq7Hs8YHfVmBdSly/pk9BDS2XhK7Z2SA2FeOxvL9q/fi9ZbiIL7cRdyr7DpVm2jcj1fodcV+11NGLqQKCvouhdeGrczK6JU+YfKWqfmN6z5ueO+0hmhJjpwH+2NdwrxXXX1kE8Sx/2bHg0U6gcuhvpTIJeo0LQF
22
+ X-Amz-Content-Sha256:
23
+ - a42fedff4ee4d1452a82db452ce5d626bd98201da7e2b11c64248b9a89a6ce08
24
+ Authorization:
25
+ - AWS4-HMAC-SHA256 Credential=ASIAJXTSTL45SLHQUIJQ/20160111/us-east-1/ec2/aws4_request,
26
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token,
27
+ Signature=1cd81e6fe08cdf8fc1e32d15ad6c3c304e3379bf62d31238685ec60d08f4804b
28
+ Content-Length:
29
+ - '183'
30
+ Accept:
31
+ - "*/*"
32
+ response:
33
+ status:
34
+ code: 200
35
+ message: OK
36
+ headers:
37
+ Content-Type:
38
+ - text/xml;charset=UTF-8
39
+ Transfer-Encoding:
40
+ - chunked
41
+ Vary:
42
+ - Accept-Encoding
43
+ Date:
44
+ - Mon, 11 Jan 2016 21:41:09 GMT
45
+ Server:
46
+ - AmazonEC2
47
+ body:
48
+ encoding: UTF-8
49
+ string: |-
50
+ <?xml version="1.0" encoding="UTF-8"?>
51
+ <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2015-10-01/">
52
+ <requestId>a2cc4a5c-504b-432f-be15-a5f803969b04</requestId>
53
+ <reservationSet>
54
+ <item>
55
+ <reservationId>r-df91310c</reservationId>
56
+ <ownerId>042293964381</ownerId>
57
+ <groupSet/>
58
+ <instancesSet>
59
+ <item>
60
+ <instanceId>i-dbfb806d</instanceId>
61
+ <imageId>ami-906569f8</imageId>
62
+ <instanceState>
63
+ <code>16</code>
64
+ <name>running</name>
65
+ </instanceState>
66
+ <privateDnsName>ip-172-31-8-125.ec2.internal</privateDnsName>
67
+ <dnsName>ec2-54-173-176-184.compute-1.amazonaws.com</dnsName>
68
+ <reason/>
69
+ <keyName>athompson</keyName>
70
+ <amiLaunchIndex>0</amiLaunchIndex>
71
+ <productCodes/>
72
+ <instanceType>m4.large</instanceType>
73
+ <launchTime>2015-12-18T20:13:22.000Z</launchTime>
74
+ <placement>
75
+ <availabilityZone>us-east-1a</availabilityZone>
76
+ <groupName/>
77
+ <tenancy>default</tenancy>
78
+ </placement>
79
+ <monitoring>
80
+ <state>enabled</state>
81
+ </monitoring>
82
+ <subnetId>subnet-57fedf20</subnetId>
83
+ <vpcId>vpc-e826368d</vpcId>
84
+ <privateIpAddress>172.31.8.125</privateIpAddress>
85
+ <ipAddress>54.173.176.184</ipAddress>
86
+ <sourceDestCheck>true</sourceDestCheck>
87
+ <groupSet>
88
+ <item>
89
+ <groupId>sg-29f80e50</groupId>
90
+ <groupName>foo</groupName>
91
+ </item>
92
+ </groupSet>
93
+ <architecture>x86_64</architecture>
94
+ <rootDeviceType>ebs</rootDeviceType>
95
+ <rootDeviceName>/dev/xvda</rootDeviceName>
96
+ <blockDeviceMapping>
97
+ <item>
98
+ <deviceName>/dev/xvda</deviceName>
99
+ <ebs>
100
+ <volumeId>vol-c59f9026</volumeId>
101
+ <status>attached</status>
102
+ <attachTime>2015-12-18T20:13:25.000Z</attachTime>
103
+ <deleteOnTermination>true</deleteOnTermination>
104
+ </ebs>
105
+ </item>
106
+ <item>
107
+ <deviceName>/dev/sdc</deviceName>
108
+ <ebs>
109
+ <volumeId>vol-0c808fef</volumeId>
110
+ <status>attached</status>
111
+ <attachTime>2015-12-18T20:13:25.000Z</attachTime>
112
+ <deleteOnTermination>true</deleteOnTermination>
113
+ </ebs>
114
+ </item>
115
+ <item>
116
+ <deviceName>/dev/sdb</deviceName>
117
+ <ebs>
118
+ <volumeId>vol-3b808fd8</volumeId>
119
+ <status>attached</status>
120
+ <attachTime>2015-12-18T20:13:25.000Z</attachTime>
121
+ <deleteOnTermination>true</deleteOnTermination>
122
+ </ebs>
123
+ </item>
124
+ </blockDeviceMapping>
125
+ <virtualizationType>hvm</virtualizationType>
126
+ <clientToken>d27bdeb2-786c-4991-a6bf-4b31f899907c_us-east-1a_1</clientToken>
127
+ <tagSet>
128
+ <item>
129
+ <key>aws:autoscaling:groupName</key>
130
+ <value>foo-prod-v000</value>
131
+ </item>
132
+ </tagSet>
133
+ <hypervisor>xen</hypervisor>
134
+ <networkInterfaceSet>
135
+ <item>
136
+ <networkInterfaceId>eni-951337d9</networkInterfaceId>
137
+ <subnetId>subnet-57fedf20</subnetId>
138
+ <vpcId>vpc-e826368d</vpcId>
139
+ <description/>
140
+ <ownerId>042293964381</ownerId>
141
+ <status>in-use</status>
142
+ <macAddress>0a:73:be:e5:02:2d</macAddress>
143
+ <privateIpAddress>172.31.8.125</privateIpAddress>
144
+ <privateDnsName>ip-172-31-8-125.ec2.internal</privateDnsName>
145
+ <sourceDestCheck>true</sourceDestCheck>
146
+ <groupSet>
147
+ <item>
148
+ <groupId>sg-29f80e50</groupId>
149
+ <groupName>foo</groupName>
150
+ </item>
151
+ </groupSet>
152
+ <attachment>
153
+ <attachmentId>eni-attach-af7a6444</attachmentId>
154
+ <deviceIndex>0</deviceIndex>
155
+ <status>attached</status>
156
+ <attachTime>2015-12-18T20:13:22.000Z</attachTime>
157
+ <deleteOnTermination>true</deleteOnTermination>
158
+ </attachment>
159
+ <association>
160
+ <publicIp>54.173.176.184</publicIp>
161
+ <publicDnsName>ec2-54-173-176-184.compute-1.amazonaws.com</publicDnsName>
162
+ <ipOwnerId>amazon</ipOwnerId>
163
+ </association>
164
+ <privateIpAddressesSet>
165
+ <item>
166
+ <privateIpAddress>172.31.8.125</privateIpAddress>
167
+ <privateDnsName>ip-172-31-8-125.ec2.internal</privateDnsName>
168
+ <primary>true</primary>
169
+ <association>
170
+ <publicIp>54.173.176.184</publicIp>
171
+ <publicDnsName>ec2-54-173-176-184.compute-1.amazonaws.com</publicDnsName>
172
+ <ipOwnerId>amazon</ipOwnerId>
173
+ </association>
174
+ </item>
175
+ </privateIpAddressesSet>
176
+ </item>
177
+ </networkInterfaceSet>
178
+ <iamInstanceProfile>
179
+ <arn>arn:aws:iam::042293964381:instance-profile/test-athompson</arn>
180
+ <id>AIPAIXKM44WHMQ4NUUINY</id>
181
+ </iamInstanceProfile>
182
+ <ebsOptimized>false</ebsOptimized>
183
+ </item>
184
+ </instancesSet>
185
+ <requesterId>226008221399</requesterId>
186
+ </item>
187
+ </reservationSet>
188
+ </DescribeInstancesResponse>
189
+ http_version:
190
+ recorded_at: Mon, 11 Jan 2016 21:41:09 GMT
191
+ recorded_with: VCR 3.0.1