choria-mcorpc-support 2.20.3 → 2.20.4
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 +18 -19
- data/lib/mcollective/agent.rb +0 -1
- data/lib/mcollective/agents.rb +17 -18
- data/lib/mcollective/aggregate.rb +11 -11
- data/lib/mcollective/application.rb +30 -41
- data/lib/mcollective/applications.rb +13 -14
- data/lib/mcollective/cache.rb +1 -1
- data/lib/mcollective/client.rb +25 -25
- data/lib/mcollective/config.rb +114 -120
- data/lib/mcollective/data.rb +9 -9
- data/lib/mcollective/ddl.rb +1 -1
- data/lib/mcollective/discovery.rb +13 -13
- data/lib/mcollective/exceptions.rb +17 -17
- data/lib/mcollective/facts.rb +2 -2
- data/lib/mcollective/log.rb +7 -9
- data/lib/mcollective/matcher.rb +28 -32
- data/lib/mcollective/message.rb +31 -29
- data/lib/mcollective/monkey_patches.rb +92 -83
- data/lib/mcollective/optionparser.rb +23 -23
- data/lib/mcollective/pluginmanager.rb +8 -11
- data/lib/mcollective/pluginpackager.rb +13 -17
- data/lib/mcollective/rpc.rb +16 -18
- data/lib/mcollective/runnerstats.rb +10 -6
- data/lib/mcollective/shell.rb +30 -33
- data/lib/mcollective/ssl.rb +9 -12
- data/lib/mcollective/util.rb +160 -135
- data/lib/mcollective/validator.rb +18 -20
- metadata +4 -4
data/lib/mcollective/cache.rb
CHANGED
@@ -125,7 +125,7 @@ module MCollective
|
|
125
125
|
def self.synchronize(cache_name)
|
126
126
|
raise("No cache called '%s'" % cache_name) unless @cache.include?(cache_name)
|
127
127
|
|
128
|
-
raise
|
128
|
+
raise("No block supplied to synchronize") unless block_given?
|
129
129
|
|
130
130
|
@cache_locks[cache_name].synchronize do
|
131
131
|
yield
|
data/lib/mcollective/client.rb
CHANGED
@@ -32,7 +32,7 @@ module MCollective
|
|
32
32
|
# connection_timeout defaults to nil which means it will try forever if
|
33
33
|
# not specified
|
34
34
|
begin
|
35
|
-
Timeout
|
35
|
+
Timeout.timeout(@connection_timeout, ClientTimeoutError) do
|
36
36
|
@connection.connect
|
37
37
|
end
|
38
38
|
rescue ClientTimeoutError => e
|
@@ -41,7 +41,8 @@ module MCollective
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
@@request_sequence = 0
|
44
|
+
@@request_sequence = 0 # rubocop:disable Style/ClassVars
|
45
|
+
|
45
46
|
def self.request_sequence
|
46
47
|
@@request_sequence
|
47
48
|
end
|
@@ -64,23 +65,23 @@ module MCollective
|
|
64
65
|
|
65
66
|
# Sends a request and returns the generated request id, doesn't wait for
|
66
67
|
# responses and doesn't execute any passed in code blocks for responses
|
67
|
-
def sendreq(msg, agent, filter
|
68
|
+
def sendreq(msg, agent, filter={})
|
68
69
|
request = createreq(msg, agent, filter)
|
69
70
|
publish(request)
|
70
71
|
request.requestid
|
71
72
|
end
|
72
73
|
|
73
|
-
def createreq(msg, agent, filter
|
74
|
+
def createreq(msg, agent, filter={})
|
74
75
|
if msg.is_a?(Message)
|
75
76
|
request = msg
|
76
77
|
agent = request.agent
|
77
78
|
else
|
78
79
|
ttl = @options[:ttl] || @config.ttl
|
79
|
-
request = Message.new(msg, nil,
|
80
|
+
request = Message.new(msg, nil, :agent => agent, :type => :request, :collective => collective, :filter => filter, :ttl => ttl)
|
80
81
|
request.reply_to = @options[:reply_to] if @options[:reply_to]
|
81
82
|
end
|
82
83
|
|
83
|
-
@@request_sequence += 1
|
84
|
+
@@request_sequence += 1 # rubocop:disable Style/ClassVars
|
84
85
|
|
85
86
|
request.encode!
|
86
87
|
subscribe(agent, :reply) unless request.reply_to
|
@@ -106,13 +107,14 @@ module MCollective
|
|
106
107
|
@subscriptions.delete(agent)
|
107
108
|
end
|
108
109
|
end
|
110
|
+
|
109
111
|
# Blocking call that waits for ever for a message to arrive.
|
110
112
|
#
|
111
113
|
# If you give it a requestid this means you've previously send a request
|
112
114
|
# with that ID and now you just want replies that matches that id, in that
|
113
115
|
# case the current connection will just ignore all messages not directed at it
|
114
116
|
# and keep waiting for more till it finds a matching message.
|
115
|
-
def receive(requestid
|
117
|
+
def receive(requestid=nil)
|
116
118
|
reply = nil
|
117
119
|
|
118
120
|
begin
|
@@ -145,7 +147,7 @@ module MCollective
|
|
145
147
|
# of the discovery being cancelled soon as it reached the
|
146
148
|
# requested limit of hosts
|
147
149
|
def discover(filter, timeout, limit=0)
|
148
|
-
@discoverer.discover(filter.merge(
|
150
|
+
@discoverer.discover(filter.merge("collective" => collective), timeout, limit)
|
149
151
|
end
|
150
152
|
|
151
153
|
# Send a request, performs the passed block for each response
|
@@ -178,12 +180,12 @@ module MCollective
|
|
178
180
|
else
|
179
181
|
hosts_responded = unthreaded_req(request, publish_timeout, timeout, waitfor, &block)
|
180
182
|
end
|
181
|
-
rescue Interrupt
|
183
|
+
rescue Interrupt # rubocop:disable Lint/HandleExceptions
|
182
184
|
ensure
|
183
185
|
unsubscribe(agent, :reply)
|
184
186
|
end
|
185
187
|
|
186
|
-
|
188
|
+
update_stat(stat, hosts_responded, request.requestid)
|
187
189
|
end
|
188
190
|
|
189
191
|
# Starts the client receiver and publisher unthreaded.
|
@@ -198,7 +200,7 @@ module MCollective
|
|
198
200
|
# option is set.
|
199
201
|
def threaded_req(request, publish_timeout, timeout, waitfor, &block)
|
200
202
|
Log.debug("Starting threaded client")
|
201
|
-
|
203
|
+
Thread.new do
|
202
204
|
start_publisher(request, publish_timeout)
|
203
205
|
end
|
204
206
|
|
@@ -223,7 +225,7 @@ module MCollective
|
|
223
225
|
Timeout.timeout(publish_timeout) do
|
224
226
|
publish(request)
|
225
227
|
end
|
226
|
-
rescue Timeout::Error
|
228
|
+
rescue Timeout::Error
|
227
229
|
Log.warn("Could not publish all messages. Publishing timed out.")
|
228
230
|
end
|
229
231
|
end
|
@@ -239,7 +241,7 @@ module MCollective
|
|
239
241
|
Log.debug("Starting response receiver with timeout of #{timeout}")
|
240
242
|
hosts_responded = 0
|
241
243
|
|
242
|
-
if
|
244
|
+
if waitfor.is_a?(Array)
|
243
245
|
unfinished = Hash.new(0)
|
244
246
|
waitfor.each {|w| unfinished[w] += 1}
|
245
247
|
else
|
@@ -259,7 +261,7 @@ module MCollective
|
|
259
261
|
|
260
262
|
hosts_responded += 1
|
261
263
|
|
262
|
-
if
|
264
|
+
if waitfor.is_a?(Array)
|
263
265
|
sender = resp.payload[:senderid]
|
264
266
|
if unfinished[sender] <= 1
|
265
267
|
unfinished.delete(sender)
|
@@ -273,12 +275,12 @@ module MCollective
|
|
273
275
|
end
|
274
276
|
end
|
275
277
|
end
|
276
|
-
rescue Timeout::Error
|
278
|
+
rescue Timeout::Error
|
277
279
|
if waitfor.is_a?(Array)
|
278
|
-
|
280
|
+
unless unfinished.empty?
|
279
281
|
Log.warn("Could not receive all responses. Did not receive responses from #{unfinished.keys.join(', ')}")
|
280
282
|
end
|
281
|
-
elsif
|
283
|
+
elsif waitfor > hosts_responded
|
282
284
|
Log.warn("Could not receive all responses. Expected : #{waitfor}. Received : #{hosts_responded}")
|
283
285
|
end
|
284
286
|
end
|
@@ -303,7 +305,7 @@ module MCollective
|
|
303
305
|
|
304
306
|
# Prints out the stats returns from req and discovered_req in a nice way
|
305
307
|
def display_stats(stats, options=false, caption="stomp call summary")
|
306
|
-
options
|
308
|
+
options ||= @options
|
307
309
|
|
308
310
|
if options[:verbose]
|
309
311
|
puts("\n---- #{caption} ----")
|
@@ -319,15 +321,13 @@ module MCollective
|
|
319
321
|
printf(" Agent Time: %.2fms\n", stats[:blocktime] * 1000)
|
320
322
|
printf(" Total Time: %.2fms\n", stats[:totaltime] * 1000)
|
321
323
|
|
324
|
+
elsif stats[:discovered]
|
325
|
+
printf("\nFinished processing %d / %d hosts in %.2f ms\n\n", stats[:responses], stats[:discovered], stats[:blocktime] * 1000)
|
322
326
|
else
|
323
|
-
|
324
|
-
printf("\nFinished processing %d / %d hosts in %.2f ms\n\n", stats[:responses], stats[:discovered], stats[:blocktime] * 1000)
|
325
|
-
else
|
326
|
-
printf("\nFinished processing %d hosts in %.2f ms\n\n", stats[:responses], stats[:blocktime] * 1000)
|
327
|
-
end
|
327
|
+
printf("\nFinished processing %d hosts in %.2f ms\n\n", stats[:responses], stats[:blocktime] * 1000)
|
328
328
|
end
|
329
329
|
|
330
|
-
|
330
|
+
unless stats[:noresponsefrom].empty?
|
331
331
|
puts("\nNo response from:\n")
|
332
332
|
|
333
333
|
stats[:noresponsefrom].each do |c|
|
@@ -338,7 +338,7 @@ module MCollective
|
|
338
338
|
puts
|
339
339
|
end
|
340
340
|
|
341
|
-
|
341
|
+
unless stats[:unexpectedresponsefrom].empty?
|
342
342
|
puts("\nUnexpected response from:\n")
|
343
343
|
|
344
344
|
stats[:unexpectedresponsefrom].each do |c|
|
data/lib/mcollective/config.rb
CHANGED
@@ -7,7 +7,7 @@ module MCollective
|
|
7
7
|
|
8
8
|
attr_reader :daemonize, :pluginconf, :configured
|
9
9
|
attr_reader :logfile, :keeplogs, :max_log_size, :loglevel, :logfacility
|
10
|
-
attr_reader :identity, :
|
10
|
+
attr_reader :identity, :connector, :securityprovider, :factsource
|
11
11
|
attr_reader :registration, :registerinterval, :classesfile
|
12
12
|
attr_reader :rpcauditprovider, :rpcaudit, :configdir, :rpcauthprovider
|
13
13
|
attr_reader :rpcauthorization, :color, :configfile
|
@@ -23,134 +23,129 @@ module MCollective
|
|
23
23
|
@configured = false
|
24
24
|
end
|
25
25
|
|
26
|
-
def loadconfig(configfile)
|
26
|
+
def loadconfig(configfile) # rubocop:disable Metrics/MethodLength
|
27
27
|
set_config_defaults(configfile)
|
28
28
|
|
29
|
-
if File.
|
29
|
+
if File.exist?(configfile)
|
30
30
|
libdirs = []
|
31
31
|
File.readlines(configfile).each do |line|
|
32
|
-
|
33
32
|
# strip blank spaces, tabs etc off the end of all lines
|
34
33
|
line.gsub!(/\s*$/, "")
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
when "identity"
|
73
|
-
@identity = val
|
74
|
-
when "direct_addressing"
|
75
|
-
@direct_addressing = Util.str_to_bool(val)
|
76
|
-
when "direct_addressing_threshold"
|
77
|
-
@direct_addressing_threshold = Integer(val)
|
78
|
-
when "color"
|
79
|
-
@color = Util.str_to_bool(val)
|
80
|
-
when "daemonize"
|
81
|
-
@daemonize = Util.str_to_bool(val)
|
82
|
-
when "securityprovider"
|
83
|
-
@securityprovider = val.capitalize
|
84
|
-
when "factsource"
|
85
|
-
@factsource = val.capitalize
|
86
|
-
when "connector"
|
87
|
-
@connector = val.capitalize
|
88
|
-
when "classesfile"
|
89
|
-
@classesfile = val
|
90
|
-
when /^plugin.(.+)$/
|
91
|
-
@pluginconf[$1] = val
|
92
|
-
when "discovery_timeout"
|
93
|
-
@discovery_timeout = Integer(val)
|
94
|
-
when "publish_timeout"
|
95
|
-
@publish_timeout = Integer(val)
|
96
|
-
when "connection_timeout"
|
97
|
-
@connection_timeout = Integer(val)
|
98
|
-
when "rpcaudit"
|
99
|
-
@rpcaudit = Util.str_to_bool(val)
|
100
|
-
when "rpcauditprovider"
|
101
|
-
@rpcauditprovider = val.capitalize
|
102
|
-
when "rpcauthorization"
|
103
|
-
@rpcauthorization = Util.str_to_bool(val)
|
104
|
-
when "rpcauthprovider"
|
105
|
-
@rpcauthprovider = val.capitalize
|
106
|
-
when "rpclimitmethod"
|
107
|
-
@rpclimitmethod = val.to_sym
|
108
|
-
when "logger_type"
|
109
|
-
@logger_type = val
|
110
|
-
when "fact_cache_time"
|
111
|
-
@fact_cache_time = Integer(val)
|
112
|
-
when "ssl_cipher"
|
113
|
-
@ssl_cipher = val
|
114
|
-
when "threaded"
|
115
|
-
@threaded = Util.str_to_bool(val)
|
116
|
-
when "ttl"
|
117
|
-
@ttl = Integer(val)
|
118
|
-
when "default_discovery_options"
|
119
|
-
@default_discovery_options << val
|
120
|
-
when "default_discovery_method"
|
121
|
-
@default_discovery_method = val
|
122
|
-
when "soft_shutdown"
|
123
|
-
@soft_shutdown = Util.str_to_bool(val)
|
124
|
-
when "soft_shutdown_timeout"
|
125
|
-
@soft_shutdown_timeout = Integer(val)
|
126
|
-
when "activate_agents"
|
127
|
-
@activate_agents = Util.str_to_bool(val)
|
128
|
-
when "default_batch_size"
|
129
|
-
@default_batch_size = Integer(val)
|
130
|
-
when "default_batch_sleep_time"
|
131
|
-
@default_batch_sleep_time = Float(val)
|
132
|
-
when "topicprefix", "topicsep", "queueprefix", "rpchelptemplate", "helptemplatedir"
|
133
|
-
Log.warn("Use of deprecated '#{key}' option. This option is ignored and should be removed from '#{configfile}'")
|
134
|
-
else
|
135
|
-
raise("Unknown config parameter '#{key}'")
|
136
|
-
end
|
137
|
-
rescue ArgumentError => e
|
138
|
-
raise "Could not parse value for configuration option '#{key}' with value '#{val}'"
|
35
|
+
next if line =~ /^#|^$/
|
36
|
+
next unless line =~ /(.+?)\s*=\s*(.+)/
|
37
|
+
key = $1.strip
|
38
|
+
val = $2
|
39
|
+
|
40
|
+
begin
|
41
|
+
case key
|
42
|
+
when "registration"
|
43
|
+
@registration = val.capitalize
|
44
|
+
when "registration_collective"
|
45
|
+
@registration_collective = val
|
46
|
+
when "registerinterval"
|
47
|
+
@registerinterval = Integer(val)
|
48
|
+
when "registration_splay"
|
49
|
+
@registration_splay = Util.str_to_bool(val)
|
50
|
+
when "collectives"
|
51
|
+
@collectives = val.split(",").map(&:strip)
|
52
|
+
when "main_collective"
|
53
|
+
@main_collective = val
|
54
|
+
when "logfile"
|
55
|
+
@logfile = val
|
56
|
+
when "keeplogs"
|
57
|
+
@keeplogs = Integer(val)
|
58
|
+
when "max_log_size"
|
59
|
+
@max_log_size = Integer(val)
|
60
|
+
when "loglevel"
|
61
|
+
@loglevel = val
|
62
|
+
when "logfacility"
|
63
|
+
@logfacility = val
|
64
|
+
when "libdir"
|
65
|
+
paths = val.split(File::PATH_SEPARATOR)
|
66
|
+
paths.each do |path|
|
67
|
+
raise("libdir paths should be absolute paths but '%s' is relative" % path) unless Util.absolute_path?(path)
|
68
|
+
|
69
|
+
libdirs << path
|
139
70
|
end
|
71
|
+
when "identity"
|
72
|
+
@identity = val
|
73
|
+
when "direct_addressing"
|
74
|
+
@direct_addressing = Util.str_to_bool(val)
|
75
|
+
when "direct_addressing_threshold"
|
76
|
+
@direct_addressing_threshold = Integer(val)
|
77
|
+
when "color"
|
78
|
+
@color = Util.str_to_bool(val)
|
79
|
+
when "daemonize"
|
80
|
+
@daemonize = Util.str_to_bool(val)
|
81
|
+
when "securityprovider"
|
82
|
+
@securityprovider = val.capitalize
|
83
|
+
when "factsource"
|
84
|
+
@factsource = val.capitalize
|
85
|
+
when "connector"
|
86
|
+
@connector = val.capitalize
|
87
|
+
when "classesfile"
|
88
|
+
@classesfile = val
|
89
|
+
when /^plugin.(.+)$/
|
90
|
+
@pluginconf[$1] = val
|
91
|
+
when "discovery_timeout"
|
92
|
+
@discovery_timeout = Integer(val)
|
93
|
+
when "publish_timeout"
|
94
|
+
@publish_timeout = Integer(val)
|
95
|
+
when "connection_timeout"
|
96
|
+
@connection_timeout = Integer(val)
|
97
|
+
when "rpcaudit"
|
98
|
+
@rpcaudit = Util.str_to_bool(val)
|
99
|
+
when "rpcauditprovider"
|
100
|
+
@rpcauditprovider = val.capitalize
|
101
|
+
when "rpcauthorization"
|
102
|
+
@rpcauthorization = Util.str_to_bool(val)
|
103
|
+
when "rpcauthprovider"
|
104
|
+
@rpcauthprovider = val.capitalize
|
105
|
+
when "rpclimitmethod"
|
106
|
+
@rpclimitmethod = val.to_sym
|
107
|
+
when "logger_type"
|
108
|
+
@logger_type = val
|
109
|
+
when "fact_cache_time"
|
110
|
+
@fact_cache_time = Integer(val)
|
111
|
+
when "ssl_cipher"
|
112
|
+
@ssl_cipher = val
|
113
|
+
when "threaded"
|
114
|
+
@threaded = Util.str_to_bool(val)
|
115
|
+
when "ttl"
|
116
|
+
@ttl = Integer(val)
|
117
|
+
when "default_discovery_options"
|
118
|
+
@default_discovery_options << val
|
119
|
+
when "default_discovery_method"
|
120
|
+
@default_discovery_method = val
|
121
|
+
when "soft_shutdown"
|
122
|
+
@soft_shutdown = Util.str_to_bool(val)
|
123
|
+
when "soft_shutdown_timeout"
|
124
|
+
@soft_shutdown_timeout = Integer(val)
|
125
|
+
when "activate_agents"
|
126
|
+
@activate_agents = Util.str_to_bool(val)
|
127
|
+
when "default_batch_size"
|
128
|
+
@default_batch_size = Integer(val)
|
129
|
+
when "default_batch_sleep_time"
|
130
|
+
@default_batch_sleep_time = Float(val)
|
131
|
+
when "topicprefix", "topicsep", "queueprefix", "rpchelptemplate", "helptemplatedir"
|
132
|
+
Log.warn("Use of deprecated '#{key}' option. This option is ignored and should be removed from '#{configfile}'")
|
133
|
+
else
|
134
|
+
raise("Unknown config parameter '#{key}'")
|
140
135
|
end
|
136
|
+
rescue ArgumentError
|
137
|
+
raise("Could not parse value for configuration option '%s' with value '%s'" % [key, val])
|
141
138
|
end
|
142
139
|
end
|
143
140
|
|
144
141
|
read_plugin_config_dir("#{@configdir}/plugin.d")
|
145
142
|
|
146
|
-
raise 'Identities can only match /\w\.\-/' unless @identity
|
143
|
+
raise 'Identities can only match /\w\.\-/' unless @identity =~ /^[\w\.\-]+$/
|
147
144
|
|
148
145
|
@configured = true
|
149
146
|
|
150
147
|
libdirs.each do |dir|
|
151
|
-
unless File.directory?(dir)
|
152
|
-
Log.debug("Cannot find libdir: #{dir}")
|
153
|
-
end
|
148
|
+
Log.debug("Cannot find libdir: #{dir}") unless File.directory?(dir)
|
154
149
|
|
155
150
|
# remove the old one if it exists, we're moving it to the front
|
156
151
|
$LOAD_PATH.reject! { |elem| elem == dir }
|
@@ -172,10 +167,10 @@ module MCollective
|
|
172
167
|
end
|
173
168
|
end
|
174
169
|
|
175
|
-
def set_config_defaults(configfile)
|
176
|
-
@stomp =
|
177
|
-
@subscribe =
|
178
|
-
@pluginconf =
|
170
|
+
def set_config_defaults(configfile) # rubocop:disable Naming/AccessorMethodName
|
171
|
+
@stomp = {}
|
172
|
+
@subscribe = []
|
173
|
+
@pluginconf = {}
|
179
174
|
@connector = "base"
|
180
175
|
@securityprovider = "Base"
|
181
176
|
@factsource = "Yaml"
|
@@ -233,11 +228,10 @@ module MCollective
|
|
233
228
|
# strip blank lines
|
234
229
|
line.gsub!(/\s*$/, "")
|
235
230
|
next if line =~ /^#|^$/
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
end
|
231
|
+
next unless line =~ /(.+?)\s*=\s*(.+)/
|
232
|
+
key = $1.strip
|
233
|
+
val = $2
|
234
|
+
@pluginconf["#{plugin}.#{key}"] = val
|
241
235
|
end
|
242
236
|
end
|
243
237
|
end
|