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, #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) ⇒ 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)

Returns:

  • (OpenStruct)

    all datacenters avaliable to this consul agent



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

def get(meta = nil)
  url = ['/v1/catalog/datacenters']

  ret = @conn.get concat_url url

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