mcollective-client 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/lib/mcollective/agent/discovery.rb +37 -0
  2. data/lib/mcollective/agent/rpcutil.ddl +220 -0
  3. data/lib/mcollective/agent/rpcutil.rb +108 -0
  4. data/lib/mcollective/aggregate/average.ddl +33 -0
  5. data/lib/mcollective/aggregate/average.rb +29 -0
  6. data/lib/mcollective/aggregate/result.rb +3 -3
  7. data/lib/mcollective/aggregate/sum.ddl +33 -0
  8. data/lib/mcollective/aggregate/sum.rb +18 -0
  9. data/lib/mcollective/aggregate/summary.ddl +33 -0
  10. data/lib/mcollective/aggregate/summary.rb +53 -0
  11. data/lib/mcollective/aggregate.rb +2 -2
  12. data/lib/mcollective/application/completion.rb +104 -0
  13. data/lib/mcollective/application/facts.rb +62 -0
  14. data/lib/mcollective/application/find.rb +21 -0
  15. data/lib/mcollective/application/help.rb +28 -0
  16. data/lib/mcollective/application/inventory.rb +344 -0
  17. data/lib/mcollective/application/ping.rb +77 -0
  18. data/lib/mcollective/application/plugin.rb +369 -0
  19. data/lib/mcollective/application/rpc.rb +121 -0
  20. data/lib/mcollective/application.rb +2 -0
  21. data/lib/mcollective/audit/logfile.rb +26 -0
  22. data/lib/mcollective/config.rb +16 -9
  23. data/lib/mcollective/connector/activemq.ddl +9 -0
  24. data/lib/mcollective/connector/activemq.rb +572 -0
  25. data/lib/mcollective/connector/rabbitmq.ddl +9 -0
  26. data/lib/mcollective/connector/rabbitmq.rb +484 -0
  27. data/lib/mcollective/connector.rb +1 -1
  28. data/lib/mcollective/data/agent_data.ddl +22 -0
  29. data/lib/mcollective/data/agent_data.rb +17 -0
  30. data/lib/mcollective/data/collective_data.ddl +20 -0
  31. data/lib/mcollective/data/collective_data.rb +9 -0
  32. data/lib/mcollective/data/fact_data.ddl +28 -0
  33. data/lib/mcollective/data/fact_data.rb +55 -0
  34. data/lib/mcollective/data/fstat_data.ddl +89 -0
  35. data/lib/mcollective/data/fstat_data.rb +56 -0
  36. data/lib/mcollective/data.rb +2 -2
  37. data/lib/mcollective/ddl.rb +4 -4
  38. data/lib/mcollective/discovery/flatfile.ddl +11 -0
  39. data/lib/mcollective/discovery/flatfile.rb +48 -0
  40. data/lib/mcollective/discovery/mc.ddl +11 -0
  41. data/lib/mcollective/discovery/mc.rb +30 -0
  42. data/lib/mcollective/discovery/stdin.ddl +11 -0
  43. data/lib/mcollective/discovery/stdin.rb +66 -0
  44. data/lib/mcollective/facts/yaml_facts.rb +61 -0
  45. data/lib/mcollective/facts.rb +1 -1
  46. data/lib/mcollective/generators.rb +3 -3
  47. data/lib/mcollective/logger.rb +1 -1
  48. data/lib/mcollective/matcher/scanner.rb +1 -1
  49. data/lib/mcollective/matcher.rb +2 -2
  50. data/lib/mcollective/pluginpackager/debpackage_packager.rb +237 -0
  51. data/lib/mcollective/pluginpackager/modulepackage_packager.rb +127 -0
  52. data/lib/mcollective/pluginpackager/ospackage_packager.rb +59 -0
  53. data/lib/mcollective/pluginpackager/rpmpackage_packager.rb +180 -0
  54. data/lib/mcollective/pluginpackager/templates/debian/Makefile.erb +7 -0
  55. data/lib/mcollective/pluginpackager/templates/debian/changelog.erb +5 -0
  56. data/lib/mcollective/pluginpackager/templates/debian/compat.erb +1 -0
  57. data/lib/mcollective/pluginpackager/templates/debian/control.erb +15 -0
  58. data/lib/mcollective/pluginpackager/templates/debian/copyright.erb +8 -0
  59. data/lib/mcollective/pluginpackager/templates/debian/rules.erb +6 -0
  60. data/lib/mcollective/pluginpackager/templates/module/Modulefile.erb +5 -0
  61. data/lib/mcollective/pluginpackager/templates/module/README.md.erb +37 -0
  62. data/lib/mcollective/pluginpackager/templates/module/_manifest.pp.erb +9 -0
  63. data/lib/mcollective/pluginpackager/templates/redhat/rpm_spec.erb +63 -0
  64. data/lib/mcollective/pluginpackager.rb +2 -2
  65. data/lib/mcollective/registration/agentlist.rb +10 -0
  66. data/lib/mcollective/registration.rb +1 -1
  67. data/lib/mcollective/rpc/stats.rb +0 -1
  68. data/lib/mcollective/rpc.rb +11 -11
  69. data/lib/mcollective/security/aes_security.rb +394 -0
  70. data/lib/mcollective/security/psk.rb +117 -0
  71. data/lib/mcollective/security/ssl.rb +328 -0
  72. data/lib/mcollective/security.rb +1 -1
  73. data/lib/mcollective/util.rb +18 -18
  74. data/lib/mcollective/validator/array_validator.ddl +7 -0
  75. data/lib/mcollective/validator/array_validator.rb +9 -0
  76. data/lib/mcollective/validator/ipv4address_validator.ddl +7 -0
  77. data/lib/mcollective/validator/ipv4address_validator.rb +16 -0
  78. data/lib/mcollective/validator/ipv6address_validator.ddl +7 -0
  79. data/lib/mcollective/validator/ipv6address_validator.rb +16 -0
  80. data/lib/mcollective/validator/length_validator.ddl +7 -0
  81. data/lib/mcollective/validator/length_validator.rb +11 -0
  82. data/lib/mcollective/validator/regex_validator.ddl +7 -0
  83. data/lib/mcollective/validator/regex_validator.rb +9 -0
  84. data/lib/mcollective/validator/shellsafe_validator.ddl +7 -0
  85. data/lib/mcollective/validator/shellsafe_validator.rb +13 -0
  86. data/lib/mcollective/validator/typecheck_validator.ddl +7 -0
  87. data/lib/mcollective/validator/typecheck_validator.rb +28 -0
  88. data/lib/mcollective.rb +31 -31
  89. data/spec/spec_helper.rb +0 -5
  90. data/spec/unit/{plugins/mcollective → mcollective}/agent/rpcutil_spec.rb +1 -1
  91. data/spec/unit/{agents_spec.rb → mcollective/agents_spec.rb} +0 -0
  92. data/spec/unit/{plugins/mcollective → mcollective}/aggregate/average_spec.rb +1 -1
  93. data/spec/unit/{aggregate → mcollective/aggregate}/base_spec.rb +0 -0
  94. data/spec/unit/{aggregate → mcollective/aggregate}/result/base_spec.rb +0 -0
  95. data/spec/unit/{aggregate → mcollective/aggregate}/result/collection_result_spec.rb +0 -0
  96. data/spec/unit/{aggregate → mcollective/aggregate}/result/numeric_result_spec.rb +0 -0
  97. data/spec/unit/{plugins/mcollective → mcollective}/aggregate/sum_spec.rb +1 -1
  98. data/spec/unit/{plugins/mcollective → mcollective}/aggregate/summary_spec.rb +1 -1
  99. data/spec/unit/{aggregate_spec.rb → mcollective/aggregate_spec.rb} +0 -0
  100. data/spec/unit/{plugins/mcollective → mcollective}/application/plugin_spec.rb +1 -1
  101. data/spec/unit/{application_spec.rb → mcollective/application_spec.rb} +0 -0
  102. data/spec/unit/{applications_spec.rb → mcollective/applications_spec.rb} +1 -1
  103. data/spec/unit/{array_spec.rb → mcollective/array_spec.rb} +0 -0
  104. data/spec/unit/{plugins/mcollective → mcollective}/audit/logfile_spec.rb +1 -1
  105. data/spec/unit/{cache_spec.rb → mcollective/cache_spec.rb} +0 -0
  106. data/spec/unit/{client_spec.rb → mcollective/client_spec.rb} +0 -0
  107. data/spec/unit/{config_spec.rb → mcollective/config_spec.rb} +12 -7
  108. data/spec/unit/{plugins/mcollective → mcollective}/connector/activemq_spec.rb +1 -1
  109. data/spec/unit/{connector → mcollective/connector}/base_spec.rb +0 -0
  110. data/spec/unit/{plugins/mcollective → mcollective}/connector/rabbitmq_spec.rb +1 -1
  111. data/spec/unit/{plugins/mcollective → mcollective}/data/agent_data_spec.rb +1 -1
  112. data/spec/unit/{data → mcollective/data}/base_spec.rb +0 -0
  113. data/spec/unit/{plugins/mcollective → mcollective}/data/collective_data_spec.rb +1 -1
  114. data/spec/unit/{plugins/mcollective → mcollective}/data/fact_data_spec.rb +1 -1
  115. data/spec/unit/{plugins/mcollective → mcollective}/data/fstat_data_spec.rb +1 -1
  116. data/spec/unit/{data → mcollective/data}/result_spec.rb +0 -0
  117. data/spec/unit/{data_spec.rb → mcollective/data_spec.rb} +0 -0
  118. data/spec/unit/{ddl → mcollective/ddl}/agentddl_spec.rb +0 -0
  119. data/spec/unit/{ddl → mcollective/ddl}/base_spec.rb +0 -0
  120. data/spec/unit/{ddl → mcollective/ddl}/dataddl_spec.rb +0 -0
  121. data/spec/unit/{ddl → mcollective/ddl}/discoveryddl_spec.rb +0 -0
  122. data/spec/unit/{ddl_spec.rb → mcollective/ddl_spec.rb} +0 -0
  123. data/spec/unit/{plugins/mcollective → mcollective}/discovery/flatfile_spec.rb +1 -1
  124. data/spec/unit/{plugins/mcollective → mcollective}/discovery/mc_spec.rb +1 -1
  125. data/spec/unit/{plugins/mcollective → mcollective}/discovery/stdin_spec.rb +1 -1
  126. data/spec/unit/{discovery_spec.rb → mcollective/discovery_spec.rb} +0 -0
  127. data/spec/unit/{facts → mcollective/facts}/base_spec.rb +0 -0
  128. data/spec/unit/{plugins/mcollective → mcollective}/facts/yaml_facts_spec.rb +1 -1
  129. data/spec/unit/{facts_spec.rb → mcollective/facts_spec.rb} +0 -0
  130. data/spec/unit/{generators → mcollective/generators}/agent_generator_spec.rb +0 -0
  131. data/spec/unit/{generators → mcollective/generators}/base_spec.rb +0 -0
  132. data/spec/unit/{generators → mcollective/generators}/data_generator_spec.rb +0 -0
  133. data/spec/unit/{generators → mcollective/generators}/snippets/agent_ddl +0 -0
  134. data/spec/unit/{generators → mcollective/generators}/snippets/data_ddl +0 -0
  135. data/spec/unit/{log_spec.rb → mcollective/log_spec.rb} +0 -0
  136. data/spec/unit/{logger → mcollective/logger}/base_spec.rb +0 -0
  137. data/spec/unit/{logger → mcollective/logger}/console_logger_spec.rb +0 -0
  138. data/spec/unit/{logger → mcollective/logger}/file_logger_spec.rb +0 -0
  139. data/spec/unit/{logger → mcollective/logger}/syslog_logger_spec.rb +0 -0
  140. data/spec/unit/{matcher → mcollective/matcher}/parser_spec.rb +0 -0
  141. data/spec/unit/{matcher → mcollective/matcher}/scanner_spec.rb +0 -0
  142. data/spec/unit/{matcher_spec.rb → mcollective/matcher_spec.rb} +0 -0
  143. data/spec/unit/{message_spec.rb → mcollective/message_spec.rb} +0 -0
  144. data/spec/unit/{monkey_patches_spec.rb → mcollective/monkey_patches_spec.rb} +0 -0
  145. data/spec/unit/{optionparser_spec.rb → mcollective/optionparser_spec.rb} +0 -0
  146. data/spec/unit/{plugins/mcollective → mcollective}/packagers/debpackage_packager_spec.rb +1 -1
  147. data/spec/unit/{plugins/mcollective → mcollective}/packagers/modulepackage_packager_spec.rb +1 -1
  148. data/spec/unit/{plugins/mcollective → mcollective}/packagers/ospackage_spec.rb +1 -1
  149. data/spec/unit/{plugins/mcollective → mcollective}/packagers/rpmpackage_packager_spec.rb +1 -1
  150. data/spec/unit/{pluginmanager_spec.rb → mcollective/pluginmanager_spec.rb} +0 -0
  151. data/spec/unit/{pluginpackager → mcollective/pluginpackager}/agent_definition_spec.rb +0 -0
  152. data/spec/unit/{pluginpackager → mcollective/pluginpackager}/standard_definition_spec.rb +0 -0
  153. data/spec/unit/{pluginpackager_spec.rb → mcollective/pluginpackager_spec.rb} +0 -0
  154. data/spec/unit/{registration → mcollective/registration}/base_spec.rb +0 -0
  155. data/spec/unit/{rpc → mcollective/rpc}/actionrunner_spec.rb +0 -0
  156. data/spec/unit/{rpc → mcollective/rpc}/agent_spec.rb +0 -0
  157. data/spec/unit/{rpc → mcollective/rpc}/client_spec.rb +0 -0
  158. data/spec/unit/{rpc → mcollective/rpc}/helpers_spec.rb +0 -0
  159. data/spec/unit/{rpc → mcollective/rpc}/reply_spec.rb +0 -0
  160. data/spec/unit/{rpc → mcollective/rpc}/request_spec.rb +0 -0
  161. data/spec/unit/{rpc → mcollective/rpc}/result_spec.rb +0 -0
  162. data/spec/unit/{rpc → mcollective/rpc}/stats_spec.rb +0 -0
  163. data/spec/unit/{rpc_spec.rb → mcollective/rpc_spec.rb} +0 -0
  164. data/spec/unit/{runner_spec.rb → mcollective/runner_spec.rb} +0 -0
  165. data/spec/unit/{runnerstats_spec.rb → mcollective/runnerstats_spec.rb} +0 -0
  166. data/spec/unit/{plugins/mcollective → mcollective}/security/aes_security_spec.rb +1 -1
  167. data/spec/unit/{security → mcollective/security}/base_spec.rb +0 -0
  168. data/spec/unit/{plugins/mcollective → mcollective}/security/psk_spec.rb +1 -1
  169. data/spec/unit/{shell_spec.rb → mcollective/shell_spec.rb} +0 -0
  170. data/spec/unit/{ssl_spec.rb → mcollective/ssl_spec.rb} +12 -12
  171. data/spec/unit/{string_spec.rb → mcollective/string_spec.rb} +0 -0
  172. data/spec/unit/{symbol_spec.rb → mcollective/symbol_spec.rb} +0 -0
  173. data/spec/unit/{unix_daemon_spec.rb → mcollective/unix_daemon_spec.rb} +0 -0
  174. data/spec/unit/{util_spec.rb → mcollective/util_spec.rb} +28 -6
  175. data/spec/unit/{plugins/mcollective → mcollective}/validator/array_validator_spec.rb +1 -1
  176. data/spec/unit/{plugins/mcollective → mcollective}/validator/ipv4address_validator_spec.rb +1 -1
  177. data/spec/unit/{plugins/mcollective → mcollective}/validator/ipv6address_validator_spec.rb +1 -1
  178. data/spec/unit/{plugins/mcollective → mcollective}/validator/length_validator_spec.rb +1 -1
  179. data/spec/unit/{plugins/mcollective → mcollective}/validator/regex_validator_spec.rb +1 -1
  180. data/spec/unit/{plugins/mcollective → mcollective}/validator/shellsafe_validator_spec.rb +1 -1
  181. data/spec/unit/{plugins/mcollective → mcollective}/validator/typecheck_validator_spec.rb +1 -1
  182. data/spec/unit/{validator_spec.rb → mcollective/validator_spec.rb} +1 -1
  183. data/spec/unit/{vendor_spec.rb → mcollective/vendor_spec.rb} +2 -2
  184. data/spec/unit/{windows_daemon_spec.rb → mcollective/windows_daemon_spec.rb} +0 -0
  185. metadata +361 -284
  186. checksums.yaml +0 -7
