diplomat 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce6e11c99998e8ccde4674d2f25b1c65a7dadcb6
4
- data.tar.gz: 0ed7b4a14cedf79aed1f0856b60f8eb96744adbe
3
+ metadata.gz: a9956fd68674648c7b2644f8d08d154a367ca2e1
4
+ data.tar.gz: 74a39316e04f1134fa609670a4edb7001dcb6bf6
5
5
  SHA512:
6
- metadata.gz: dae2bbf4adfdcda941ce8d9ad5b09868dfe7abbd957122e217159fc27d15f585201edfd8de4ac570fb0e28baf284352ba9c4e4a750808b9e95b8149e074eaf80
7
- data.tar.gz: 4a5b3fb941c350acc1a2272727fb4eaefe63df2c5814bca82fd9dc0f889acf6709aa85b1fb531431d2c092b96cff766d48ae5fe392c6f6c84a8d81e659d191e8
6
+ metadata.gz: 1a836986d9eca10c7afed887e8c4b0241e2cbca3ef53c7a144f39563497ded774a754fc71ba647ab80b37dbd72de6fac0c510dc8525bd11071faae9160ede586
7
+ data.tar.gz: ae779f2691daf74d05e1d96f8a627b42e3a2939145d26f98eb5ea9ea984b142b634be65505f55cb875db46e8d90ab98daccb092140bd04db8791224d7d3d84fa
data/README.md CHANGED
@@ -131,6 +131,13 @@ services = Diplomat::Service.get_all
131
131
  # => #<OpenStruct consul=[], foo=[], bar=[]>
