diplomat 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/lib/diplomat.rb +1 -1
- data/lib/diplomat/event.rb +13 -8
- data/lib/diplomat/maintenance.rb +47 -0
- data/lib/diplomat/node.rb +22 -1
- data/lib/diplomat/service.rb +23 -3
- data/lib/diplomat/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ea44efec4bbbbd7dcea08226f4c1e85ee3d0c74
|
4
|
+
data.tar.gz: 686a774e0ff66b40516eb75f905a9ffb463e4317
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96a3c918192148440c80515a0e49cadd8422ead23a814c12d9e21e66907654c6d07a6dbf5e6b1a33864165644245442eb0b36ac8fb9ac8a9acbc87d10e52cfb6
|
7
|
+
data.tar.gz: 54a7dc66263f1dadb005e6ba4ef402551e5c5244d492d9f83e01d3dab27164384b865c98c451d4f25305a843542a23797b16bd32b3aea3b1cda1cb96099f79a1
|
data/README.md
CHANGED
@@ -100,6 +100,20 @@ nodes = Diplomat::Node.get_all
|
|
100
100
|
# => [#<OpenStruct Address="10.1.10.12", Node="foo">, #<OpenStruct Address="10.1.10.13", Node="bar">]
|
101
101
|
```
|
102
102
|
|
103
|
+
Register a node:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
Diplomat::Node.register({ :Node => "app1", :Address => "10.0.0.2" })
|
107
|
+
# => true
|
108
|
+
```
|
109
|
+
|
110
|
+
De-register a node:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
Diplomat::Node.deregister({ :Node => "app1", :Address => "10.0.0.2" })
|
114
|
+
# => true
|
115
|
+
```
|
116
|
+
|
103
117
|
### Services
|
104
118
|
|
105
119
|
#### Getting
|
@@ -227,6 +241,21 @@ end
|
|
227
241
|
events.each{ |e| puts e }
|
228
242
|
```
|
229
243
|
|
244
|
+
### Maintenance mode
|
245
|
+
|
246
|
+
Enable maintenance mode on a host, with optional reason and DC (requires access to local agent)
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
Diplomat::Maintenance.enable(true, 'doing stuff', :dc => 'abc')
|
250
|
+
```
|
251
|
+
|
252
|
+
Determine if a host has maintenance mode enabled
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
Diplomat::Maintenance.enabled('foobar')
|
256
|
+
# => { :enabled => true, :reason => 'doing stuff' }
|
257
|
+
```
|
258
|
+
|
230
259
|
### Custom configuration
|
231
260
|
|
232
261
|
You can create a custom configuration using the following syntax:
|
data/lib/diplomat.rb
CHANGED
@@ -23,7 +23,7 @@ module Diplomat
|
|
23
23
|
|
24
24
|
require_libs "configuration", "rest_client", "api_options", "kv", "datacenter",
|
25
25
|
"service", "members", "node", "nodes", "check", "health", "session", "lock",
|
26
|
-
"error", "event", "acl"
|
26
|
+
"error", "event", "acl", "maintenance"
|
27
27
|
self.configuration ||= Diplomat::Configuration.new
|
28
28
|
|
29
29
|
class << self
|
data/lib/diplomat/event.rb
CHANGED
@@ -2,6 +2,9 @@ require 'faraday'
|
|
2
2
|
|
3
3
|
module Diplomat
|
4
4
|
class Event < Diplomat::RestClient
|
5
|
+
|
6
|
+
include ApiOptions
|
7
|
+
|
5
8
|
@access_methods = [ :fire, :get_all, :get ]
|
6
9
|
|
7
10
|
# Send an event
|
@@ -12,14 +15,14 @@ module Diplomat
|
|
12
15
|
# @param tag [String] the target tag name, must only be used with service
|
13
16
|
# @return [nil]
|
14
17
|
def fire name, value=nil, service=nil, node=nil, tag=nil
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
url = [ "/v1/event/fire/#{name}" ]
|
19
|
+
url += check_acl_token
|
20
|
+
url += use_named_parameter("service", service)
|
21
|
+
url += use_named_parameter("node", node)
|
22
|
+
url += use_named_parameter("tag", tag) if service
|
23
|
+
url = concat_url url
|
24
|
+
|
25
|
+
@conn.put(url, value)
|
23
26
|
nil
|
24
27
|
end
|
25
28
|
|
@@ -55,6 +58,7 @@ module Diplomat
|
|
55
58
|
# - W W - get the first or next value; wait until there is an update
|
56
59
|
def get_all name=nil, not_found=:reject, found=:return
|
57
60
|
url = ["/v1/event/list"]
|
61
|
+
url += check_acl_token
|
58
62
|
url += use_named_parameter("name", name)
|
59
63
|
url = concat_url url
|
60
64
|
|
@@ -104,6 +108,7 @@ module Diplomat
|
|
104
108
|
# events (while being sure that none are missed).
|
105
109
|
def get name=nil, token=:last, not_found=:wait, found=:return
|
106
110
|
url = ["/v1/event/list"]
|
111
|
+
url += check_acl_token
|
107
112
|
url += use_named_parameter("name", name)
|
108
113
|
url = concat_url url
|
109
114
|
@raw = @conn.get url
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Diplomat
|
5
|
+
class Maintenance < Diplomat::RestClient
|
6
|
+
@access_methods = [ :enabled, :enable]
|
7
|
+
|
8
|
+
# Get the maintenance state of a host
|
9
|
+
# @param n [String] the node
|
10
|
+
# @param options [Hash] :dc string for dc specific query
|
11
|
+
# @return [Hash] { :enabled => true, :reason => 'foo' }
|
12
|
+
def enabled n, options=nil
|
13
|
+
health = Diplomat::Health.new(@conn)
|
14
|
+
result = health.node(n, options).
|
15
|
+
select { |check| check['CheckID'] == '_node_maintenance' }
|
16
|
+
|
17
|
+
if result.size > 0
|
18
|
+
{ :enabled => true, :reason => result.first['Notes'] }
|
19
|
+
else
|
20
|
+
{ :enabled => false, :reason => nil }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Enable or disable maintenance mode. This endpoint only works
|
25
|
+
# on the local agent.
|
26
|
+
# @param enable enable or disable maintenance mode
|
27
|
+
# @param reason [String] the reason for enabling maintenance mode
|
28
|
+
# @param options [Hash] :dc string for dc specific query
|
29
|
+
# @return true if call is successful
|
30
|
+
def enable enable=true, reason=nil, options=nil
|
31
|
+
raw = @conn.put do |req|
|
32
|
+
url = ["/v1/agent/maintenance"]
|
33
|
+
url << use_named_parameter('enable', enable.to_s)
|
34
|
+
url << use_named_parameter('reason', reason) unless reason.nil?
|
35
|
+
url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
|
36
|
+
req.url concat_url url
|
37
|
+
end
|
38
|
+
|
39
|
+
if raw.status == 200
|
40
|
+
@raw = raw
|
41
|
+
return true
|
42
|
+
else
|
43
|
+
raise Diplomat::UnknownStatus, "status #{raw.status}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/diplomat/node.rb
CHANGED
@@ -4,7 +4,9 @@ require 'faraday'
|
|
4
4
|
module Diplomat
|
5
5
|
class Node < Diplomat::RestClient
|
6
6
|
|
7
|
-
|
7
|
+
include ApiOptions
|
8
|
+
|
9
|
+
@access_methods = [ :get, :get_all, :register, :deregister ]
|
8
10
|
|
9
11
|
# Get a node by it's key
|
10
12
|
# @param key [String] the key
|
@@ -13,6 +15,7 @@ module Diplomat
|
|
13
15
|
def get key, options=nil
|
14
16
|
|
15
17
|
url = ["/v1/catalog/node/#{key}"]
|
18
|
+
url += check_acl_token
|
16
19
|
url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
|
17
20
|
|
18
21
|
# If the request fails, it's probably due to a bad path
|
@@ -37,5 +40,23 @@ module Diplomat
|
|
37
40
|
|
38
41
|
return JSON.parse(ret.body).map { |service| OpenStruct.new service }
|
39
42
|
end
|
43
|
+
|
44
|
+
# Register a node
|
45
|
+
# @param definition [Hash] Hash containing definition of a node to register
|
46
|
+
# @return [Boolean]
|
47
|
+
def register(definition, path='/v1/catalog/register')
|
48
|
+
register = @conn.put path, JSON.dump(definition)
|
49
|
+
|
50
|
+
return register.status == 200
|
51
|
+
end
|
52
|
+
|
53
|
+
# De-register a node (and all associated services and checks)
|
54
|
+
# @param definition [Hash] Hash containing definition of a node to de-register
|
55
|
+
# @return [Boolean]
|
56
|
+
def deregister(definition, path="/v1/catalog/deregister")
|
57
|
+
deregister = @conn.put path, JSON.dump(definition)
|
58
|
+
|
59
|
+
return deregister.status == 200
|
60
|
+
end
|
40
61
|
end
|
41
62
|
end
|
data/lib/diplomat/service.rb
CHANGED
@@ -4,7 +4,9 @@ require 'faraday'
|
|
4
4
|
module Diplomat
|
5
5
|
class Service < Diplomat::RestClient
|
6
6
|
|
7
|
-
|
7
|
+
include ApiOptions
|
8
|
+
|
9
|
+
@access_methods = [ :get, :get_all, :register, :deregister, :register_external, :deregister_external ]
|
8
10
|
|
9
11
|
# Get a service by it's key
|
10
12
|
# @param key [String] the key
|
@@ -15,6 +17,7 @@ module Diplomat
|
|
15
17
|
def get key, scope=:first, options=nil, meta=nil
|
16
18
|
|
17
19
|
url = ["/v1/catalog/service/#{key}"]
|
20
|
+
url += check_acl_token
|
18
21
|
url << use_named_parameter('wait', options[:wait]) if options and options[:wait]
|
19
22
|
url << use_named_parameter('index', options[:index]) if options and options[:index]
|
20
23
|
url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
|
@@ -46,6 +49,7 @@ module Diplomat
|
|
46
49
|
# @return [OpenStruct] the list of all services
|
47
50
|
def get_all options=nil
|
48
51
|
url = ["/v1/catalog/services"]
|
52
|
+
url += check_acl_token
|
49
53
|
url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
|
50
54
|
begin
|
51
55
|
ret = @conn.get concat_url url
|
@@ -59,9 +63,9 @@ module Diplomat
|
|
59
63
|
# Register a service
|
60
64
|
# @param definition [Hash] Hash containing definition of service
|
61
65
|
# @return [Boolean]
|
62
|
-
def register(definition)
|
66
|
+
def register(definition, path='/v1/agent/service/register')
|
63
67
|
json_definition = JSON.dump(definition)
|
64
|
-
register = @conn.put
|
68
|
+
register = @conn.put path, json_definition
|
65
69
|
return register.status == 200
|
66
70
|
end
|
67
71
|
|
@@ -72,5 +76,21 @@ module Diplomat
|
|
72
76
|
deregister = @conn.get "/v1/agent/service/deregister/#{service_name}"
|
73
77
|
return deregister.status == 200
|
74
78
|
end
|
79
|
+
|
80
|
+
# Register an external service
|
81
|
+
# @param definition [Hash] Hash containing definition of service
|
82
|
+
# @return [Boolean]
|
83
|
+
def register_external(definition)
|
84
|
+
register(definition, '/v1/catalog/register')
|
85
|
+
end
|
86
|
+
|
87
|
+
# Deregister an external service
|
88
|
+
# @param definition [Hash] Hash containing definition of service
|
89
|
+
# @return [Boolean]
|
90
|
+
def deregister_external(definition)
|
91
|
+
json_definition = JSON.dump(definition)
|
92
|
+
deregister = @conn.put '/v1/catalog/deregister', json_definition
|
93
|
+
return deregister.status == 200
|
94
|
+
end
|
75
95
|
end
|
76
96
|
end
|
data/lib/diplomat/version.rb
CHANGED
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.
|
4
|
+
version: 0.18.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: 2016-
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/diplomat/health.rb
|
188
188
|
- lib/diplomat/kv.rb
|
189
189
|
- lib/diplomat/lock.rb
|
190
|
+
- lib/diplomat/maintenance.rb
|
190
191
|
- lib/diplomat/members.rb
|
191
192
|
- lib/diplomat/node.rb
|
192
193
|
- lib/diplomat/nodes.rb
|