@@ -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
@@ -0,0 +1,121 @@
1
+ class MCollective::Application::Rpc<MCollective::Application
2
+ description "Generic RPC agent client application"
3
+
4
+ usage "mco rpc [options] [filters] --agent <agent> --action <action> [--argument <key=val> --argument ...]"
5
+ usage "mco rpc [options] [filters] <agent> <action> [<key=val> <key=val> ...]"
6
+
7
+ option :show_results,
8
+ :description => "Do not process results, just send request",
9
+ :arguments => ["--no-results", "--nr"],
10
+ :default => true,
11
+ :type => :bool
12
+
13
+ option :agent,
14
+ :description => "Agent to call",
15
+ :arguments => ["-a", "--agent AGENT"]
16
+
17
+ option :action,
18
+ :description => "Action to call",
19
+ :arguments => ["--action ACTION"]
20
+
21
+ option :arguments,
22
+ :description => "Arguments to pass to agent",
23
+ :arguments => ["--arg", "--argument ARGUMENT"],
24
+ :type => :array,
25
+ :default => [],
26
+ :validate => Proc.new {|val| val.match(/^(.+?)=(.+)$/) ? true : "Could not parse --arg #{val} should be of the form key=val" }
27
+
28
+ def post_option_parser(configuration)
29
+ # handle the alternative format that optparse cant parse
30
+ unless (configuration.include?(:agent) && configuration.include?(:action))
31
+ if ARGV.length >= 2
32
+ configuration[:agent] = ARGV[0]
33
+ ARGV.delete_at(0)
34
+
35
+ configuration[:action] = ARGV[0]
36
+ ARGV.delete_at(0)
37
+
38
+ ARGV.each do |v|
39
+ if v =~ /^(.+?)=(.+)$/
40
+ configuration[:arguments] = [] unless configuration.include?(:arguments)
41
+ configuration[:arguments] << v
42
+ else
43
+ STDERR.puts("Could not parse --arg #{v}")
44
+ exit(1)
45
+ end
46
+ end
47
+ else
48
+ STDERR.puts("No agent, action and arguments specified")
49
+ exit(1)
50
+ end
51
+ end
52
+
53
+ # convert arguments to symbols for keys to comply with simplerpc conventions
54
+ args = configuration[:arguments].clone
55
+ configuration[:arguments] = {}
56
+
57
+ args.each do |v|
58
+ if v =~ /^(.+?)=(.+)$/
59
+ configuration[:arguments][$1.to_sym] = $2
60
+ end
61
+ end
62
+ end
63
+
64
+ def string_to_ddl_type(arguments, ddl)
65
+ return if ddl.empty?
66
+
67
+ arguments.keys.each do |key|
68
+ if ddl[:input].keys.include?(key)
69
+ case ddl[:input][key][:type]
70
+ when :boolean
71
+ arguments[key] = MCollective::DDL.string_to_boolean(arguments[key])
72
+
73
+ when :number, :integer, :float
74
+ arguments[key] = MCollective::DDL.string_to_number(arguments[key])
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def main
81
+ mc = rpcclient(configuration[:agent])
82
+
83
+ mc.agent_filter(configuration[:agent])
84
+
85
+ string_to_ddl_type(configuration[:arguments], mc.ddl.action_interface(configuration[:action])) if mc.ddl
86
+
87
+ mc.validate_request(configuration[:action], configuration[:arguments])
88
+
89
+ if mc.reply_to
90
+ configuration[:arguments][:process_results] = true
91
+
92
+ puts "Request sent with id: " + mc.send(configuration[:action], configuration[:arguments]) + " replies to #{mc.reply_to}"
93
+ elsif !configuration[:show_results]
94
+ configuration[:arguments][:process_results] = false
95
+
96
+ puts "Request sent with id: " + mc.send(configuration[:action], configuration[:arguments])
97
+ else
98
+ discover_args = {:verbose => true}
99
+ # IF the discovery method hasn't been explicitly overridden
100
+ # and we're not being run interactively,
101
+ # and someone has piped us some data
102
+ # Then we assume it's a discovery list - this can be either:
103
+ # - list of hosts in plaintext
104
+ # - JSON that came from another rpc or printrpc
105
+ if mc.default_discovery_method && !STDIN.tty? && !STDIN.eof?
106
+ # Then we override discovery to try to grok the data on STDIN
107
+ mc.discovery_method = 'stdin'
108
+ mc.discovery_options = 'auto'
109
+ discover_args = {:verbose => false}
110
+ end
111
+
112
+ mc.discover discover_args
113
+
114
+ printrpc mc.send(configuration[:action], configuration[:arguments])
115
+
116
+ printrpcstats :summarize => true, :caption => "#{configuration[:agent]}##{configuration[:action]} call stats" if mc.discover.size > 0
117
+
118
+ halt mc.stats
119
+ end
120
+ end
121
+ end
@@ -1,3 +1,5 @@
1
+ require 'mcollective/rpc'
2
+
1
3
  module MCollective