132
132
  ```
133
133
 
134
+ If you wish to list all the services for a specific datacenter:
135
+
136
+ ```ruby
137
+ services = Diplomat::Service.get_all({ :dc => 'My_Datacenter' })
138
+ # => #<OpenStruct consul=[], foo=[], bar=[]>
139
+ ```
140
+
134
141
  ### Datacenters
135
142
 
136
143
  Getting a list of datacenters is quite simple and gives you the option to extract all services out of
@@ -8,34 +8,75 @@ module Diplomat
8
8
 
9
9
  # Get node health
10
10
  # @param n [String] the node
11
+ # @param options [Hash] :dc string for dc specific query
11
12
  # @return [OpenStruct] all data associated with the node
12
- def node n
13
- ret = @conn.get "/v1/health/node/#{n}"
13
+ def node n, options=nil
14
+ url = ["/v1/health/node/#{n}"]
15
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
16
+
17
+ # If the request fails, it's probably due to a bad path
18
+ # so return a PathNotFound error.
19
+ begin
20
+ ret = @conn.get concat_url url
21
+ rescue Faraday::ClientError
22
+ raise Diplomat::PathNotFound
23
+ end
14
24
  return JSON.parse(ret.body)
15
25
  end
16
26
 
17
27
  # Get service checks
18
28
  # @param s [String] the service
29
+ # @param options [Hash] :dc string for dc specific query
19
30
  # @return [OpenStruct] all data associated with the node
20
- def checks s
21
- ret = @conn.get "/v1/health/checks/#{s}"
31
+ def checks s, options=nil
32
+ url = ["/v1/health/checks/#{s}"]
33
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
34
+
35
+ # If the request fails, it's probably due to a bad path
36
+ # so return a PathNotFound error.
37
+ begin
38
+ ret = @conn.get concat_url url
39
+ rescue Faraday::ClientError
40
+ raise Diplomat::PathNotFound
41
+ end
22
42
  return JSON.parse(ret.body)
23
43
  end
24
44
 
25
45
  # Get service health
26
46
  # @param s [String] the service
47
+ # @param options [Hash] :dc string for dc specific query
27
48
  # @return [OpenStruct] all data associated with the node
28
- def service s
29
- ret = @conn.get "/v1/health/service/#{s}"
49
+ def service s, options=nil
50
+ url = ["/v1/health/service/#{s}"]
51
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
52
+
53
+ # If the request fails, it's probably due to a bad path
54
+ # so return a PathNotFound error.
55
+ begin
56
+ ret = @conn.get concat_url url
57
+ rescue Faraday::ClientError
58
+ raise Diplomat::PathNotFound
59
+ end
30
60
  return JSON.parse(ret.body)
31
61
  end
32
62
 
33
63
  # Get service health
34
64
  # @param s [String] the state ("unknown", "passing", "warning", or "critical")
65
+ # @param options [Hash] :dc string for dc specific query
35
66
  # @return [OpenStruct] all data associated with the node
36
- def state s
37
- ret = @conn.get "/v1/health/state/#{s}"
38
- return JSON.parse(ret.body)
67
+ def state s, options=nil
68
+ url = ["/v1/health/state/#{s}"]
69
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
70
+
71
+ # If the request fails, it's probably due to a bad path
72
+ # so return a PathNotFound error.
73
+ begin
74
+ ret = @conn.get concat_url url
75
+ rescue Faraday::ClientError
76
+ raise Diplomat::PathNotFound
77
+ end
78
+ return JSON.parse(ret.body)
79
+
39
80
  end
40
81
 
41
82
  # Convenience method to get services in unknown state
data/lib/diplomat/kv.rb CHANGED
@@ -16,6 +16,7 @@ module Diplomat
16
16
  # @option options [String] :consistency The read consistency type
17
17
  # @option options [String] :dc Target datacenter
18
18
  # @option options [Boolean] :keys Only return key names.
19
+ # @option options [Boolean] :modify_index Only return ModifyIndex value.
19
20
  # @option options [String] :separator List only up to a given separator. Only applies when combined with :keys option.
20
21
  # @option options [Boolean] :nil_values If to return keys/dirs with nil values
21
22
  # @param not_found [Symbol] behaviour if the key doesn't exist;
@@ -71,6 +72,9 @@ module Diplomat
71
72
  when :return
72
73
  @raw = raw
73
74
  parse_body
75
+ if @options and @options[:modify_index]
76
+ return @raw.first['ModifyIndex']
77
+ end
74
78
  return return_value(return_nil_values)
75
79
  when :wait
76
80
  index = raw.headers["x-consul-index"]
@@ -136,11 +140,11 @@ module Diplomat
136
140
  def dc(options)
137
141
  if options && options[:dc] then use_named_parameter("dc", options[:dc]) else [] end
138
142
  end
139
-
143
+
140
144
  def keys(options)
141
145
  if options && options[:keys] == true then ['keys'] else [] end
142
146
  end
143
-
147
+
144
148
  def separator(options)
145
149
  if options && options[:separator] then use_named_parameter("separator", options[:separator]) else [] end
146
150
  end
@@ -3,7 +3,7 @@ require 'faraday'
3
3
 
4
4
  module Diplomat
5
5
  class Nodes < Diplomat::RestClient
6
- @access_methods = [ :get ]
6
+ @access_methods = [ :get, :get_all ]
7
7
 
8
8
  # Get all nodes
9
9
  # @deprecated Please use Diplomat::Node instead.
@@ -12,5 +12,16 @@ module Diplomat
12
12
  ret = @conn.get "/v1/catalog/nodes"
13
13
  return JSON.parse(ret.body)
14
14
  end
15
+
16
+ def get_all options=nil
17
+ url = ["/v1/catalog/nodes"]
18
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
19
+ begin
20
+ ret = @conn.get concat_url url
21
+ rescue Faraday::ClientError
22
+ raise Diplomat::PathNotFound
23
+ end
24
+ return JSON.parse(ret.body).map { |service| OpenStruct.new service }
25
+ end
15
26
  end
16
27
  end
@@ -42,11 +42,13 @@ module Diplomat
42
42
  end
43
43
 
44
44
  # Get all the services
45
+ # @param options [Hash] :dc Consul datacenter to query
45
46
  # @return [OpenStruct] the list of all services
46
- def get_all
47
- url = "/v1/catalog/services"
47
+ def get_all options=nil
48
+ url = ["/v1/catalog/services"]
49
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
48
50
  begin
49
- ret = @conn.get url
51
+ ret = @conn.get concat_url url
50
52
  rescue Faraday::ClientError
51
53
  raise Diplomat::PathNotFound
52
54
  end
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.15.0"
2
+ VERSION = "0.16.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  requirements: []
216
216
  rubyforge_project:
217
- rubygems_version: 2.4.5.1
217
+ rubygems_version: 2.5.1
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Diplomat is a simple wrapper for Consul