Class: Dplyr::Consul

Inherits:
Object
  • Object
show all
Defined in:
lib/dplyr/consul.rb

Instance Method Summary collapse

Instance Method Details

#hosts(app_name, service: "app") ⇒ Object



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 = {}
     = i["ServiceMeta"]
    host[:user] = ["user"]
    host[:dir] = ["dir"]
    host[:addr] = i["Address"]
    host[:id] = i["Node"]
    hosts << host
  end
  hosts
rescue
  raise ::Dply::Error, "failed to load hosts from consul"
end