Class: Diplomat::Datacenter

Inherits:
RestClient show all
Defined in:
lib/diplomat/datacenter.rb

Overview

Methods for interacting with the Consul dataceneter API endpoint

Instance Method Summary collapse

Methods inherited from RestClient

access_method?, #concat_url, #configuration, #initialize, method_missing, respond_to?, respond_to_missing?, #use_named_parameter

Constructor Details

This class inherits a constructor from Diplomat::RestClient

Instance Method Details

#get(meta = nil, options = {}) ⇒ OpenStruct

Get an array of all avaliable datacenters accessible by the local consul agent

Parameters:

  • meta (Hash) (defaults to: nil)

    output structure containing header information about the request (index)

  • options (Hash) (defaults to: {})

    options parameter hash

Returns:

  • (OpenStruct)

    all datacenters avaliable to this consul agent


12
13
14
15
16
17
18
19
20
21
# File 'lib/diplomat/datacenter.rb', line 12

def get(meta = nil, options = {})
  ret = send_get_request(@conn, ['/v1/catalog/datacenters'], options)

  if meta && ret.headers
    meta[:index] = ret.headers['x-consul-index'] if ret.headers['x-consul-index']
    meta[:knownleader] = ret.headers['x-consul-knownleader'] if ret.headers['x-consul-knownleader']
    meta[:lastcontact] = ret.headers['x-consul-lastcontact'] if ret.headers['x-consul-lastcontact']
  end
  JSON.parse(ret.body)
end