Class: Diplomat::Node
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Node
- Defined in:
- lib/diplomat/node.rb
Overview
Methods for interacting with the Consul node API endpoint
Instance Method Summary collapse
-
#deregister(definition, options = {}) ⇒ Boolean
De-register a node (and all associated services and checks).
-
#get(key, options = {}) ⇒ OpenStruct
Get a node by it’s key.
-
#get_all(options = {}) ⇒ OpenStruct
Get all the nodes.
-
#register(definition, options = {}) ⇒ Boolean
Register a node.
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)
40 41 42 43 |
# File 'lib/diplomat/node.rb', line 40 def deregister(definition, = {}) deregister = send_put_request(@conn, ['/v1/catalog/deregister'], , definition) deregister.status == 200 end |
#get(key, options = {}) ⇒ OpenStruct
Get a node by it’s key
12 13 14 15 16 |
# File 'lib/diplomat/node.rb', line 12 def get(key, = {}) custom_params = [:dc] ? use_named_parameter('dc', [:dc]) : nil ret = send_get_request(@conn, ["/v1/catalog/node/#{key}"], , custom_params) OpenStruct.new JSON.parse(ret.body) end |
#get_all(options = {}) ⇒ OpenStruct
Get all the nodes
21 22 23 24 25 |
# File 'lib/diplomat/node.rb', line 21 def get_all( = {}) custom_params = [:dc] ? use_named_parameter('dc', [:dc]) : nil ret = send_get_request(@conn, ['/v1/catalog/nodes'], , custom_params) JSON.parse(ret.body).map { |service| OpenStruct.new service } end |
#register(definition, options = {}) ⇒ Boolean
Register a node
31 32 33 34 |
# File 'lib/diplomat/node.rb', line 31 def register(definition, = {}) register = send_put_request(@conn, ['/v1/catalog/register'], , definition) register.status == 200 end |