class Consul::Client::Status

Public Instance Methods

build_url(suffix) click to toggle source
# File lib/consul/client/status.rb, line 34
def build_url(suffix)
  "#{base_versioned_url}/status/#{suffix}"
end
leader() click to toggle source

Public: This endpoint is used to get the Raft leader for the datacenter in which the agent is running

Reference: www.consul.io/docs/agent/http/status.html

Returns: Address, host:port.

# File lib/consul/client/status.rb, line 14
def leader
  resp = RestClient.get leader_url
  return resp.body.slice(1, resp.body.length-2) if resp.code == 200
  logger.warn("Unable to get leader. Resp code: #{resp.code} Resp message: #{resp.body}")
  nil
end
peers() click to toggle source

Public: This endpoint retrieves the Raft peers for the datacenter in which the the agent is running

Reference: www.consul.io/docs/agent/http/status.html

Returns: List of addresses.

# File lib/consul/client/status.rb, line 27
def peers
  resp = RestClient.get peers_url
  return JSON.parse(resp.body) if resp.code == 200
  logger.warn("Unable to get peers. Resp code: #{resp.code} Resp message: #{resp.body}")
  nil
end

Private Instance Methods

leader_url() click to toggle source
# File lib/consul/client/status.rb, line 44
def leader_url
  build_url('leader')
end
peers_url() click to toggle source
# File lib/consul/client/status.rb, line 40
def peers_url
  build_url('peers')
end