choria-mcorpc-support 2.20.8 → 2.23.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mcollective.rb +1 -1
- data/lib/mcollective/agent/bolt_tasks.ddl +235 -0
- data/lib/mcollective/agent/bolt_tasks.json +347 -0
- data/lib/mcollective/agent/bolt_tasks.rb +176 -0
- data/lib/mcollective/agent/choria_util.ddl +152 -0
- data/lib/mcollective/agent/choria_util.json +244 -0
- data/lib/mcollective/agent/rpcutil.ddl +7 -3
- data/lib/mcollective/agent/rpcutil.json +333 -0
- data/lib/mcollective/agent/scout.ddl +169 -0
- data/lib/mcollective/agent/scout.json +224 -0
- data/lib/mcollective/agents.rb +7 -6
- data/lib/mcollective/aggregate.rb +4 -4
- data/lib/mcollective/aggregate/average.rb +2 -2
- data/lib/mcollective/aggregate/base.rb +2 -2
- data/lib/mcollective/aggregate/result.rb +3 -3
- data/lib/mcollective/aggregate/result/collection_result.rb +2 -2
- data/lib/mcollective/aggregate/result/numeric_result.rb +2 -2
- data/lib/mcollective/aggregate/sum.rb +2 -2
- data/lib/mcollective/aggregate/summary.rb +3 -4
- data/lib/mcollective/application.rb +57 -21
- data/lib/mcollective/application/choria.rb +249 -0
- data/lib/mcollective/application/completion.rb +6 -6
- data/lib/mcollective/application/describe_filter.rb +20 -20
- data/lib/mcollective/application/facts.rb +19 -11
- data/lib/mcollective/application/federation.rb +239 -0
- data/lib/mcollective/application/find.rb +4 -4
- data/lib/mcollective/application/help.rb +3 -3
- data/lib/mcollective/application/inventory.rb +3 -341
- data/lib/mcollective/application/ping.rb +3 -77
- data/lib/mcollective/application/playbook.rb +207 -0
- data/lib/mcollective/application/plugin.rb +106 -106
- data/lib/mcollective/application/rpc.rb +3 -108
- data/lib/mcollective/application/tasks.rb +416 -0
- data/lib/mcollective/applications.rb +11 -10
- data/lib/mcollective/audit/choria.rb +33 -0
- data/lib/mcollective/cache.rb +2 -4
- data/lib/mcollective/client.rb +11 -10
- data/lib/mcollective/config.rb +21 -34
- data/lib/mcollective/connector/base.rb +2 -1
- data/lib/mcollective/connector/nats.ddl +9 -0
- data/lib/mcollective/connector/nats.rb +450 -0
- data/lib/mcollective/data.rb +8 -3
- data/lib/mcollective/data/agent_data.rb +1 -1
- data/lib/mcollective/data/base.rb +6 -5
- data/lib/mcollective/data/bolt_task_data.ddl +90 -0
- data/lib/mcollective/data/bolt_task_data.rb +32 -0
- data/lib/mcollective/data/collective_data.rb +1 -1
- data/lib/mcollective/data/fact_data.rb +6 -6
- data/lib/mcollective/data/fstat_data.rb +2 -4
- data/lib/mcollective/data/result.rb +7 -2
- data/lib/mcollective/ddl/agentddl.rb +5 -17
- data/lib/mcollective/ddl/base.rb +11 -14
- data/lib/mcollective/discovery.rb +12 -26
- data/lib/mcollective/discovery/choria.ddl +11 -0
- data/lib/mcollective/discovery/choria.rb +223 -0
- data/lib/mcollective/discovery/flatfile.rb +7 -8
- data/lib/mcollective/discovery/mc.rb +2 -2
- data/lib/mcollective/discovery/stdin.rb +17 -18
- data/lib/mcollective/exceptions.rb +13 -0
- data/lib/mcollective/facts/base.rb +9 -9
- data/lib/mcollective/facts/yaml_facts.rb +12 -12
- data/lib/mcollective/generators.rb +3 -3
- data/lib/mcollective/generators/agent_generator.rb +3 -4
- data/lib/mcollective/generators/base.rb +14 -15
- data/lib/mcollective/generators/data_generator.rb +5 -6
- data/lib/mcollective/log.rb +2 -2
- data/lib/mcollective/logger/base.rb +3 -2
- data/lib/mcollective/logger/console_logger.rb +10 -10
- data/lib/mcollective/logger/file_logger.rb +7 -7
- data/lib/mcollective/logger/syslog_logger.rb +11 -15
- data/lib/mcollective/matcher.rb +14 -14
- data/lib/mcollective/matcher/parser.rb +31 -41
- data/lib/mcollective/matcher/scanner.rb +69 -74
- data/lib/mcollective/message.rb +10 -17
- data/lib/mcollective/monkey_patches.rb +2 -4
- data/lib/mcollective/optionparser.rb +1 -0
- data/lib/mcollective/pluginmanager.rb +3 -5
- data/lib/mcollective/pluginpackager.rb +1 -3
- data/lib/mcollective/pluginpackager/agent_definition.rb +10 -11
- data/lib/mcollective/pluginpackager/forge_packager.rb +7 -9
- data/lib/mcollective/pluginpackager/standard_definition.rb +1 -2
- data/lib/mcollective/registration/base.rb +18 -16
- data/lib/mcollective/rpc.rb +2 -4
- data/lib/mcollective/rpc/actionrunner.rb +16 -18
- data/lib/mcollective/rpc/agent.rb +26 -43
- data/lib/mcollective/rpc/audit.rb +1 -0
- data/lib/mcollective/rpc/client.rb +67 -85
- data/lib/mcollective/rpc/helpers.rb +55 -62
- data/lib/mcollective/rpc/progress.rb +2 -2
- data/lib/mcollective/rpc/reply.rb +17 -19
- data/lib/mcollective/rpc/request.rb +7 -5
- data/lib/mcollective/rpc/result.rb +6 -8
- data/lib/mcollective/rpc/stats.rb +49 -58
- data/lib/mcollective/security/base.rb +29 -36
- data/lib/mcollective/security/choria.rb +765 -0
- data/lib/mcollective/shell.rb +9 -4
- data/lib/mcollective/signer/base.rb +28 -0
- data/lib/mcollective/signer/choria.rb +185 -0
- data/lib/mcollective/ssl.rb +8 -6
- data/lib/mcollective/util.rb +58 -55
- data/lib/mcollective/util/bolt_support.rb +176 -0
- data/lib/mcollective/util/bolt_support/plan_runner.rb +167 -0
- data/lib/mcollective/util/bolt_support/task_result.rb +94 -0
- data/lib/mcollective/util/bolt_support/task_results.rb +128 -0
- data/lib/mcollective/util/choria.rb +1103 -0
- data/lib/mcollective/util/indifferent_hash.rb +12 -0
- data/lib/mcollective/util/natswrapper.rb +242 -0
- data/lib/mcollective/util/playbook.rb +435 -0
- data/lib/mcollective/util/playbook/data_stores.rb +201 -0
- data/lib/mcollective/util/playbook/data_stores/base.rb +99 -0
- data/lib/mcollective/util/playbook/data_stores/consul_data_store.rb +88 -0
- data/lib/mcollective/util/playbook/data_stores/environment_data_store.rb +33 -0
- data/lib/mcollective/util/playbook/data_stores/etcd_data_store.rb +42 -0
- data/lib/mcollective/util/playbook/data_stores/file_data_store.rb +106 -0
- data/lib/mcollective/util/playbook/data_stores/shell_data_store.rb +103 -0
- data/lib/mcollective/util/playbook/inputs.rb +265 -0
- data/lib/mcollective/util/playbook/nodes.rb +207 -0
- data/lib/mcollective/util/playbook/nodes/mcollective_nodes.rb +86 -0
- data/lib/mcollective/util/playbook/nodes/pql_nodes.rb +40 -0
- data/lib/mcollective/util/playbook/nodes/shell_nodes.rb +55 -0
- data/lib/mcollective/util/playbook/nodes/terraform_nodes.rb +65 -0
- data/lib/mcollective/util/playbook/nodes/yaml_nodes.rb +47 -0
- data/lib/mcollective/util/playbook/playbook_logger.rb +47 -0
- data/lib/mcollective/util/playbook/puppet_logger.rb +51 -0
- data/lib/mcollective/util/playbook/report.rb +152 -0
- data/lib/mcollective/util/playbook/task_result.rb +55 -0
- data/lib/mcollective/util/playbook/tasks.rb +196 -0
- data/lib/mcollective/util/playbook/tasks/base.rb +45 -0
- data/lib/mcollective/util/playbook/tasks/graphite_event_task.rb +64 -0
- data/lib/mcollective/util/playbook/tasks/mcollective_task.rb +356 -0
- data/lib/mcollective/util/playbook/tasks/shell_task.rb +93 -0
- data/lib/mcollective/util/playbook/tasks/slack_task.rb +105 -0
- data/lib/mcollective/util/playbook/tasks/webhook_task.rb +136 -0
- data/lib/mcollective/util/playbook/template_util.rb +98 -0
- data/lib/mcollective/util/playbook/uses.rb +169 -0
- data/lib/mcollective/util/tasks_support.rb +733 -0
- data/lib/mcollective/util/tasks_support/cli.rb +260 -0
- data/lib/mcollective/util/tasks_support/default_formatter.rb +138 -0
- data/lib/mcollective/util/tasks_support/json_formatter.rb +108 -0
- data/lib/mcollective/validator.rb +8 -3
- data/lib/mcollective/validator/bolt_task_name_validator.ddl +7 -0
- data/lib/mcollective/validator/bolt_task_name_validator.rb +11 -0
- data/lib/mcollective/validator/length_validator.rb +1 -3
- data/lib/mcollective/validator/typecheck_validator.rb +4 -0
- metadata +67 -4
@@ -0,0 +1,201 @@
|
|
1
|
+
require_relative "data_stores/base"
|
2
|
+
require_relative "data_stores/consul_data_store"
|
3
|
+
require_relative "data_stores/environment_data_store"
|
4
|
+
require_relative "data_stores/etcd_data_store"
|
5
|
+
require_relative "data_stores/file_data_store"
|
6
|
+
require_relative "data_stores/shell_data_store"
|
7
|
+
|
8
|
+
module MCollective
|
9
|
+
module Util
|
10
|
+
class Playbook
|
11
|
+
class DataStores
|
12
|
+
def initialize(playbook)
|
13
|
+
@playbook = playbook
|
14
|
+
@stores = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Determines if a path is in the valid form and a known store
|
18
|
+
#
|
19
|
+
# @param path [String] example data_store/key_name
|
20
|
+
# @return [Boolean]
|
21
|
+
def valid_path?(path)
|
22
|
+
store, _ = parse_path(path)
|
23
|
+
include?(store)
|
24
|
+
rescue
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
# Parse a normal format data path
|
29
|
+
#
|
30
|
+
# @param path [String] example data_store/key_name
|
31
|
+
# @return [String, String] store name and key name
|
32
|
+
# @raise [StandardError] for incorrectly formatted paths
|
33
|
+
def parse_path(path)
|
34
|
+
if path =~ /^([a-zA-Z0-9\-_]+)\/(.+)$/
|
35
|
+
[$1, $2]
|
36
|
+
else
|
37
|
+
raise("Invalid data store path %s" % [path])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Reads from a path
|
42
|
+
#
|
43
|
+
# @param path [String] example data_store/key_name
|
44
|
+
# @return [Object] data from the data store
|
45
|
+
# @raise [StandardError] when reading from the key fails
|
46
|
+
# @raise [StandardError] for unknown stores
|
47
|
+
def read(path)
|
48
|
+
store, key = parse_path(path)
|
49
|
+
|
50
|
+
Log.debug("Reading key %s from data store %s" % [key, store])
|
51
|
+
|
52
|
+
self[store].read(key)
|
53
|
+
rescue
|
54
|
+
raise("Could not read key %s: %s: %s" % [path, $!.class, $!.to_s])
|
55
|
+
end
|
56
|
+
|
57
|
+
# Writes to a path
|
58
|
+
#
|
59
|
+
# @param path [String] example data_store/key_name
|
60
|
+
# @param value [Object] data to write to the path
|
61
|
+
# @raise [StandardError] when reading from the key fails
|
62
|
+
# @raise [StandardError] for unknown stores
|
63
|
+
def write(path, value)
|
64
|
+
store, key = parse_path(path)
|
65
|
+
|
66
|
+
Log.debug("Storing data in key %s within data store %s" % [key, store])
|
67
|
+
self[store].write(key, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Deletes a path
|
71
|
+
#
|
72
|
+
# @param path [String] example data_store/key_name
|
73
|
+
# @raise [StandardError] when reading from the key fails
|
74
|
+
# @raise [StandardError] for unknown stores
|
75
|
+
def delete(path)
|
76
|
+
store, key = parse_path(path)
|
77
|
+
|
78
|
+
Log.debug("Deleting key %s from data store %s" % [key, store])
|
79
|
+
self[store].delete(key)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Members registered in a service
|
83
|
+
#
|
84
|
+
# @param path [String] example data_store/key_name
|
85
|
+
# @return [Array<String>]
|
86
|
+
# @raise [StandardError] when reading from the key fails
|
87
|
+
# @raise [StandardError] for unknown stores
|
88
|
+
def members(path)
|
89
|
+
store, service = parse_path(path)
|
90
|
+
|
91
|
+
Log.debug("Retrieving service members for service %s from data store %s" % [service, store])
|
92
|
+
self[store].members(service)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Attempts to lock a named semaphore, waits until it succeeds
|
96
|
+
#
|
97
|
+
# @param path [String] example data_store/key_name
|
98
|
+
# @raise [StandardError] when obtaining a lock fails
|
99
|
+
# @raise [StandardError] when obtaining a lock timesout
|
100
|
+
# @raise [StandardError] for unknown stores
|
101
|
+
def lock(path)
|
102
|
+
store, key = parse_path(path)
|
103
|
+
timeout = lock_timeout(store)
|
104
|
+
|
105
|
+
Log.debug("Obtaining lock %s on data store %s with timeout %d" % [key, store, timeout])
|
106
|
+
|
107
|
+
self[store].lock(key, timeout)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Attempts to unlock a named semaphore
|
111
|
+
#
|
112
|
+
# @param path [String] example data_store/key_name
|
113
|
+
# @raise [StandardError] when reading from the key fails
|
114
|
+
# @raise [StandardError] for unknown stores
|
115
|
+
def release(path)
|
116
|
+
store, key = parse_path(path)
|
117
|
+
|
118
|
+
Log.debug("Releasing lock %s on data store %s" % [key, store])
|
119
|
+
|
120
|
+
self[store].release(key)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Retrieves the configured lock timeout for a store
|
124
|
+
#
|
125
|
+
# @param store [String]
|
126
|
+
# @return [Integer]
|
127
|
+
def lock_timeout(store)
|
128
|
+
raise("Unknown data store %s" % store) unless include?(store)
|
129
|
+
|
130
|
+
@stores[store][:lock_timeout]
|
131
|
+
end
|
132
|
+
|
133
|
+
# Finds a named store instance
|
134
|
+
#
|
135
|
+
# @param store [String] a store name
|
136
|
+
# @raise [StandardError] for unknown stores
|
137
|
+
def [](store)
|
138
|
+
raise("Unknown data store %s" % store) unless include?(store)
|
139
|
+
|
140
|
+
@stores[store][:store]
|
141
|
+
end
|
142
|
+
|
143
|
+
# List of known store names
|
144
|
+
#
|
145
|
+
# @return [Array<String>]
|
146
|
+
def keys
|
147
|
+
@stores.keys
|
148
|
+
end
|
149
|
+
|
150
|
+
# Determines if a store is known
|
151
|
+
#
|
152
|
+
# @return [Boolean]
|
153
|
+
def include?(store)
|
154
|
+
@stores.include?(store)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Prepares all the stores
|
158
|
+
def prepare
|
159
|
+
@stores.each_value do |properties|
|
160
|
+
properties[:store].from_hash(properties[:properties]).prepare
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# Creates a store instance for a given type
|
165
|
+
#
|
166
|
+
# @param name [String] the store instance name
|
167
|
+
# @param type [String] store type
|
168
|
+
# @return [DataStores::Base] data store instance
|
169
|
+
# @raise [NameError] for unknown types
|
170
|
+
def store_for(name, type)
|
171
|
+
klass_name = "%sDataStore" % type.capitalize
|
172
|
+
|
173
|
+
DataStores.const_get(klass_name).new(name, @playbook)
|
174
|
+
rescue NameError
|
175
|
+
raise("Cannot find a handler for Data Store type %s" % type)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Initialize the data stores from playbook data
|
179
|
+
#
|
180
|
+
# @param data [Hash] playbook format data
|
181
|
+
# @return [DataStores]
|
182
|
+
def from_hash(data)
|
183
|
+
@stores.clear
|
184
|
+
|
185
|
+
data.each do |store, props|
|
186
|
+
Log.debug("Loading data store %s" % [store])
|
187
|
+
|
188
|
+
@stores[store] = {
|
189
|
+
:properties => props,
|
190
|
+
:type => props["type"],
|
191
|
+
:lock_timeout => Integer(props.fetch("timeout", 120)),
|
192
|
+
:store => store_for(store, props["type"])
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
196
|
+
self
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module MCollective
|
2
|
+
module Util
|
3
|
+
class Playbook
|
4
|
+
class DataStores
|
5
|
+
class Base
|
6
|
+
def initialize(name, playbook)
|
7
|
+
@playbook = playbook
|
8
|
+
@name = name
|
9
|
+
|
10
|
+
startup_hook
|
11
|
+
end
|
12
|
+
|
13
|
+
# Start up processing
|
14
|
+
#
|
15
|
+
# Implementations should not create a {initialize} instead they should
|
16
|
+
# have this hook which will be called once initialization is done
|
17
|
+
def startup_hook; end
|
18
|
+
|
19
|
+
# Prepares the store for use
|
20
|
+
#
|
21
|
+
# Here you can do things like connect to data bases, set up pools etc
|
22
|
+
def prepare; end
|
23
|
+
|
24
|
+
# Validate store properties created using from_hash
|
25
|
+
#
|
26
|
+
# @raise [StandardError] when configuration is invalid
|
27
|
+
def validate_configuration!; end
|
28
|
+
|
29
|
+
# Parse the data store properties as supplied by the playbook
|
30
|
+
#
|
31
|
+
# @param properties [Hash] lock properties
|
32
|
+
# @return [Base]
|
33
|
+
def from_hash(properties)
|
34
|
+
@properties = properties
|
35
|
+
|
36
|
+
validate_configuration!
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Release a lock found in the store
|
42
|
+
#
|
43
|
+
# @note when the lock does not exist it should not raise an error
|
44
|
+
# @param key [String] the lock name
|
45
|
+
# @raise [StandardError] when releaging fails
|
46
|
+
def release(key)
|
47
|
+
raise(StandardError, "release not implemented in %s" % [self.class], caller)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Locks a specific lock in the store
|
51
|
+
#
|
52
|
+
# @note when the lock does not exist it should be created
|
53
|
+
# @param key [String] the lock name
|
54
|
+
# @param timeout [Integer,Float] how long to attempt to get the lock for
|
55
|
+
# @raise [StandardError] when locking fails
|
56
|
+
def lock(key, timeout)
|
57
|
+
raise(StandardError, "lock not implemented in %s" % [self.class], caller)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Finds the members in a service
|
61
|
+
#
|
62
|
+
# @param key [String] the service name
|
63
|
+
# @return [Array<String>] list of service members
|
64
|
+
# @raise [StandardError] when the service is unknown or general error happened
|
65
|
+
def members(key)
|
66
|
+
raise(StandardError, "members not implemented in %s" % [self.class], caller)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Deletes a key from a data store
|
70
|
+
#
|
71
|
+
# @note deleting non existing data should not raise an error
|
72
|
+
# @param key [String] the key to delete
|
73
|
+
# @raise [StandardError] when deleting fails
|
74
|
+
def delete(key)
|
75
|
+
raise(StandardError, "delete not implemented in %s" % [self.class], caller)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Writes a value to the key in a data store
|
79
|
+
#
|
80
|
+
# @param key [String] the key to write
|
81
|
+
# @param value [String] the value to write
|
82
|
+
# @raise [StandardError] when writing fails
|
83
|
+
def write(key, value)
|
84
|
+
raise(StandardError, "write not implemented in %s" % [self.class], caller)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Reads a key from a data store
|
88
|
+
#
|
89
|
+
# @param key [String] the key to read
|
90
|
+
# @return [String] string found in the data store
|
91
|
+
# @raise [StandardError] when the key does not exist
|
92
|
+
def read(key)
|
93
|
+
raise(StandardError, "read not implemented in %s" % [self.class], caller)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module MCollective
|
2
|
+
module Util
|
3
|
+
class Playbook
|
4
|
+
class DataStores
|
5
|
+
class ConsulDataStore < Base
|
6
|
+
def startup_hook
|
7
|
+
require "diplomat"
|
8
|
+
|
9
|
+
@session_mutex = Mutex.new
|
10
|
+
@session_manager = nil
|
11
|
+
@session_id = nil
|
12
|
+
rescue LoadError
|
13
|
+
raise("Consul Data Store is not functional. Please install the diplomat Gem.")
|
14
|
+
end
|
15
|
+
|
16
|
+
def lock(key, timeout)
|
17
|
+
Timeout.timeout(timeout) do
|
18
|
+
Diplomat::Lock.wait_to_acquire(key, session, nil, 2)
|
19
|
+
end
|
20
|
+
rescue Timeout::Error
|
21
|
+
raise("Failed to obtain lock %s after %d seconds" % [key, timeout])
|
22
|
+
end
|
23
|
+
|
24
|
+
def release(key)
|
25
|
+
Diplomat::Lock.release(key, session)
|
26
|
+
end
|
27
|
+
|
28
|
+
def read(key)
|
29
|
+
Diplomat::Kv.get(key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def write(key, value)
|
33
|
+
Diplomat::Kv.put(key, value)
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete(key)
|
37
|
+
Diplomat::Kv.delete(key)
|
38
|
+
end
|
39
|
+
|
40
|
+
def ttl
|
41
|
+
supplied = Integer(@properties.fetch("ttl", 10)).abs
|
42
|
+
|
43
|
+
supplied < 10 ? 10 : supplied
|
44
|
+
end
|
45
|
+
|
46
|
+
def renew_session
|
47
|
+
if @session_id
|
48
|
+
Log.debug("Renewing Consul session %s" % [@session_id])
|
49
|
+
Diplomat::Session.renew(@session_id)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def start_session_manager
|
54
|
+
@session_manager = Thread.new do
|
55
|
+
begin
|
56
|
+
loop do
|
57
|
+
renew_session
|
58
|
+
|
59
|
+
sleep(ttl - 5)
|
60
|
+
end
|
61
|
+
rescue
|
62
|
+
Log.warn("Session manager for Consul data store %s failed: %s: %s" % [@name, $!.class, $!.to_s])
|
63
|
+
|
64
|
+
sleep(1)
|
65
|
+
|
66
|
+
retry
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def session
|
72
|
+
@session_mutex.synchronize do
|
73
|
+
return @session_id if @session_id
|
74
|
+
|
75
|
+
ttl_spec = "%ss" % ttl
|
76
|
+
|
77
|
+
@session_id ||= Diplomat::Session.create("TTL" => ttl_spec, "Behavior" => "delete")
|
78
|
+
|
79
|
+
start_session_manager
|
80
|
+
|
81
|
+
@session_id
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module MCollective
|
4
|
+
module Util
|
5
|
+
class Playbook
|
6
|
+
class DataStores
|
7
|
+
class EnvironmentDataStore < Base
|
8
|
+
def read(key)
|
9
|
+
raise("No such environment variable %s" % [key_for(key)]) unless include?(key)
|
10
|
+
|
11
|
+
ENV[key_for(key)]
|
12
|
+
end
|
13
|
+
|
14
|
+
def write(key, value)
|
15
|
+
ENV[key_for(key)] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(key)
|
19
|
+
ENV.delete(key_for(key))
|
20
|
+
end
|
21
|
+
|
22
|
+
def key_for(key)
|
23
|
+
"%s%s" % [@properties["prefix"], key]
|
24
|
+
end
|
25
|
+
|
26
|
+
def include?(key)
|
27
|
+
ENV.include?(key_for(key))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MCollective
|
2
|
+
module Util
|
3
|
+
class Playbook
|
4
|
+
class DataStores
|
5
|
+
class EtcdDataStore < Base
|
6
|
+
def startup_hook
|
7
|
+
require "etcdv3"
|
8
|
+
rescue LoadError
|
9
|
+
raise("Etcd Data Store is not functional. Please install the etcdv3 Gem.")
|
10
|
+
end
|
11
|
+
|
12
|
+
def conn
|
13
|
+
return @_conn if @_conn
|
14
|
+
|
15
|
+
opts = {}
|
16
|
+
opts[:url] = @properties.fetch("url", "http://127.0.0.1:2379")
|
17
|
+
opts[:user] = @properties["user"] if @properties["user"]
|
18
|
+
opts[:password] = @properties["password"] if @properties["password"]
|
19
|
+
|
20
|
+
@_conn = Etcdv3.new(opts)
|
21
|
+
end
|
22
|
+
|
23
|
+
def read(key)
|
24
|
+
result = conn.get(key)
|
25
|
+
|
26
|
+
raise("Could not find key %s" % key) if !result || result.kvs.empty?
|
27
|
+
|
28
|
+
result.kvs[0].value
|
29
|
+
end
|
30
|
+
|
31
|
+
def write(key, value)
|
32
|
+
conn.put(key, value)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(key)
|
36
|
+
conn.del(key)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|