class Diplomat::Node

Methods for interacting with the Consul node API endpoint

Public Instance Methods

deregister(definition, options = {}) click to toggle source

De-register a node (and all associated services and checks) @param definition [Hash] Hash containing definition of a node to de-register @param options [Hash] options parameter hash @return [Boolean]

# File lib/diplomat/node.rb, line 38
def deregister(definition, options = {})
  deregister = send_put_request(@conn, ['/v1/catalog/deregister'], options, definition)
  deregister.status == 200
end
get(key, options = {}) click to toggle source

Get a node by it's key @param key [String] the key @param options [Hash] :dc string for dc specific query @return [OpenStruct] all data associated with the node

# File lib/diplomat/node.rb, line 10
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 = {}) click to toggle source

Get all the nodes @param options [Hash] :dc string for dc specific query @return [OpenStruct] the list of all nodes

# File lib/diplomat/node.rb, line 19
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 = {}) click to toggle source

Register a node @param definition [Hash] Hash containing definition of a node to register @param options [Hash] options parameter hash @return [Boolean]

# File lib/diplomat/node.rb, line 29
def register(definition, options = {})
  register = send_put_request(@conn, ['/v1/catalog/register'], options, definition)
  register.status == 200
end