Class: Diplomat::Node
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Node
- Includes:
- ApiOptions
- Defined in:
- lib/diplomat/node.rb
Overview
Methods for interacting with the Consul node API endpoint
Instance Method Summary collapse
-
#deregister(definition, path = '/v1/catalog/deregister') ⇒ Boolean
De-register a node (and all associated services and checks).
-
#get(key, options = nil) ⇒ OpenStruct
Get a node by it’s key.
-
#get_all(options = nil) ⇒ OpenStruct
Get all the nodes.
-
#register(definition, path = '/v1/catalog/register') ⇒ Boolean
Register a node.
Methods included from ApiOptions
#check_acl_token, #use_cas, #use_consistency, #valid_transaction_verbs, #valid_value_transactions
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
#deregister(definition, path = '/v1/catalog/deregister') ⇒ Boolean
De-register a node (and all associated services and checks)
50 51 52 53 54 |
# File 'lib/diplomat/node.rb', line 50 def deregister(definition, path = '/v1/catalog/deregister') deregister = @conn.put path, JSON.dump(definition) deregister.status == 200 end |
#get(key, options = nil) ⇒ OpenStruct
Get a node by it’s key
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/diplomat/node.rb', line 12 def get(key, = nil) url = ["/v1/catalog/node/#{key}"] url += check_acl_token url << use_named_parameter('dc', [:dc]) if && [:dc] # If the request fails, it's probably due to a bad path # so return a PathNotFound error. ret = @conn.get concat_url url OpenStruct.new JSON.parse(ret.body) rescue Faraday::ClientError raise Diplomat::PathNotFound end |
#get_all(options = nil) ⇒ OpenStruct
Get all the nodes
28 29 30 31 32 33 34 35 36 |
# File 'lib/diplomat/node.rb', line 28 def get_all( = nil) url = ['/v1/catalog/nodes'] url << use_named_parameter('dc', [:dc]) if && [:dc] ret = @conn.get concat_url url JSON.parse(ret.body).map { |service| OpenStruct.new service } rescue Faraday::ClientError raise Diplomat::PathNotFound end |
#register(definition, path = '/v1/catalog/register') ⇒ Boolean
Register a node
41 42 43 44 45 |
# File 'lib/diplomat/node.rb', line 41 def register(definition, path = '/v1/catalog/register') register = @conn.put path, JSON.dump(definition) register.status == 200 end |