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
@@ -40,7 +40,7 @@ module MCollective
|
|
40
40
|
|
41
41
|
puts("Completed building module for %s" % module_name)
|
42
42
|
rescue
|
43
|
-
|
43
|
+
warn("Failed to build plugin module: %s: %s" % [$!.class, $!.to_s])
|
44
44
|
ensure
|
45
45
|
if @keep_artifacts
|
46
46
|
puts("Keeping build artifacts")
|
@@ -191,12 +191,12 @@ module MCollective
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def render_template(infile, outfile)
|
194
|
-
erb = ERB.new(File.read(infile),
|
194
|
+
erb = ERB.new(File.read(infile), 0, "%")
|
195
195
|
File.open(outfile, "w") do |f|
|
196
196
|
f.puts erb.result(binding)
|
197
197
|
end
|
198
198
|
rescue
|
199
|
-
|
199
|
+
warn("Could not render template %s to %s" % [infile, outfile])
|
200
200
|
raise
|
201
201
|
end
|
202
202
|
|
@@ -218,9 +218,7 @@ module MCollective
|
|
218
218
|
actual_version = s.stdout.chomp
|
219
219
|
required_version = "1.12.0"
|
220
220
|
|
221
|
-
if Util.versioncmp(actual_version, required_version) < 0
|
222
|
-
raise("Cannot build package. pdk #{required_version} or greater required. We have #{actual_version}.")
|
223
|
-
end
|
221
|
+
raise("Cannot build package. pdk #{required_version} or greater required. We have #{actual_version}.") if Util.versioncmp(actual_version, required_version) < 0
|
224
222
|
end
|
225
223
|
|
226
224
|
def run_build
|
@@ -230,7 +228,7 @@ module MCollective
|
|
230
228
|
end
|
231
229
|
end
|
232
230
|
rescue
|
233
|
-
|
231
|
+
warn("Build process has failed")
|
234
232
|
raise
|
235
233
|
end
|
236
234
|
|
@@ -238,14 +236,14 @@ module MCollective
|
|
238
236
|
package_file = File.join(@tmpdir, "pkg", module_file_name)
|
239
237
|
FileUtils.cp(package_file, ".")
|
240
238
|
rescue
|
241
|
-
|
239
|
+
warn("Could not copy package to working directory")
|
242
240
|
raise
|
243
241
|
end
|
244
242
|
|
245
243
|
def cleanup_tmpdirs
|
246
244
|
FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
|
247
245
|
rescue
|
248
|
-
|
246
|
+
warn("Could not remove temporary build directory %s" % [@tmpdir])
|
249
247
|
raise
|
250
248
|
end
|
251
249
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module MCollective
|
2
2
|
module PluginPackager
|
3
3
|
class StandardDefinition
|
4
|
-
attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :revision
|
5
|
-
attr_accessor :plugintype, :preinstall, :postinstall, :dependencies, :mcname, :mcversion
|
4
|
+
attr_accessor :path, :packagedata, :metadata, :target_path, :vendor, :revision, :plugintype, :preinstall, :postinstall, :dependencies, :mcname, :mcversion
|
6
5
|
|
7
6
|
def initialize(configuration, mcdependency, plugintype)
|
8
7
|
@plugintype = plugintype
|
@@ -10,6 +10,7 @@ module MCollective
|
|
10
10
|
# Register plugins that inherits base
|
11
11
|
def self.inherited(klass)
|
12
12
|
PluginManager << {:type => "registration_plugin", :class => klass.to_s}
|
13
|
+
super
|
13
14
|
end
|
14
15
|
|
15
16
|
# Creates a background thread that periodically send a registration notice.
|
@@ -44,7 +45,7 @@ module MCollective
|
|
44
45
|
collective = main_collective
|
45
46
|
end
|
46
47
|
|
47
|
-
|
48
|
+
collective
|
48
49
|
end
|
49
50
|
|
50
51
|
def interval
|
@@ -52,15 +53,15 @@ module MCollective
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def publish(message)
|
55
|
-
|
56
|
-
Log.debug("Skipping registration due to nil body")
|
57
|
-
else
|
56
|
+
if message
|
58
57
|
req = Message.new(message, nil, {:type => :request, :agent => "registration", :collective => target_collective, :filter => msg_filter})
|
59
58
|
req.encode!
|
60
59
|
|
61
60
|
Log.debug("Sending registration #{req.requestid} to collective #{req.collective}")
|
62
61
|
|
63
62
|
req.publish
|
63
|
+
else
|
64
|
+
Log.debug("Skipping registration due to nil body")
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
@@ -69,22 +70,23 @@ module MCollective
|
|
69
70
|
end
|
70
71
|
|
71
72
|
private
|
73
|
+
|
72
74
|
def publish_thread(connnection)
|
73
75
|
if config.registration_splay
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
splay_delay = rand(interval)
|
77
|
+
Log.debug("registration_splay enabled. Registration will start in #{splay_delay} seconds")
|
78
|
+
sleep splay_delay
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
81
|
+
loop do
|
82
|
+
begin
|
83
|
+
publish(body)
|
84
|
+
sleep interval
|
85
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
86
|
+
Log.error("Sending registration message failed: #{e}")
|
87
|
+
sleep interval
|
87
88
|
end
|
89
|
+
end
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
data/lib/mcollective/rpc.rb
CHANGED
@@ -21,13 +21,11 @@ module MCollective
|
|
21
21
|
def rpcoptions
|
22
22
|
oparser = MCollective::Optionparser.new({:verbose => false, :progress_bar => true}, "filter")
|
23
23
|
|
24
|
-
|
24
|
+
oparser.parse do |parser, opts|
|
25
25
|
yield(parser, opts) if block_given?
|
26
26
|
|
27
27
|
Helpers.add_simplerpc_options(parser, opts)
|
28
28
|
end
|
29
|
-
|
30
|
-
options
|
31
29
|
end
|
32
30
|
|
33
31
|
# Wrapper to create clients, supposed to be used as
|
@@ -86,7 +84,7 @@ module MCollective
|
|
86
84
|
if block_given?
|
87
85
|
yield(rpc)
|
88
86
|
else
|
89
|
-
|
87
|
+
rpc
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
@@ -35,11 +35,11 @@ module MCollective
|
|
35
35
|
|
36
36
|
def run
|
37
37
|
unless canrun?(command)
|
38
|
-
Log.warn("Cannot run #{
|
39
|
-
raise RPCAborted, "Cannot execute #{
|
38
|
+
Log.warn("Cannot run #{self}")
|
39
|
+
raise RPCAborted, "Cannot execute #{self}"
|
40
40
|
end
|
41
41
|
|
42
|
-
Log.debug("Running #{
|
42
|
+
Log.debug("Running #{self}")
|
43
43
|
|
44
44
|
request_file = saverequest(request)
|
45
45
|
reply_file = tempfile("reply")
|
@@ -51,13 +51,13 @@ module MCollective
|
|
51
51
|
|
52
52
|
Log.debug("#{command} exited with #{runner.status.exitstatus}")
|
53
53
|
|
54
|
-
stderr.each_line {|l| Log.error("#{
|
55
|
-
stdout.each_line {|l| Log.info("#{
|
54
|
+
stderr.each_line {|l| Log.error("#{self}: #{l.chomp}")} unless stderr.empty?
|
55
|
+
stdout.each_line {|l| Log.info("#{self}: #{l.chomp}")} unless stdout.empty?
|
56
56
|
|
57
57
|
{:exitstatus => runner.status.exitstatus,
|
58
|
-
:stdout
|
59
|
-
:stderr
|
60
|
-
:data
|
58
|
+
:stdout => runner.stdout,
|
59
|
+
:stderr => runner.stderr,
|
60
|
+
:data => load_results(reply_file.path)}
|
61
61
|
ensure
|
62
62
|
request_file.close! if request_file.respond_to?("close!")
|
63
63
|
reply_file.close! if reply_file.respond_to?("close")
|
@@ -65,7 +65,7 @@ module MCollective
|
|
65
65
|
|
66
66
|
def shell(command, infile, outfile)
|
67
67
|
env = {"MCOLLECTIVE_REQUEST_FILE" => infile,
|
68
|
-
"MCOLLECTIVE_REPLY_FILE"
|
68
|
+
"MCOLLECTIVE_REPLY_FILE" => outfile}
|
69
69
|
|
70
70
|
Shell.new("#{command} #{infile} #{outfile}", :cwd => Dir.tmpdir, :stdout => stdout, :stderr => stderr, :environment => env)
|
71
71
|
end
|
@@ -78,20 +78,20 @@ module MCollective
|
|
78
78
|
if respond_to?("load_#{format}_results")
|
79
79
|
tempdata = send("load_#{format}_results", file)
|
80
80
|
|
81
|
-
tempdata.each_pair do |k,v|
|
81
|
+
tempdata.each_pair do |k, v|
|
82
82
|
data[k.to_sym] = v
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
data
|
87
|
-
rescue Exception
|
87
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
88
88
|
{}
|
89
89
|
end
|
90
90
|
|
91
91
|
def load_json_results(file)
|
92
92
|
return {} unless File.readable?(file)
|
93
93
|
|
94
|
-
JSON.
|
94
|
+
JSON.parse(File.read(file)) || {}
|
95
95
|
rescue JSON::ParserError
|
96
96
|
{}
|
97
97
|
end
|
@@ -119,7 +119,7 @@ module MCollective
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def to_s
|
122
|
-
"%s#%s command: %s" % [
|
122
|
+
"%s#%s command: %s" % [agent, action, command]
|
123
123
|
end
|
124
124
|
|
125
125
|
def tempfile(prefix)
|
@@ -127,15 +127,13 @@ module MCollective
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def path_to_command(command)
|
130
|
-
if Util.absolute_path?(command)
|
131
|
-
return command
|
132
|
-
end
|
130
|
+
return command if Util.absolute_path?(command)
|
133
131
|
|
134
132
|
Config.instance.libdir.each do |libdir|
|
135
133
|
command_file_old = File.join(libdir, "agent", agent, command)
|
136
134
|
command_file_new = File.join(libdir, "mcollective", "agent", agent, command)
|
137
|
-
command_file_old_exists = File.
|
138
|
-
command_file_new_exists = File.
|
135
|
+
command_file_old_exists = File.exist?(command_file_old)
|
136
|
+
command_file_new_exists = File.exist?(command_file_new)
|
139
137
|
|
140
138
|
if command_file_new_exists && command_file_old_exists
|
141
139
|
Log.debug("Found 'implemented_by' scripts found in two locations #{command_file_old} and #{command_file_new}")
|
@@ -53,8 +53,7 @@ module MCollective
|
|
53
53
|
@ddl = DDL.new(@agent_name, :agent)
|
54
54
|
@meta = @ddl.meta
|
55
55
|
@timeout = @meta[:timeout] || 10
|
56
|
-
|
57
|
-
rescue Exception => e
|
56
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
58
57
|
Log.error("Failed to load DDL for the '%s' agent, DDLs are required: %s: %s" % [@agent_name, e.class, e.to_s])
|
59
58
|
raise DDLValidationError
|
60
59
|
end
|
@@ -89,35 +88,29 @@ module MCollective
|
|
89
88
|
end
|
90
89
|
rescue RPCAborted => e
|
91
90
|
@reply.fail e.to_s, 1
|
92
|
-
|
93
91
|
rescue UnknownRPCAction => e
|
94
92
|
@reply.fail e.to_s, 2
|
95
|
-
|
96
93
|
rescue MissingRPCData => e
|
97
94
|
@reply.fail e.to_s, 3
|
98
|
-
|
99
95
|
rescue InvalidRPCData, DDLValidationError => e
|
100
96
|
@reply.fail e.to_s, 4
|
101
|
-
|
102
97
|
rescue UnknownRPCError => e
|
103
98
|
Log.error("%s#%s failed: %s: %s" % [@agent_name, @request.action, e.class, e.to_s])
|
104
99
|
Log.error(e.backtrace.join("\n\t"))
|
105
100
|
@reply.fail e.to_s, 5
|
106
|
-
|
107
|
-
rescue Exception => e
|
101
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
108
102
|
Log.error("%s#%s failed: %s: %s" % [@agent_name, @request.action, e.class, e.to_s])
|
109
103
|
Log.error(e.backtrace.join("\n\t"))
|
110
104
|
@reply.fail e.to_s, 5
|
111
|
-
|
112
105
|
end
|
113
106
|
|
114
107
|
after_processing_hook
|
115
108
|
|
116
109
|
if @request.should_respond?
|
117
|
-
|
110
|
+
@reply.to_hash
|
118
111
|
else
|
119
112
|
Log.debug("Client did not request a response, surpressing reply")
|
120
|
-
|
113
|
+
nil
|
121
114
|
end
|
122
115
|
end
|
123
116
|
|
@@ -137,7 +130,7 @@ module MCollective
|
|
137
130
|
# File.exist?("/usr/bin/puppet")
|
138
131
|
# end
|
139
132
|
def self.activate?
|
140
|
-
agent_name =
|
133
|
+
agent_name = to_s.split("::").last.downcase
|
141
134
|
config = Config.instance
|
142
135
|
|
143
136
|
Log.debug("Starting default activation checks for #{agent_name}")
|
@@ -146,14 +139,12 @@ module MCollective
|
|
146
139
|
should_activate = config.activate_agents
|
147
140
|
|
148
141
|
# Check agent specific state to determine if agent should be loaded
|
149
|
-
should_activate = Util.str_to_bool(config.pluginconf.fetch("#{agent_name}.activate_agent",
|
150
|
-
|
142
|
+
should_activate = Util.str_to_bool(config.pluginconf.fetch("#{agent_name}.activate_agent",
|
143
|
+
should_activate))
|
151
144
|
|
152
|
-
unless should_activate
|
153
|
-
Log.debug("Found plugin configuration '#{agent_name}.activate_agent' with value '#{should_activate}'")
|
154
|
-
end
|
145
|
+
Log.debug("Found plugin configuration '#{agent_name}.activate_agent' with value '#{should_activate}'") unless should_activate
|
155
146
|
|
156
|
-
|
147
|
+
should_activate
|
157
148
|
end
|
158
149
|
|
159
150
|
# Returns an array of actions this agent support
|
@@ -163,7 +154,6 @@ module MCollective
|
|
163
154
|
end
|
164
155
|
end
|
165
156
|
|
166
|
-
private
|
167
157
|
# Runs a command via the MC::Shell wrapper, options are as per MC::Shell
|
168
158
|
#
|
169
159
|
# The simplest use is:
|
@@ -206,22 +196,18 @@ module MCollective
|
|
206
196
|
[:stderr, :stdout].each do |k|
|
207
197
|
if options.include?(k)
|
208
198
|
if options[k].is_a?(Symbol)
|
209
|
-
reply[
|
210
|
-
shellopts[k] = reply[
|
199
|
+
reply[options[k]] = ""
|
200
|
+
shellopts[k] = reply[options[k]]
|
201
|
+
elsif options[k].respond_to?("<<")
|
202
|
+
shellopts[k] = options[k]
|
211
203
|
else
|
212
|
-
|
213
|
-
shellopts[k] = options[k]
|
214
|
-
else
|
215
|
-
reply.fail! "#{k} should support << while calling run(#{command})"
|
216
|
-
end
|
204
|
+
reply.fail! "#{k} should support << while calling run(#{command})"
|
217
205
|
end
|
218
206
|
end
|
219
207
|
end
|
220
208
|
|
221
209
|
[:stdin, :cwd, :environment, :timeout].each do |k|
|
222
|
-
if options.include?(k)
|
223
|
-
shellopts[k] = options[k]
|
224
|
-
end
|
210
|
+
shellopts[k] = options[k] if options.include?(k)
|
225
211
|
end
|
226
212
|
|
227
213
|
shell = Shell.new(command, shellopts)
|
@@ -263,7 +249,7 @@ module MCollective
|
|
263
249
|
def self.action(name, &block)
|
264
250
|
raise "Need to pass a body for the action" unless block_given?
|
265
251
|
|
266
|
-
|
252
|
+
module_eval { define_method("#{name}_action", &block) }
|
267
253
|
end
|
268
254
|
|
269
255
|
# Helper that creates a method on the class that will call your authorization
|
@@ -272,16 +258,18 @@ module MCollective
|
|
272
258
|
plugin = plugin.to_s.capitalize
|
273
259
|
|
274
260
|
# turns foo_bar into FooBar
|
275
|
-
plugin = plugin.to_s.split("_").map
|
261
|
+
plugin = plugin.to_s.split("_").map(&:capitalize).join
|
276
262
|
pluginname = "MCollective::Util::#{plugin}"
|
277
263
|
|
278
264
|
PluginManager.loadclass(pluginname) unless MCollective::Util.constants.include?(plugin)
|
279
265
|
|
266
|
+
# rubocop:disable Style/EvalWithLocation
|
280
267
|
class_eval("
|
281
268
|
def authorization_hook(request)
|
282
269
|
#{pluginname}.authorize(request)
|
283
270
|
end
|
284
271
|
")
|
272
|
+
# rubocop:enable Style/EvalWithLocation
|
285
273
|
end
|
286
274
|
|
287
275
|
# Validates a data member, if validation is a regex then it will try to match it
|
@@ -304,7 +292,7 @@ module MCollective
|
|
304
292
|
|
305
293
|
Validator.validate(@request[key], validation)
|
306
294
|
rescue ValidatorError => e
|
307
|
-
raise InvalidRPCData, "Input %s did not pass validation: %s" % [
|
295
|
+
raise InvalidRPCData, "Input %s did not pass validation: %s" % [key, e.message]
|
308
296
|
end
|
309
297
|
|
310
298
|
# convenience wrapper around Util#shellescape
|
@@ -323,10 +311,8 @@ module MCollective
|
|
323
311
|
|
324
312
|
reply.data.merge!(res[:data])
|
325
313
|
|
326
|
-
if res[:exitstatus] > 0
|
327
|
-
|
328
|
-
end
|
329
|
-
rescue Exception => e
|
314
|
+
reply.fail "Failed to run #{command}: #{res[:stderr]}", res[:exitstatus] if res[:exitstatus] > 0
|
315
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
330
316
|
Log.warn("Unhandled #{e.class} exception during #{request.agent}##{request.action}: #{e}")
|
331
317
|
reply.fail! "Unexpected failure calling #{command}: #{e.class}: #{e}"
|
332
318
|
end
|
@@ -338,15 +324,13 @@ module MCollective
|
|
338
324
|
# This will not be called right when the daemon starts up, we use
|
339
325
|
# lazy loading and initialization so it will only be called the first
|
340
326
|
# time a request for this agent arrives.
|
341
|
-
def startup_hook
|
342
|
-
end
|
327
|
+
def startup_hook; end
|
343
328
|
|
344
329
|
# Called just after a message was received from the middleware before
|
345
330
|
# it gets passed to the handlers. @request and @reply will already be
|
346
331
|
# set, the msg passed is the message as received from the normal
|
347
332
|
# mcollective runner and the connection is the actual connector.
|
348
|
-
def before_processing_hook(msg, connection)
|
349
|
-
end
|
333
|
+
def before_processing_hook(msg, connection); end
|
350
334
|
|
351
335
|
# Called at the end of processing just before the response gets sent
|
352
336
|
# to the middleware.
|
@@ -356,8 +340,7 @@ module MCollective
|
|
356
340
|
# it is outside of the block is so you'll have access to even status codes
|
357
341
|
# set by the exception handlers. If you do raise an exception it will just
|
358
342
|
# be passed onto the runner and processing will fail.
|
359
|
-
def after_processing_hook
|
360
|
-
end
|
343
|
+
def after_processing_hook; end
|
361
344
|
|
362
345
|
# Gets called right after a request was received and calls audit plugins
|
363
346
|
#
|
@@ -366,7 +349,7 @@ module MCollective
|
|
366
349
|
# do not care for the auditing in a specific agent.
|
367
350
|
def audit_request(msg, connection)
|
368
351
|
PluginManager["rpcaudit_plugin"].audit_request(msg, connection) if @config.rpcaudit
|
369
|
-
rescue Exception => e
|
352
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
370
353
|
Log.warn("Audit failed - #{e} - continuing to process message")
|
371
354
|
end
|
372
355
|
end
|