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,207 @@
|
|
1
|
+
module MCollective
|
2
|
+
class Application
|
3
|
+
class Playbook < Application
|
4
|
+
description "Choria Playbook Runner"
|
5
|
+
|
6
|
+
usage <<-USAGE
|
7
|
+
mco playbook [OPTIONS] <ACTION> <PLAYBOOK>
|
8
|
+
|
9
|
+
The ACTION can be one of the following:
|
10
|
+
|
11
|
+
run - run the playbook as your local user
|
12
|
+
|
13
|
+
The PLAYBOOK Puppet Plan describing the tasks to perform
|
14
|
+
|
15
|
+
Passing --help as well as a PLAYBOOK argument will show
|
16
|
+
flags and help related to the specific playbook.
|
17
|
+
|
18
|
+
Any inputs to the playbook should be given on the CLI.
|
19
|
+
USAGE
|
20
|
+
|
21
|
+
exclude_argument_sections "common", "filter", "rpc"
|
22
|
+
|
23
|
+
def pre_parse_modulepath
|
24
|
+
words = Shellwords.shellwords(ARGV.join(" "))
|
25
|
+
words.each_with_index do |word, idx|
|
26
|
+
if word == "--modulepath"
|
27
|
+
configuration[:__modulepath] = words[idx + 1]
|
28
|
+
break
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Playbook should be given right after the command, this finds the value after the command
|
34
|
+
#
|
35
|
+
# @return [String,nil]
|
36
|
+
def pre_parse_find_playbook
|
37
|
+
commands = Regexp.union(valid_commands)
|
38
|
+
|
39
|
+
cmd_idx = ARGV.index {|a| a.match(commands)}
|
40
|
+
return nil unless cmd_idx
|
41
|
+
|
42
|
+
pb = ARGV[cmd_idx + 1]
|
43
|
+
|
44
|
+
pb if pb =~ /\A([a-z][a-z0-9_]*)?(::[a-z][a-z0-9_]*)*\Z/
|
45
|
+
end
|
46
|
+
|
47
|
+
# Creates an instance of the plan runner
|
48
|
+
#
|
49
|
+
# @param plan [String] the name of a plan
|
50
|
+
# @return [Util::BoltSupport::PlanRunner]
|
51
|
+
def runner(plan, loglevel=nil)
|
52
|
+
require "mcollective/util/bolt_support"
|
53
|
+
plan_runner = Util::BoltSupport::PlanRunner.new(
|
54
|
+
plan,
|
55
|
+
configuration[:__tmpdir],
|
56
|
+
configuration[:__modulepath],
|
57
|
+
configuration[:__loglevel] || "info"
|
58
|
+
)
|
59
|
+
|
60
|
+
unless plan_runner.exist?
|
61
|
+
warn("Cannot find supplied Playbook %s" % plan)
|
62
|
+
$stderr.puts
|
63
|
+
warn("Module Path:")
|
64
|
+
$stderr.puts
|
65
|
+
|
66
|
+
if configuration[:__modulepath]
|
67
|
+
warn(Util.align_text(configuration[:__modulepath].split(":").join("\n")))
|
68
|
+
else
|
69
|
+
warn(Util.align_text("Puppet Default"))
|
70
|
+
end
|
71
|
+
|
72
|
+
exit(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
plan_runner
|
76
|
+
end
|
77
|
+
|
78
|
+
# Adds the playbook inputs as CLI options before starting the app
|
79
|
+
def run
|
80
|
+
pre_parse_modulepath
|
81
|
+
|
82
|
+
Dir.mktmpdir("choria") do |dir|
|
83
|
+
configuration[:__tmpdir] = dir
|
84
|
+
|
85
|
+
if playbook_name = pre_parse_find_playbook
|
86
|
+
configuration[:__playbook] = playbook_name
|
87
|
+
runner(playbook_name).add_cli_options(self, false)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Hackily done here to force it below the playbook options
|
91
|
+
self.class.option :__json_input,
|
92
|
+
:arguments => ["--input INPUT"],
|
93
|
+
:description => "JSON input to pass to the task",
|
94
|
+
:required => false,
|
95
|
+
:type => String
|
96
|
+
|
97
|
+
self.class.option :__modulepath,
|
98
|
+
:arguments => ["--modulepath PATH"],
|
99
|
+
:description => "Path to find Puppet module when using the Playbook DSL",
|
100
|
+
:type => String
|
101
|
+
|
102
|
+
self.class.option :__loglevel,
|
103
|
+
:arguments => ["--loglevel LEVEL"],
|
104
|
+
:description => "Override the loglevel set in the playbook (emerg alert crit err warning notice info verbose debug)",
|
105
|
+
:type => String,
|
106
|
+
:validate => ->(level) { %w[emerg alert crit err warning notice info verbose debug].include?(level) }
|
107
|
+
|
108
|
+
super
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def post_option_parser(configuration)
|
113
|
+
if ARGV.length >= 1
|
114
|
+
configuration[:__command] = ARGV.shift
|
115
|
+
else
|
116
|
+
abort("Please specify a command, valid commands are: %s" % valid_commands.join(", "))
|
117
|
+
end
|
118
|
+
|
119
|
+
if input = configuration[:__json_input]
|
120
|
+
result = {}
|
121
|
+
|
122
|
+
if input.start_with?("@")
|
123
|
+
input.sub!("@", "")
|
124
|
+
result = JSON.parse(File.read(input)) if input.end_with?("json")
|
125
|
+
result = YAML.safe_load(File.read(input)) if input.end_with?("yaml")
|
126
|
+
else
|
127
|
+
result = JSON.parse(input)
|
128
|
+
end
|
129
|
+
|
130
|
+
configuration.merge!(result)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Validates the configuration
|
135
|
+
#
|
136
|
+
# @return [void]
|
137
|
+
def validate_configuration(configuration)
|
138
|
+
abort("Please specify a playbook to run") unless configuration[:__playbook]
|
139
|
+
|
140
|
+
configuration[:__loglevel] = "debug" if options[:verbose] && !configuration.include?(:loglevel)
|
141
|
+
end
|
142
|
+
|
143
|
+
# List of valid commands this application respond to
|
144
|
+
#
|
145
|
+
# @return [Array<String>] like `plan` and `run`
|
146
|
+
def valid_commands
|
147
|
+
methods.grep(/_command$/).map {|c| c.to_s.gsub("_command", "")}
|
148
|
+
end
|
149
|
+
|
150
|
+
def run_command
|
151
|
+
pb_config = configuration.clone
|
152
|
+
pb_config.delete_if {|k, _| k.to_s.start_with?("__")}
|
153
|
+
|
154
|
+
pb = runner(configuration[:__playbook], configuration[:__loglevel])
|
155
|
+
|
156
|
+
run_plan(pb, pb_config)
|
157
|
+
end
|
158
|
+
|
159
|
+
def run_plan(playbook, pb_config)
|
160
|
+
startime = Time.now
|
161
|
+
|
162
|
+
success = true
|
163
|
+
|
164
|
+
result = playbook.run!(pb_config)
|
165
|
+
rescue
|
166
|
+
success = false
|
167
|
+
ensure
|
168
|
+
disconnect
|
169
|
+
|
170
|
+
endtime = Time.now
|
171
|
+
|
172
|
+
color = :green
|
173
|
+
msg = "OK"
|
174
|
+
|
175
|
+
unless success
|
176
|
+
color = :red
|
177
|
+
msg = "FAILED"
|
178
|
+
end
|
179
|
+
|
180
|
+
puts
|
181
|
+
puts "Playbook %s ran in %.2f seconds: %s" % [
|
182
|
+
Util.colorize(:bold, configuration[:__playbook]),
|
183
|
+
endtime - startime,
|
184
|
+
Util.colorize(color, msg)
|
185
|
+
]
|
186
|
+
|
187
|
+
if result
|
188
|
+
puts
|
189
|
+
puts "Result: "
|
190
|
+
puts
|
191
|
+
if result.instance_of?(String)
|
192
|
+
puts result
|
193
|
+
else
|
194
|
+
puts Util.align_text(JSON.pretty_generate(result), 10000)
|
195
|
+
end
|
196
|
+
puts
|
197
|
+
end
|
198
|
+
|
199
|
+
success ? exit(0) : exit(1)
|
200
|
+
end
|
201
|
+
|
202
|
+
def main
|
203
|
+
send("%s_command" % configuration[:__command])
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module MCollective
|
2
|
-
class Application::Plugin<Application
|
3
|
-
|
2
|
+
class Application::Plugin < Application # rubocop:disable Style/ClassAndModuleChildren
|
4
3
|
exclude_argument_sections "common", "filter", "rpc"
|
5
4
|
|
6
5
|
description "MCollective Plugin Application"
|
@@ -18,119 +17,119 @@ mco plugin package [options] <directory>
|
|
18
17
|
END_OF_USAGE
|
19
18
|
|
20
19
|
option :pluginname,
|
21
|
-
:description =>
|
22
|
-
:arguments
|
23
|
-
:type
|
20
|
+
:description => "Plugin name",
|
21
|
+
:arguments => ["-n", "--name NAME"],
|
22
|
+
:type => String
|
24
23
|
|
25
24
|
option :postinstall,
|
26
|
-
:description =>
|
27
|
-
:arguments
|
28
|
-
:type
|
25
|
+
:description => "Post install script",
|
26
|
+
:arguments => ["--postinstall POSTINSTALL"],
|
27
|
+
:type => String
|
29
28
|
|
30
29
|
option :preinstall,
|
31
|
-
:description =>
|
32
|
-
:arguments
|
33
|
-
:type
|
30
|
+
:description => "Pre install script",
|
31
|
+
:arguments => ["--preinstall PREINSTALL"],
|
32
|
+
:type => String
|
34
33
|
|
35
34
|
option :revision,
|
36
|
-
:description =>
|
37
|
-
:arguments
|
38
|
-
:type
|
35
|
+
:description => "Revision number",
|
36
|
+
:arguments => ["--revision REVISION"],
|
37
|
+
:type => String
|
39
38
|
|
40
39
|
option :iteration,
|
41
|
-
:description =>
|
42
|
-
:arguments
|
43
|
-
:type
|
40
|
+
:description => "DEPRECATED - Use --revision instead",
|
41
|
+
:arguments => ["--iteration ITERATION"],
|
42
|
+
:type => String
|
44
43
|
|
45
44
|
option :vendor,
|
46
|
-
:description =>
|
47
|
-
:arguments
|
48
|
-
:type
|
45
|
+
:description => "Vendor name",
|
46
|
+
:arguments => ["--vendor VENDOR"],
|
47
|
+
:type => String
|
49
48
|
|
50
49
|
option :pluginpath,
|
51
|
-
:description =>
|
52
|
-
:arguments
|
53
|
-
:type
|
50
|
+
:description => "MCollective plugin path",
|
51
|
+
:arguments => ["--pluginpath PATH"],
|
52
|
+
:type => String
|
54
53
|
|
55
54
|
option :mcname,
|
56
|
-
:description =>
|
57
|
-
:arguments
|
58
|
-
:type
|
55
|
+
:description => "MCollective type (mcollective, pe-mcollective) that the packages depend on",
|
56
|
+
:arguments => ["--mcname NAME"],
|
57
|
+
:type => String
|
59
58
|
|
60
59
|
option :mcversion,
|
61
|
-
:description =>
|
62
|
-
:arguments
|
63
|
-
:type
|
60
|
+
:description => "Version of MCollective that the packages depend on",
|
61
|
+
:arguments => ["--mcversion MCVERSION"],
|
62
|
+
:type => String
|
64
63
|
|
65
64
|
option :dependency,
|
66
|
-
:description =>
|
67
|
-
:arguments
|
68
|
-
:type
|
65
|
+
:description => "Adds a dependency to the plugin",
|
66
|
+
:arguments => ["--dependency DEPENDENCIES"],
|
67
|
+
:type => :array
|
69
68
|
|
70
69
|
option :format,
|
71
|
-
:description =>
|
72
|
-
:arguments
|
73
|
-
:type
|
70
|
+
:description => "Package output format. Defaults to rpmpackage or debpackage",
|
71
|
+
:arguments => ["--format OUTPUTFORMAT"],
|
72
|
+
:type => String
|
74
73
|
|
75
74
|
option :sign,
|
76
|
-
:description =>
|
77
|
-
:arguments
|
78
|
-
:type
|
75
|
+
:description => "Embed a signature in the package",
|
76
|
+
:arguments => ["--sign"],
|
77
|
+
:type => :boolean
|
79
78
|
|
80
79
|
option :rpctemplate,
|
81
|
-
:description =>
|
82
|
-
:arguments
|
83
|
-
:type
|
80
|
+
:description => "Template to use.",
|
81
|
+
:arguments => ["--template HELPTEMPLATE"],
|
82
|
+
:type => String
|
84
83
|
|
85
84
|
option :description,
|
86
|
-
:description =>
|
87
|
-
:arguments
|
88
|
-
:type
|
85
|
+
:description => "Plugin description",
|
86
|
+
:arguments => ["--description DESCRIPTION"],
|
87
|
+
:type => String
|
89
88
|
|
90
89
|
option :author,
|
91
|
-
:description =>
|
92
|
-
:arguments
|
93
|
-
:type
|
90
|
+
:description => "The author of the plugin",
|
91
|
+
:arguments => ["--author AUTHOR"],
|
92
|
+
:type => String
|
94
93
|
|
95
94
|
option :license,
|
96
|
-
:description =>
|
97
|
-
:arguments
|
98
|
-
:type
|
95
|
+
:description => "The license under which the plugin is distributed",
|
96
|
+
:arguments => ["--license LICENSE"],
|
97
|
+
:type => String
|
99
98
|
|
100
99
|
option :version,
|
101
|
-
:description =>
|
102
|
-
:arguments
|
103
|
-
:type
|
100
|
+
:description => "The version of the plugin",
|
101
|
+
:arguments => ["--pluginversion VERSION"],
|
102
|
+
:type => String
|
104
103
|
|
105
104
|
option :url,
|
106
|
-
:description =>
|
107
|
-
:arguments
|
108
|
-
:type
|
105
|
+
:description => "Url at which information about the plugin can be found",
|
106
|
+
:arguments => ["--url URL"],
|
107
|
+
:type => String
|
109
108
|
|
110
109
|
option :timeout,
|
111
110
|
:description => "The plugin's timeout",
|
112
|
-
:arguments
|
113
|
-
:type
|
111
|
+
:arguments => ["--timeout TIMEOUT"],
|
112
|
+
:type => Integer
|
114
113
|
|
115
114
|
option :actions,
|
116
|
-
:description =>
|
117
|
-
:arguments
|
118
|
-
:type
|
115
|
+
:description => "Actions to be generated for an Agent Plugin",
|
116
|
+
:arguments => ["--actions [ACTIONS]"],
|
117
|
+
:type => Array
|
119
118
|
|
120
119
|
option :outputs,
|
121
|
-
:description =>
|
122
|
-
:arguments
|
123
|
-
:type
|
120
|
+
:description => "Outputs to be generated for an Data Plugin",
|
121
|
+
:arguments => ["--outputs [OUTPUTS]"],
|
122
|
+
:type => Array
|
124
123
|
|
125
124
|
option :keep_artifacts,
|
126
125
|
:description => "Don't remove artifacts after building packages",
|
127
|
-
:arguments
|
128
|
-
:type
|
126
|
+
:arguments => ["--keep-artifacts"],
|
127
|
+
:type => :boolean
|
129
128
|
|
130
129
|
option :module_template,
|
131
130
|
:description => "Path to the template used by the modulepackager",
|
132
|
-
:arguments
|
133
|
-
:type
|
131
|
+
:arguments => ["--module-template PATH"],
|
132
|
+
:type => String
|
134
133
|
|
135
134
|
# Handle alternative format that optparser can't parse.
|
136
135
|
def post_option_parser(configuration)
|
@@ -141,16 +140,16 @@ mco plugin package [options] <directory>
|
|
141
140
|
|
142
141
|
if configuration[:action] == "generate"
|
143
142
|
unless ARGV[0] && ARGV[0].match(/(actions|outputs)=(.+)/i)
|
144
|
-
|
145
|
-
configuration[:pluginname] = ARGV.delete_at(0)
|
146
|
-
else
|
143
|
+
if configuration[:pluginname] # rubocop:disable Metrics/BlockNesting
|
147
144
|
ARGV.delete_at(0)
|
145
|
+
else
|
146
|
+
configuration[:pluginname] = ARGV.delete_at(0)
|
148
147
|
end
|
149
148
|
end
|
150
149
|
|
151
150
|
ARGV.each do |argument|
|
152
151
|
if argument.match(/(actions|outputs)=(.+)/i)
|
153
|
-
configuration[$1.downcase.to_sym]= $2.split(",")
|
152
|
+
configuration[$1.downcase.to_sym] = $2.split(",")
|
154
153
|
else
|
155
154
|
raise "Could not parse --arg '#{argument}'"
|
156
155
|
end
|
@@ -168,7 +167,7 @@ mco plugin package [options] <directory>
|
|
168
167
|
|
169
168
|
# Generate a plugin skeleton
|
170
169
|
def generate_command
|
171
|
-
raise "undefined plugin type. cannot generate plugin. valid types are 'agent' and 'data'" if configuration["target"] ==
|
170
|
+
raise "undefined plugin type. cannot generate plugin. valid types are 'agent' and 'data'" if configuration["target"] == "."
|
172
171
|
|
173
172
|
unless configuration[:pluginname]
|
174
173
|
puts "No plugin name specified. Using 'new_plugin'"
|
@@ -178,15 +177,16 @@ mco plugin package [options] <directory>
|
|
178
177
|
load_plugin_config_values
|
179
178
|
|
180
179
|
case configuration[:target].downcase
|
181
|
-
when
|
180
|
+
when "agent"
|
182
181
|
Generators::AgentGenerator.new(configuration[:pluginname], configuration[:actions], configuration[:pluginname],
|
183
182
|
configuration[:description], configuration[:author], configuration[:license],
|
184
183
|
configuration[:version], configuration[:url], configuration[:timeout])
|
185
|
-
when
|
184
|
+
when "data"
|
186
185
|
raise "data plugin must have at least one output" unless configuration[:outputs]
|
186
|
+
|
187
187
|
Generators::DataGenerator.new(configuration[:pluginname], configuration[:outputs], configuration[:pluginname],
|
188
|
-
|
189
|
-
|
188
|
+
configuration[:description], configuration[:author], configuration[:license],
|
189
|
+
configuration[:version], configuration[:url], configuration[:timeout])
|
190
190
|
else
|
191
191
|
raise "invalid plugin type. cannot generate plugin '#{configuration[:target]}'"
|
192
192
|
end
|
@@ -196,11 +196,11 @@ mco plugin package [options] <directory>
|
|
196
196
|
def package_command
|
197
197
|
if configuration[:sign] && Config.instance.pluginconf.include?("debian_packager.keyname")
|
198
198
|
configuration[:sign] = Config.instance.pluginconf["debian_packager.keyname"]
|
199
|
-
configuration[:sign] = "\"#{configuration[:sign]}\"" unless configuration[:sign].match(
|
199
|
+
configuration[:sign] = "\"#{configuration[:sign]}\"" unless configuration[:sign].match(/".*"/)
|
200
200
|
end
|
201
201
|
|
202
202
|
plugin = prepare_plugin
|
203
|
-
(configuration[:pluginpath] = configuration[:pluginpath]
|
203
|
+
(configuration[:pluginpath] = "#{configuration[:pluginpath]}/") if configuration[:pluginpath] && !configuration[:pluginpath].match(/^.*\/$/)
|
204
204
|
packager = PluginPackager["#{configuration[:format].capitalize}Packager"]
|
205
205
|
packager.new(plugin, configuration[:pluginpath], configuration[:sign],
|
206
206
|
options[:verbose], configuration[:keep_artifacts],
|
@@ -219,11 +219,11 @@ mco plugin package [options] <directory>
|
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
|
-
|
222
|
+
nil
|
223
223
|
end
|
224
224
|
|
225
225
|
# Show application list and plugin help
|
226
|
-
def doc_command
|
226
|
+
def doc_command # rubocop:disable Metrics/MethodLength
|
227
227
|
known_plugin_types = [
|
228
228
|
["Agents", :agent],
|
229
229
|
["Aggregate", :aggregate],
|
@@ -240,12 +240,12 @@ mco plugin package [options] <directory>
|
|
240
240
|
found_plugin_type = nil
|
241
241
|
|
242
242
|
known_plugin_types.each do |plugin_type|
|
243
|
-
PluginManager.find(plugin_type[1], "ddl").each do |
|
244
|
-
pluginname =
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
243
|
+
PluginManager.find(plugin_type[1], "ddl").each do |ddlf|
|
244
|
+
pluginname = ddlf.gsub(/_#{plugin_type[1]}$/, "")
|
245
|
+
|
246
|
+
abort "Duplicate plugin name found, please specify a full path like agent/rpcutil" if pluginname == configuration[:target] && found_plugin_type
|
247
|
+
|
248
|
+
found_plugin_type = plugin_type[1] if pluginname == configuration[:target]
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
@@ -256,7 +256,7 @@ mco plugin package [options] <directory>
|
|
256
256
|
if ddl
|
257
257
|
puts ddl.help(configuration[:rpctemplate])
|
258
258
|
else
|
259
|
-
abort "Could not find a '%s' plugin named '%s'" % configuration[:target].split(
|
259
|
+
abort "Could not find a '%s' plugin named '%s'" % configuration[:target].split("/")
|
260
260
|
end
|
261
261
|
|
262
262
|
else
|
@@ -268,17 +268,17 @@ mco plugin package [options] <directory>
|
|
268
268
|
known_plugin_types.each do |plugin_type|
|
269
269
|
puts "%s:" % plugin_type[0]
|
270
270
|
|
271
|
-
PluginManager.find(plugin_type[1], "ddl").each do |
|
271
|
+
PluginManager.find(plugin_type[1], "ddl").each do |ddlf|
|
272
272
|
begin
|
273
|
-
help = DDL.new(
|
273
|
+
help = DDL.new(ddlf, plugin_type[1], false)
|
274
274
|
|
275
275
|
next unless help.client_activated?
|
276
276
|
|
277
277
|
help.loadddlfile
|
278
|
-
pluginname =
|
278
|
+
pluginname = ddlf.gsub(/_#{plugin_type[1]}$/, "")
|
279
279
|
puts " %-25s %s" % [pluginname, help.meta[:description]]
|
280
280
|
rescue => e
|
281
|
-
load_errors << [plugin_type[1],
|
281
|
+
load_errors << [plugin_type[1], ddlf, e]
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -305,7 +305,7 @@ mco plugin package [options] <directory>
|
|
305
305
|
if configuration[:dependency] && configuration[:dependency].size == 1
|
306
306
|
configuration[:dependency] = configuration[:dependency][0].split(" ")
|
307
307
|
elsif configuration[:dependency]
|
308
|
-
configuration[:dependency].map!{|dep| {:name => dep, :version => nil}}
|
308
|
+
configuration[:dependency].map! {|dep| {:name => dep, :version => nil}}
|
309
309
|
end
|
310
310
|
|
311
311
|
mcdependency = {
|
@@ -315,7 +315,7 @@ mco plugin package [options] <directory>
|
|
315
315
|
|
316
316
|
# Deprecation warning for --iteration
|
317
317
|
if configuration[:iteration]
|
318
|
-
puts
|
318
|
+
puts "Warning. The --iteration flag has been deprecated. Please use --revision instead."
|
319
319
|
configuration[:revision] = configuration[:iteration] unless configuration[:revision]
|
320
320
|
end
|
321
321
|
|
@@ -330,12 +330,12 @@ mco plugin package [options] <directory>
|
|
330
330
|
def set_plugin_type
|
331
331
|
if plugin_directory_exists?("agent") || plugin_directory_exists?("application")
|
332
332
|
configuration[:plugintype] = "AgentDefinition"
|
333
|
-
|
333
|
+
"Agent"
|
334
334
|
elsif plugin_directory_exists?(plugintype = identify_plugin)
|
335
335
|
configuration[:plugintype] = "StandardDefinition"
|
336
|
-
|
336
|
+
plugintype
|
337
337
|
else
|
338
|
-
raise
|
338
|
+
raise "target directory is not a valid mcollective plugin"
|
339
339
|
end
|
340
340
|
end
|
341
341
|
|
@@ -348,8 +348,8 @@ mco plugin package [options] <directory>
|
|
348
348
|
File.directory?(file) && file.match(/(connector|facts|registration|security|audit|pluginpackager|data|discovery|validator)/)
|
349
349
|
end
|
350
350
|
|
351
|
-
raise
|
352
|
-
raise
|
351
|
+
raise "more than one plugin type detected in directory" if plugintype.size > 1
|
352
|
+
raise "no plugins detected in directory" if plugintype.empty?
|
353
353
|
|
354
354
|
File.basename(plugintype[0])
|
355
355
|
end
|
@@ -367,15 +367,15 @@ mco plugin package [options] <directory>
|
|
367
367
|
end
|
368
368
|
|
369
369
|
def main
|
370
|
-
|
370
|
+
abort "No action specified, please run 'mco help plugin' for help" unless configuration.include?(:action)
|
371
371
|
|
372
|
-
|
372
|
+
cmd = "#{configuration[:action]}_command"
|
373
373
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
374
|
+
if respond_to? cmd
|
375
|
+
send cmd
|
376
|
+
else
|
377
|
+
abort "Invalid action #{configuration[:action]}, please run 'mco help plugin' for help."
|
378
|
+
end
|
379
379
|
end
|
380
380
|
end
|
381
381
|
end
|