Class: Diplomat::Node

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

Overview

Methods for interacting with the Consul node 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

#deregister(definition, options = {}) ⇒ Boolean

De-register a node (and all associated services and checks)

Parameters:

  • definition (Hash)

    Hash containing definition of a node to de-register

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

    options parameter hash

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/diplomat/node.rb', line 40

def deregister(definition, options = {})
  deregister = send_put_request(@conn, ['/v1/catalog/deregister'], options, definition)
  deregister.status == 200
end

#get(key, options = {}) ⇒ OpenStruct

Get a node by it’s key

Parameters:

  • key (String)

    the key

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

    :dc string for dc specific query

Returns:

  • (OpenStruct)

    all data associated with the node



12
13
14
15
16
# File 'lib/diplomat/node.rb', line 12

def get(key, options = {})
  custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
  ret = send_get_request(@conn, ["/v1/catalog/node/#{key}"], options, custom_params)
  OpenStruct.new JSON.parse(ret.body)
end

#get_all(options = {}) ⇒ OpenStruct

Get all the nodes

Parameters:

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

    :dc string for dc specific query

Returns:

  • (OpenStruct)

    the list of all nodes



21
22
23
24
25
# File 'lib/diplomat/node.rb', line 21

def get_all(options = {})
  custom_params = options[:dc] ? use_named_parameter('dc', options[:dc]) : nil
  ret = send_get_request(@conn, ['/v1/catalog/nodes'], options, custom_params)
  JSON.parse(ret.body).map { |service| OpenStruct.new service }
end

#register(definition, options = {}) ⇒ Boolean

Register a node

Parameters:

  • definition (Hash)

    Hash containing definition of a node to register

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

    options parameter hash

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/diplomat/node.rb', line 31

def register(definition, options = {})
  register = send_put_request(@conn, ['/v1/catalog/register'], options, definition)
  register.status == 200
end