-
Notifications
You must be signed in to change notification settings - Fork 118
/
node.rb
41 lines (34 loc) · 1.06 KB
/
node.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'base64'
require 'faraday'
module Diplomat
class Node < Diplomat::RestClient
@access_methods = [ :get, :get_all ]
# 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
def get key, options=nil
url = ["/v1/catalog/node/#{key}"]
url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
# If the request fails, it's probably due to a bad path
# so return a PathNotFound error.
begin
ret = @conn.get concat_url url
rescue Faraday::ClientError
raise Diplomat::PathNotFound
end
return JSON.parse(ret.body)
end
# Get all the nodes
# @return [OpenStruct] the list of all nodes
def get_all
url = "/v1/catalog/nodes"
begin
ret = @conn.get url
rescue Faraday::ClientError
raise Diplomat::PathNotFound
end
return JSON.parse(ret.body).map { |service| OpenStruct.new service }
end
end
end