2
4
  class Application
3
5
  include RPC
@@ -0,0 +1,26 @@
1
+ module MCollective
2
+ module RPC
3
+ # An audit plugin that just logs to a file
4
+ #
5
+ # You can configure which file it logs to with the setting
6
+ #
7
+ # plugin.rpcaudit.logfile
8
+
9
+ class Logfile<Audit
10
+ require 'pp'
11
+
12
+ def audit_request(request, connection)
13
+ logfile = Config.instance.pluginconf["rpcaudit.logfile"] || "/var/log/mcollective-audit.log"
14
+
15
+ now = Time.now
16
+ # Already told timezone to be in UTC so we don't look it up again
17
+ # This avoids platform specific timezone representation issues
18
+ now_iso8601 = now.utc.strftime("%Y-%m-%d %H:%M:%S UTC")
19
+
20
+ File.open(logfile, "a") do |f|
21
+ f.puts("[#{now_iso8601}] reqid=#{request.uniqid}: reqtime=#{request.time} caller=#{request.caller}@#{request.sender} agent=#{request.agent} action=#{request.action} data=#{request.data.pretty_print_inspect}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -5,7 +5,7 @@ module MCollective
5
5
 
6
6
  attr_accessor :mode
7
7
 
8
- attr_reader :daemonize, :pluginconf, :libdir, :configured
8
+ attr_reader :daemonize, :pluginconf, :configured
9
9
  attr_reader :logfile, :keeplogs, :max_log_size, :loglevel, :logfacility
10
10
  attr_reader :identity, :daemonize, :connector, :securityprovider, :factsource
11
11
  attr_reader :registration, :registerinterval, :classesfile
@@ -27,6 +27,7 @@ module MCollective
27
27
  set_config_defaults(configfile)
28
28
 
29
29
  if File.exists?(configfile)
30
+ libdirs = []
30
31
  File.readlines(configfile).each do |line|
31
32
 
32
33
  # strip blank spaces, tabs etc off the end of all lines
@@ -66,10 +67,7 @@ module MCollective
66
67
  paths.each do |path|
67
68
  raise("libdir paths should be absolute paths but '%s' is relative" % path) unless Util.absolute_path?(path)
68
69
 
69
- @libdir << path
70
- unless $LOAD_PATH.include?(path)
71
- $LOAD_PATH << path
72
- end
70
+ libdirs << path
73
71
  end
74
72
  when "identity"
75
73
  @identity = val
@@ -139,15 +137,21 @@ module MCollective
139
137
  end
140
138
  end
141
139
 
142
- raise('The %s config file does not specify a libdir setting, cannot continue' % configfile) if @libdir.empty?
143
-
144
140
  read_plugin_config_dir("#{@configdir}/plugin.d")
145
141
 
146
142
  raise 'Identities can only match /\w\.\-/' unless @identity.match(/^[\w\.\-]+$/)
147
143
 
148
144
  @configured = true
149
145
 
150
- @libdir.each {|dir| Log.warn("Cannot find libdir: #{dir}") unless File.directory?(dir)}
146
+ libdirs.each do |dir|
147
+ unless File.directory?(dir)
148
+ Log.warn("Cannot find libdir: #{dir}")
149
+ end
150
+
151
+ # remove the old one if it exists, we're moving it to the front
152
+ $LOAD_PATH.reject! { |elem| elem == dir }
153
+ $LOAD_PATH.unshift dir
154
+ end
151
155
 
152
156
  if @logger_type == "syslog"
153
157
  raise "The sylog logger is not usable on the Windows platform" if Util.windows?
@@ -190,7 +194,6 @@ module MCollective
190
194
  @keeplogs = 5
191
195
  @max_log_size = 2097152
192
196
  @rpclimitmethod = :first
193
- @libdir = Array.new
194
197
  @fact_cache_time = 300
195
198
  @loglevel = "info"
196
199
  @logfacility = "user"
@@ -211,6 +214,10 @@ module MCollective
211
214
  @connection_timeout = nil
212
215
  end
213
216
 
217
+ def libdir
218
+ $LOAD_PATH
219
+ end
220
+
214
221
  def read_plugin_config_dir(dir)
215
222
  return unless File.directory?(dir)
216
223
 
@@ -0,0 +1,9 @@
1
+ metadata :name => "ActiveMQ Connector",
2
+ :description => "Connector plugin for ActiveMQ middleware",
3
+ :author => "Puppet Labs",
4
+ :license => "ASL 2.0",
5
+ :version => "1.0.0",
6
+ :url => "http://projects.puppetlabs.com/projects/mcollective-plugins/wiki",
7
+ :timeout => 60
8
+
9
+ requires :mcollective => "2.6.0"