8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/dplyr/consul.rb', line 8
def hosts(app_name, service: "app")
uri = "http://127.0.0.1:8500/v1/catalog/service/#{service}?tag=#{app_name}"
response = JSON.parse(open(uri).read)
hosts = []
response.each do |i|
host = {}
metadata = i["ServiceMeta"]
host[:user] = metadata["user"]
host[:dir] = metadata["dir"]
host[:addr] = i["Address"]
host[:id] = i["Node"]
hosts << host
end
hosts
rescue
raise ::Dply::Error, "failed to load hosts from consul"
end
|