choria-mcorpc-support 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/mco +64 -0
- data/lib/mcollective.rb +63 -0
- data/lib/mcollective/agent.rb +5 -0
- data/lib/mcollective/agents.rb +149 -0
- data/lib/mcollective/aggregate.rb +85 -0
- data/lib/mcollective/aggregate/average.ddl +33 -0
- data/lib/mcollective/aggregate/average.rb +29 -0
- data/lib/mcollective/aggregate/base.rb +40 -0
- data/lib/mcollective/aggregate/result.rb +9 -0
- data/lib/mcollective/aggregate/result/base.rb +25 -0
- data/lib/mcollective/aggregate/result/collection_result.rb +19 -0
- data/lib/mcollective/aggregate/result/numeric_result.rb +13 -0
- data/lib/mcollective/aggregate/sum.ddl +33 -0
- data/lib/mcollective/aggregate/sum.rb +18 -0
- data/lib/mcollective/aggregate/summary.ddl +33 -0
- data/lib/mcollective/aggregate/summary.rb +53 -0
- data/lib/mcollective/application.rb +365 -0
- data/lib/mcollective/application/completion.rb +104 -0
- data/lib/mcollective/application/describe_filter.rb +87 -0
- data/lib/mcollective/application/facts.rb +62 -0
- data/lib/mcollective/application/find.rb +23 -0
- data/lib/mcollective/application/help.rb +28 -0
- data/lib/mcollective/application/inventory.rb +344 -0
- data/lib/mcollective/application/ping.rb +82 -0
- data/lib/mcollective/application/plugin.rb +369 -0
- data/lib/mcollective/application/rpc.rb +111 -0
- data/lib/mcollective/applications.rb +134 -0
- data/lib/mcollective/cache.rb +145 -0
- data/lib/mcollective/client.rb +353 -0
- data/lib/mcollective/config.rb +245 -0
- data/lib/mcollective/connector.rb +18 -0
- data/lib/mcollective/connector/base.rb +26 -0
- data/lib/mcollective/data.rb +91 -0
- data/lib/mcollective/data/agent_data.ddl +22 -0
- data/lib/mcollective/data/agent_data.rb +17 -0
- data/lib/mcollective/data/base.rb +67 -0
- data/lib/mcollective/data/collective_data.ddl +20 -0
- data/lib/mcollective/data/collective_data.rb +9 -0
- data/lib/mcollective/data/fact_data.ddl +28 -0
- data/lib/mcollective/data/fact_data.rb +55 -0
- data/lib/mcollective/data/fstat_data.ddl +89 -0
- data/lib/mcollective/data/fstat_data.rb +56 -0
- data/lib/mcollective/data/result.rb +45 -0
- data/lib/mcollective/ddl.rb +113 -0
- data/lib/mcollective/ddl/agentddl.rb +253 -0
- data/lib/mcollective/ddl/base.rb +217 -0
- data/lib/mcollective/ddl/dataddl.rb +56 -0
- data/lib/mcollective/ddl/discoveryddl.rb +52 -0
- data/lib/mcollective/ddl/validatorddl.rb +6 -0
- data/lib/mcollective/discovery.rb +143 -0
- data/lib/mcollective/discovery/flatfile.ddl +11 -0
- data/lib/mcollective/discovery/flatfile.rb +48 -0
- data/lib/mcollective/discovery/mc.ddl +11 -0
- data/lib/mcollective/discovery/mc.rb +30 -0
- data/lib/mcollective/discovery/stdin.ddl +11 -0
- data/lib/mcollective/discovery/stdin.rb +68 -0
- data/lib/mcollective/exceptions.rb +28 -0
- data/lib/mcollective/facts.rb +39 -0
- data/lib/mcollective/facts/base.rb +100 -0
- data/lib/mcollective/facts/yaml_facts.rb +65 -0
- data/lib/mcollective/generators.rb +7 -0
- data/lib/mcollective/generators/agent_generator.rb +51 -0
- data/lib/mcollective/generators/base.rb +46 -0
- data/lib/mcollective/generators/data_generator.rb +51 -0
- data/lib/mcollective/generators/templates/action_snippet.erb +13 -0
- data/lib/mcollective/generators/templates/data_input_snippet.erb +7 -0
- data/lib/mcollective/generators/templates/ddl.erb +8 -0
- data/lib/mcollective/generators/templates/plugin.erb +7 -0
- data/lib/mcollective/log.rb +118 -0
- data/lib/mcollective/logger.rb +5 -0
- data/lib/mcollective/logger/base.rb +77 -0
- data/lib/mcollective/logger/console_logger.rb +61 -0
- data/lib/mcollective/logger/file_logger.rb +53 -0
- data/lib/mcollective/logger/syslog_logger.rb +53 -0
- data/lib/mcollective/matcher.rb +224 -0
- data/lib/mcollective/matcher/parser.rb +128 -0
- data/lib/mcollective/matcher/scanner.rb +241 -0
- data/lib/mcollective/message.rb +248 -0
- data/lib/mcollective/monkey_patches.rb +152 -0
- data/lib/mcollective/optionparser.rb +197 -0
- data/lib/mcollective/pluginmanager.rb +180 -0
- data/lib/mcollective/pluginpackager.rb +98 -0
- data/lib/mcollective/pluginpackager/agent_definition.rb +94 -0
- data/lib/mcollective/pluginpackager/debpackage_packager.rb +237 -0
- data/lib/mcollective/pluginpackager/modulepackage_packager.rb +127 -0
- data/lib/mcollective/pluginpackager/ospackage_packager.rb +59 -0
- data/lib/mcollective/pluginpackager/rpmpackage_packager.rb +180 -0
- data/lib/mcollective/pluginpackager/standard_definition.rb +69 -0
- data/lib/mcollective/pluginpackager/templates/debian/Makefile.erb +7 -0
- data/lib/mcollective/pluginpackager/templates/debian/changelog.erb +5 -0
- data/lib/mcollective/pluginpackager/templates/debian/compat.erb +1 -0
- data/lib/mcollective/pluginpackager/templates/debian/control.erb +15 -0
- data/lib/mcollective/pluginpackager/templates/debian/copyright.erb +8 -0
- data/lib/mcollective/pluginpackager/templates/debian/rules.erb +6 -0
- data/lib/mcollective/pluginpackager/templates/module/Modulefile.erb +5 -0
- data/lib/mcollective/pluginpackager/templates/module/README.md.erb +37 -0
- data/lib/mcollective/pluginpackager/templates/module/_manifest.pp.erb +9 -0
- data/lib/mcollective/pluginpackager/templates/redhat/rpm_spec.erb +63 -0
- data/lib/mcollective/registration/base.rb +91 -0
- data/lib/mcollective/rpc.rb +182 -0
- data/lib/mcollective/rpc/actionrunner.rb +158 -0
- data/lib/mcollective/rpc/agent.rb +374 -0
- data/lib/mcollective/rpc/audit.rb +38 -0
- data/lib/mcollective/rpc/client.rb +1066 -0
- data/lib/mcollective/rpc/helpers.rb +321 -0
- data/lib/mcollective/rpc/progress.rb +63 -0
- data/lib/mcollective/rpc/reply.rb +87 -0
- data/lib/mcollective/rpc/request.rb +86 -0
- data/lib/mcollective/rpc/result.rb +90 -0
- data/lib/mcollective/rpc/stats.rb +294 -0
- data/lib/mcollective/runnerstats.rb +90 -0
- data/lib/mcollective/security.rb +26 -0
- data/lib/mcollective/security/base.rb +244 -0
- data/lib/mcollective/shell.rb +126 -0
- data/lib/mcollective/ssl.rb +285 -0
- data/lib/mcollective/util.rb +579 -0
- data/lib/mcollective/validator.rb +85 -0
- data/lib/mcollective/validator/array_validator.ddl +7 -0
- data/lib/mcollective/validator/array_validator.rb +9 -0
- data/lib/mcollective/validator/ipv4address_validator.ddl +7 -0
- data/lib/mcollective/validator/ipv4address_validator.rb +16 -0
- data/lib/mcollective/validator/ipv6address_validator.ddl +7 -0
- data/lib/mcollective/validator/ipv6address_validator.rb +16 -0
- data/lib/mcollective/validator/length_validator.ddl +7 -0
- data/lib/mcollective/validator/length_validator.rb +11 -0
- data/lib/mcollective/validator/regex_validator.ddl +7 -0
- data/lib/mcollective/validator/regex_validator.rb +9 -0
- data/lib/mcollective/validator/shellsafe_validator.ddl +7 -0
- data/lib/mcollective/validator/shellsafe_validator.rb +13 -0
- data/lib/mcollective/validator/typecheck_validator.ddl +7 -0
- data/lib/mcollective/validator/typecheck_validator.rb +28 -0
- metadata +215 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module MCollective
|
|
3
|
+
class Application::Ping<Application
|
|
4
|
+
description "Ping all nodes"
|
|
5
|
+
|
|
6
|
+
option :graph,
|
|
7
|
+
:description => "Shows a graph of ping distribution",
|
|
8
|
+
:arguments => ["--graph", "-g"],
|
|
9
|
+
:default => false,
|
|
10
|
+
:type => :bool
|
|
11
|
+
|
|
12
|
+
# Convert the times structure into a array representing
|
|
13
|
+
# buckets of responses in 50 ms intervals. Return a small
|
|
14
|
+
# sparkline graph using UTF8 characters
|
|
15
|
+
def spark(resp_times)
|
|
16
|
+
return "" unless configuration[:graph] || Config.instance.pluginconf["rpc.graph"]
|
|
17
|
+
|
|
18
|
+
ticks=%w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
|
|
19
|
+
|
|
20
|
+
histo = {}
|
|
21
|
+
|
|
22
|
+
# round each time to its nearest 50ms
|
|
23
|
+
# and keep a count for each 50ms
|
|
24
|
+
resp_times.each do |time|
|
|
25
|
+
time = Integer(time + 50 - (time % 50))
|
|
26
|
+
histo[time] ||= 0
|
|
27
|
+
histo[time] += 1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# set the 50ms intervals that saw no traffic to 0
|
|
31
|
+
((histo.keys.max - histo.keys.min) / 50).times do |i|
|
|
32
|
+
time = (i * 50) + histo.keys.min
|
|
33
|
+
histo[time] = 0 unless histo[time]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# get a numerically sorted list of times
|
|
37
|
+
histo = histo.keys.sort.map{|k| histo[k]}
|
|
38
|
+
|
|
39
|
+
range = histo.max - histo.min
|
|
40
|
+
scale = ticks.size - 1
|
|
41
|
+
distance = histo.max.to_f / scale
|
|
42
|
+
|
|
43
|
+
histo.map do |val|
|
|
44
|
+
tick = (val / distance).round
|
|
45
|
+
tick = 0 if tick < 0
|
|
46
|
+
|
|
47
|
+
ticks[tick]
|
|
48
|
+
end.join
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def main
|
|
52
|
+
# If the user did not override the default timeout include the discovery timeout
|
|
53
|
+
if options[:timeout] == 5
|
|
54
|
+
discovery_timeout = options[:disctimeout] || Config.instance.discovery_timeout || 0
|
|
55
|
+
options[:timeout] = options[:timeout] + discovery_timeout
|
|
56
|
+
end
|
|
57
|
+
client = MCollective::Client.new(options)
|
|
58
|
+
|
|
59
|
+
start = Time.now.to_f
|
|
60
|
+
times = []
|
|
61
|
+
|
|
62
|
+
client.req("ping", "discovery") do |resp|
|
|
63
|
+
times << (Time.now.to_f - start) * 1000
|
|
64
|
+
|
|
65
|
+
puts "%-40s time=%.2f ms" % [resp[:senderid], times.last]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
puts("\n\n---- ping statistics ----")
|
|
69
|
+
|
|
70
|
+
if times.size > 0
|
|
71
|
+
sum = times.inject(0){|acc,i|acc +i}
|
|
72
|
+
avg = sum / times.length.to_f
|
|
73
|
+
|
|
74
|
+
puts "%d replies max: %.2f min: %.2f avg: %.2f %s" % [times.size, times.max, times.min, avg, spark(times)]
|
|
75
|
+
else
|
|
76
|
+
puts("No responses received")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
halt client.stats
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
module MCollective
|
|
2
|
+
class Application::Plugin<Application
|
|
3
|
+
|
|
4
|
+
exclude_argument_sections "common", "filter", "rpc"
|
|
5
|
+
|
|
6
|
+
description "MCollective Plugin Application"
|
|
7
|
+
usage <<-END_OF_USAGE
|
|
8
|
+
mco plugin package [options] <directory>
|
|
9
|
+
mco plugin info <directory>
|
|
10
|
+
mco plugin doc <plugin>
|
|
11
|
+
mco plugin doc <type/plugin>
|
|
12
|
+
mco plugin generate agent <pluginname> [actions=val,val]
|
|
13
|
+
mco plugin generate data <pluginname> [outputs=val,val]
|
|
14
|
+
|
|
15
|
+
info : Display plugin information including package details.
|
|
16
|
+
package : Create all available plugin packages.
|
|
17
|
+
doc : Display documentation for a specific plugin.
|
|
18
|
+
END_OF_USAGE
|
|
19
|
+
|
|
20
|
+
option :pluginname,
|
|
21
|
+
:description => 'Plugin name',
|
|
22
|
+
:arguments => ['-n', '--name NAME'],
|
|
23
|
+
:type => String
|
|
24
|
+
|
|
25
|
+
option :postinstall,
|
|
26
|
+
:description => 'Post install script',
|
|
27
|
+
:arguments => ['--postinstall POSTINSTALL'],
|
|
28
|
+
:type => String
|
|
29
|
+
|
|
30
|
+
option :preinstall,
|
|
31
|
+
:description => 'Pre install script',
|
|
32
|
+
:arguments => ['--preinstall PREINSTALL'],
|
|
33
|
+
:type => String
|
|
34
|
+
|
|
35
|
+
option :revision,
|
|
36
|
+
:description => 'Revision number',
|
|
37
|
+
:arguments => ['--revision REVISION'],
|
|
38
|
+
:type => String
|
|
39
|
+
|
|
40
|
+
option :iteration,
|
|
41
|
+
:description => 'DEPRECATED - Use --revision instead',
|
|
42
|
+
:arguments => ['--iteration ITERATION'],
|
|
43
|
+
:type => String
|
|
44
|
+
|
|
45
|
+
option :vendor,
|
|
46
|
+
:description => 'Vendor name',
|
|
47
|
+
:arguments => ['--vendor VENDOR'],
|
|
48
|
+
:type => String
|
|
49
|
+
|
|
50
|
+
option :pluginpath,
|
|
51
|
+
:description => 'MCollective plugin path',
|
|
52
|
+
:arguments => ['--pluginpath PATH'],
|
|
53
|
+
:type => String
|
|
54
|
+
|
|
55
|
+
option :mcname,
|
|
56
|
+
:description => 'MCollective type (mcollective, pe-mcollective) that the packages depend on',
|
|
57
|
+
:arguments => ['--mcname NAME'],
|
|
58
|
+
:type => String
|
|
59
|
+
|
|
60
|
+
option :mcversion,
|
|
61
|
+
:description => 'Version of MCollective that the packages depend on',
|
|
62
|
+
:arguments => ['--mcversion MCVERSION'],
|
|
63
|
+
:type => String
|
|
64
|
+
|
|
65
|
+
option :dependency,
|
|
66
|
+
:description => 'Adds a dependency to the plugin',
|
|
67
|
+
:arguments => ['--dependency DEPENDENCIES'],
|
|
68
|
+
:type => :array
|
|
69
|
+
|
|
70
|
+
option :format,
|
|
71
|
+
:description => 'Package output format. Defaults to rpmpackage or debpackage',
|
|
72
|
+
:arguments => ['--format OUTPUTFORMAT'],
|
|
73
|
+
:type => String
|
|
74
|
+
|
|
75
|
+
option :sign,
|
|
76
|
+
:description => 'Embed a signature in the package',
|
|
77
|
+
:arguments => ['--sign'],
|
|
78
|
+
:type => :boolean
|
|
79
|
+
|
|
80
|
+
option :rpctemplate,
|
|
81
|
+
:description => 'Template to use.',
|
|
82
|
+
:arguments => ['--template HELPTEMPLATE'],
|
|
83
|
+
:type => String
|
|
84
|
+
|
|
85
|
+
option :description,
|
|
86
|
+
:description => 'Plugin description',
|
|
87
|
+
:arguments => ['--description DESCRIPTION'],
|
|
88
|
+
:type => String
|
|
89
|
+
|
|
90
|
+
option :author,
|
|
91
|
+
:description => 'The author of the plugin',
|
|
92
|
+
:arguments => ['--author AUTHOR'],
|
|
93
|
+
:type => String
|
|
94
|
+
|
|
95
|
+
option :license,
|
|
96
|
+
:description => 'The license under which the plugin is distributed',
|
|
97
|
+
:arguments => ['--license LICENSE'],
|
|
98
|
+
:type => String
|
|
99
|
+
|
|
100
|
+
option :version,
|
|
101
|
+
:description => 'The version of the plugin',
|
|
102
|
+
:arguments => ['--pluginversion VERSION'],
|
|
103
|
+
:type => String
|
|
104
|
+
|
|
105
|
+
option :url,
|
|
106
|
+
:description => 'Url at which information about the plugin can be found',
|
|
107
|
+
:arguments => ['--url URL'],
|
|
108
|
+
:type => String
|
|
109
|
+
|
|
110
|
+
option :timeout,
|
|
111
|
+
:description => "The plugin's timeout",
|
|
112
|
+
:arguments => ['--timeout TIMEOUT'],
|
|
113
|
+
:type => Integer
|
|
114
|
+
|
|
115
|
+
option :actions,
|
|
116
|
+
:description => 'Actions to be generated for an Agent Plugin',
|
|
117
|
+
:arguments => ['--actions [ACTIONS]'],
|
|
118
|
+
:type => Array
|
|
119
|
+
|
|
120
|
+
option :outputs,
|
|
121
|
+
:description => 'Outputs to be generated for an Data Plugin',
|
|
122
|
+
:arguments => ['--outputs [OUTPUTS]'],
|
|
123
|
+
:type => Array
|
|
124
|
+
|
|
125
|
+
option :keep_artifacts,
|
|
126
|
+
:description => "Don't remove artifacts after building packages",
|
|
127
|
+
:arguments => ['--keep-artifacts'],
|
|
128
|
+
:type => :boolean
|
|
129
|
+
|
|
130
|
+
option :module_template,
|
|
131
|
+
:description => "Path to the template used by the modulepackager",
|
|
132
|
+
:arguments => ['--module-template PATH'],
|
|
133
|
+
:type => String
|
|
134
|
+
|
|
135
|
+
# Handle alternative format that optparser can't parse.
|
|
136
|
+
def post_option_parser(configuration)
|
|
137
|
+
if ARGV.length >= 1
|
|
138
|
+
configuration[:action] = ARGV.delete_at(0)
|
|
139
|
+
|
|
140
|
+
configuration[:target] = ARGV.delete_at(0) || "."
|
|
141
|
+
|
|
142
|
+
if configuration[:action] == "generate"
|
|
143
|
+
unless ARGV[0] && ARGV[0].match(/(actions|outputs)=(.+)/i)
|
|
144
|
+
unless configuration[:pluginname]
|
|
145
|
+
configuration[:pluginname] = ARGV.delete_at(0)
|
|
146
|
+
else
|
|
147
|
+
ARGV.delete_at(0)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
ARGV.each do |argument|
|
|
152
|
+
if argument.match(/(actions|outputs)=(.+)/i)
|
|
153
|
+
configuration[$1.downcase.to_sym]= $2.split(",")
|
|
154
|
+
else
|
|
155
|
+
raise "Could not parse --arg '#{argument}'"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Display info about plugin
|
|
163
|
+
def info_command
|
|
164
|
+
plugin = prepare_plugin
|
|
165
|
+
packager = PluginPackager["#{configuration[:format].capitalize}Packager"]
|
|
166
|
+
packager.new(plugin).package_information
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Generate a plugin skeleton
|
|
170
|
+
def generate_command
|
|
171
|
+
raise "undefined plugin type. cannot generate plugin. valid types are 'agent' and 'data'" if configuration["target"] == '.'
|
|
172
|
+
|
|
173
|
+
unless configuration[:pluginname]
|
|
174
|
+
puts "No plugin name specified. Using 'new_plugin'"
|
|
175
|
+
configuration[:pluginname] = "new_plugin"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
load_plugin_config_values
|
|
179
|
+
|
|
180
|
+
case configuration[:target].downcase
|
|
181
|
+
when 'agent'
|
|
182
|
+
Generators::AgentGenerator.new(configuration[:pluginname], configuration[:actions], configuration[:pluginname],
|
|
183
|
+
configuration[:description], configuration[:author], configuration[:license],
|
|
184
|
+
configuration[:version], configuration[:url], configuration[:timeout])
|
|
185
|
+
when 'data'
|
|
186
|
+
raise "data plugin must have at least one output" unless configuration[:outputs]
|
|
187
|
+
Generators::DataGenerator.new(configuration[:pluginname], configuration[:outputs], configuration[:pluginname],
|
|
188
|
+
configuration[:description], configuration[:author], configuration[:license],
|
|
189
|
+
configuration[:version], configuration[:url], configuration[:timeout])
|
|
190
|
+
else
|
|
191
|
+
raise "invalid plugin type. cannot generate plugin '#{configuration[:target]}'"
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Package plugin
|
|
196
|
+
def package_command
|
|
197
|
+
if configuration[:sign] && Config.instance.pluginconf.include?("debian_packager.keyname")
|
|
198
|
+
configuration[:sign] = Config.instance.pluginconf["debian_packager.keyname"]
|
|
199
|
+
configuration[:sign] = "\"#{configuration[:sign]}\"" unless configuration[:sign].match(/\".*\"/)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
plugin = prepare_plugin
|
|
203
|
+
(configuration[:pluginpath] = configuration[:pluginpath] + "/") if (configuration[:pluginpath] && !configuration[:pluginpath].match(/^.*\/$/))
|
|
204
|
+
packager = PluginPackager["#{configuration[:format].capitalize}Packager"]
|
|
205
|
+
packager.new(plugin, configuration[:pluginpath], configuration[:sign],
|
|
206
|
+
options[:verbose], configuration[:keep_artifacts],
|
|
207
|
+
configuration[:module_template]).create_packages
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# Agents are just called 'agent' but newer plugin types are
|
|
211
|
+
# called plugin_plugintype for example facter_facts etc so
|
|
212
|
+
# this will first try the old way then the new way.
|
|
213
|
+
def load_plugin_ddl(plugin, type)
|
|
214
|
+
[plugin, "#{plugin}_#{type}"].each do |p|
|
|
215
|
+
ddl = DDL.new(p, type, false)
|
|
216
|
+
if ddl.findddlfile(p, type)
|
|
217
|
+
ddl.loadddlfile
|
|
218
|
+
return ddl
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
return nil
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Show application list and plugin help
|
|
226
|
+
def doc_command
|
|
227
|
+
known_plugin_types = [["Agents", :agent], ["Aggregate", :aggregate],
|
|
228
|
+
["Connectors", :connector], ["Data Queries", :data],
|
|
229
|
+
["Discovery Methods", :discovery], ["Validator Plugins", :validator]]
|
|
230
|
+
|
|
231
|
+
if configuration.include?(:target) && configuration[:target] != "."
|
|
232
|
+
if configuration[:target] =~ /^(.+?)\/(.+)$/
|
|
233
|
+
ddl = load_plugin_ddl($2.to_sym, $1)
|
|
234
|
+
else
|
|
235
|
+
found_plugin_type = nil
|
|
236
|
+
|
|
237
|
+
known_plugin_types.each do |plugin_type|
|
|
238
|
+
PluginManager.find(plugin_type[1], "ddl").each do |ddl|
|
|
239
|
+
pluginname = ddl.gsub(/_#{plugin_type[1]}$/, "")
|
|
240
|
+
if pluginname == configuration[:target]
|
|
241
|
+
abort "Duplicate plugin name found, please specify a full path like agent/rpcutil" if found_plugin_type
|
|
242
|
+
found_plugin_type = plugin_type[1]
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
abort "Could not find a plugin named '%s' in any supported plugin type" % configuration[:target] unless found_plugin_type
|
|
248
|
+
ddl = load_plugin_ddl(configuration[:target], found_plugin_type)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
if ddl
|
|
252
|
+
puts ddl.help(configuration[:rpctemplate])
|
|
253
|
+
else
|
|
254
|
+
abort "Could not find a '%s' plugin named '%s'" % configuration[:target].split('/')
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
else
|
|
258
|
+
puts "Please specify a plugin. Available plugins are:"
|
|
259
|
+
puts
|
|
260
|
+
|
|
261
|
+
load_errors = []
|
|
262
|
+
|
|
263
|
+
known_plugin_types.each do |plugin_type|
|
|
264
|
+
puts "%s:" % plugin_type[0]
|
|
265
|
+
|
|
266
|
+
PluginManager.find(plugin_type[1], "ddl").each do |ddl|
|
|
267
|
+
begin
|
|
268
|
+
help = DDL.new(ddl, plugin_type[1])
|
|
269
|
+
pluginname = ddl.gsub(/_#{plugin_type[1]}$/, "")
|
|
270
|
+
puts " %-25s %s" % [pluginname, help.meta[:description]]
|
|
271
|
+
rescue => e
|
|
272
|
+
load_errors << [plugin_type[1], ddl, e]
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
puts
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
unless load_errors.empty?
|
|
280
|
+
puts "Plugin Load Errors:"
|
|
281
|
+
|
|
282
|
+
load_errors.each do |e|
|
|
283
|
+
puts " %-25s %s" % ["#{e[0]}/#{e[1]}", Util.colorize(:yellow, e[2])]
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Creates the correct package plugin object.
|
|
290
|
+
def prepare_plugin
|
|
291
|
+
plugintype = set_plugin_type unless configuration[:plugintype]
|
|
292
|
+
configuration[:format] = "ospackage" unless configuration[:format]
|
|
293
|
+
PluginPackager.load_packagers
|
|
294
|
+
plugin_class = PluginPackager[configuration[:plugintype]]
|
|
295
|
+
|
|
296
|
+
if configuration[:dependency] && configuration[:dependency].size == 1
|
|
297
|
+
configuration[:dependency] = configuration[:dependency][0].split(" ")
|
|
298
|
+
elsif configuration[:dependency]
|
|
299
|
+
configuration[:dependency].map!{|dep| {:name => dep, :version => nil}}
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
mcdependency = {:mcname => configuration[:mcname], :mcversion => configuration[:mcversion]}
|
|
303
|
+
|
|
304
|
+
# Deprecation warning for --iteration
|
|
305
|
+
if configuration[:iteration]
|
|
306
|
+
puts 'Warning. The --iteration flag has been deprecated. Please use --revision instead.'
|
|
307
|
+
configuration[:revision] = configuration[:iteration] unless configuration[:revision]
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
plugin_class.new(configuration, mcdependency, plugintype)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def plugin_directory_exists?(plugin_type)
|
|
314
|
+
File.directory?(File.join(PluginPackager.get_plugin_path(configuration[:target]), plugin_type))
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Identify plugin type if not provided.
|
|
318
|
+
def set_plugin_type
|
|
319
|
+
if plugin_directory_exists?("agent") || plugin_directory_exists?("application")
|
|
320
|
+
configuration[:plugintype] = "AgentDefinition"
|
|
321
|
+
return "Agent"
|
|
322
|
+
elsif plugin_directory_exists?(plugintype = identify_plugin)
|
|
323
|
+
configuration[:plugintype] = "StandardDefinition"
|
|
324
|
+
return plugintype
|
|
325
|
+
else
|
|
326
|
+
raise RuntimeError, "target directory is not a valid mcollective plugin"
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# If plugintype is StandardDefinition, identify which of the special
|
|
331
|
+
# plugin types we are dealing with based on directory structure.
|
|
332
|
+
# To keep it simple we limit it to one type per target directory.
|
|
333
|
+
# Return the name of the type of plugin as a string
|
|
334
|
+
def identify_plugin
|
|
335
|
+
plugintype = Dir.glob(File.join(configuration[:target], "*")).select do |file|
|
|
336
|
+
File.directory?(file) && file.match(/(connector|facts|registration|security|audit|pluginpackager|data|discovery|validator)/)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
raise RuntimeError, "more than one plugin type detected in directory" if plugintype.size > 1
|
|
340
|
+
raise RuntimeError, "no plugins detected in directory" if plugintype.size < 1
|
|
341
|
+
|
|
342
|
+
File.basename(plugintype[0])
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Load preset metadata values from config if they are present
|
|
346
|
+
# This makes it possible to override metadata values in a local
|
|
347
|
+
# client config file.
|
|
348
|
+
#
|
|
349
|
+
# Example : plugin.metadata.license = Apache 2
|
|
350
|
+
def load_plugin_config_values
|
|
351
|
+
config = Config.instance
|
|
352
|
+
[:pluginname, :description, :author, :license, :version, :url, :timeout].each do |confoption|
|
|
353
|
+
configuration[confoption] = config.pluginconf["metadata.#{confoption}"] unless configuration[confoption]
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def main
|
|
358
|
+
abort "No action specified, please run 'mco help plugin' for help" unless configuration.include?(:action)
|
|
359
|
+
|
|
360
|
+
cmd = "#{configuration[:action]}_command"
|
|
361
|
+
|
|
362
|
+
if respond_to? cmd
|
|
363
|
+
send cmd
|
|
364
|
+
else
|
|
365
|
+
abort "Invalid action #{configuration[:action]}, please run 'mco help plugin' for help."
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
end
|