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,237 @@
1
+ module MCollective
2
+ module PluginPackager
3
+ class DebpackagePackager
4
+ require 'erb'
5
+
6
+ def initialize(plugin, pluginpath = nil, signature = nil, verbose = false, keep_artifacts = nil, module_template = nil)
7
+ if PluginPackager.command_available?('debuild')
8
+ @plugin = plugin
9
+ @verbose = verbose
10
+ @libdir = pluginpath || '/usr/share/mcollective/plugins/mcollective/'
11
+ @signature = signature
12
+ @package_name = "#{@plugin.mcname}-#{@plugin.metadata[:name]}"
13
+ @keep_artifacts = keep_artifacts
14
+ else
15
+ raise("Cannot build package. 'debuild' is not present on the system.")
16
+ end
17
+ end
18
+
19
+ # Build process :
20
+ # - create buildroot
21
+ # - craete buildroot/debian
22
+ # - create the relative directories with package contents
23
+ # - create install files for each of the plugins that are going to be built
24
+ # - create debian build files
25
+ # - create tarball
26
+ # - create pre and post install files
27
+ # - run the build script
28
+ # - move packages to cwd
29
+ # - clean up
30
+ def create_packages
31
+ begin
32
+ puts "Building packages for #{@package_name} plugin."
33
+
34
+ @tmpdir = Dir.mktmpdir('mcollective_packager')
35
+ @build_dir = File.join(@tmpdir, "#{@package_name}_#{@plugin.metadata[:version]}")
36
+ Dir.mkdir(@build_dir)
37
+
38
+ create_debian_dir
39
+ @plugin.packagedata.each do |type, data|
40
+ prepare_tmpdirs(data)
41
+ create_install_file(type, data)
42
+ create_pre_and_post_install(type)
43
+ end
44
+ create_debian_files
45
+ create_tar
46
+ run_build
47
+ move_packages
48
+
49
+ puts "Completed building all packages for #{@package_name} plugin."
50
+ ensure
51
+ if @keep_artifacts
52
+ puts 'Keeping build artifacts.'
53
+ puts "Build artifacts saved - #{@tmpdir}"
54
+ else
55
+ puts 'Removing build artifacts.'
56
+ cleanup_tmpdirs
57
+ end
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def create_debian_files
64
+ ['control', 'Makefile', 'compat', 'rules', 'copyright', 'changelog'].each do |f|
65
+ create_file(f)
66
+ end
67
+ end
68
+
69
+ def run_build
70
+ FileUtils.cd(@build_dir) do
71
+ PluginPackager.execute_verbosely(@verbose) do
72
+ if @signature
73
+ if @signature.is_a?(String)
74
+ PluginPackager.safe_system("debuild --no-lintian -i -k#{@signature}")
75
+ else
76
+ PluginPackager.safe_system("debuild --no-lintian -i")
77
+ end
78
+ else
79
+ PluginPackager.safe_system("debuild --no-lintian -i -us -uc")
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ # Creates a string used by the control file to specify dependencies
86
+ # Dependencies can be formatted as :
87
+ # foo (>= x.x-x)
88
+ # foo (>= x.x)
89
+ # foo
90
+ def build_dependency_string(data)
91
+ dependencies = []
92
+ PluginPackager.filter_dependencies('debian', data[:dependencies]).each do |dep|
93
+ if dep[:version] && dep[:revision]
94
+ dependencies << "#{dep[:name]} (>=#{dep[:version]}-#{dep[:revision]})"
95
+ elsif dep[:version]
96
+ dependencies << "#{dep[:name]} (>=#{dep[:version]})"
97
+ else
98
+ dependencies << dep[:name]
99
+ end
100
+ end
101
+
102
+ if data[:plugindependency]
103
+ dependencies << "#{data[:plugindependency][:name]} (= ${binary:Version})"
104
+ end
105
+
106
+ dependencies.join(', ')
107
+ end
108
+
109
+ # Creates an install file for each of the packages that are going to be created
110
+ # for the plugin
111
+ def create_install_file(type, data)
112
+ install_file = "#{@package_name}-#{type}"
113
+ begin
114
+ install_file = File.join(@build_dir, 'debian', "#{install_file}.install")
115
+ File.open(install_file, 'w') do |file|
116
+ data[:files].each do |f|
117
+ extended_filename = File.join(@libdir, File.expand_path(f).gsub(/^#{@plugin.target_path}/, ''))
118
+ file.puts "#{extended_filename} #{File.dirname(extended_filename)}"
119
+ end
120
+ end
121
+ rescue Errno::EACCES => e
122
+ puts "Could not create install file '#{install_file}'. Permission denied"
123
+ raise e
124
+ rescue => e
125
+ puts "Could not create install file '#{install_file}'."
126
+ raise e
127
+ end
128
+ end
129
+
130
+ # Move source package and debs to cwd
131
+ def move_packages
132
+ begin
133
+ files_to_copy = Dir.glob(File.join(@tmpdir, '*.{deb,dsc,diff.gz,orig.tar.gz,changes}'))
134
+ FileUtils.cp(files_to_copy, '.')
135
+ rescue => e
136
+ puts 'Could not copy packages to working directory.'
137
+ raise e
138
+ end
139
+ end
140
+
141
+ # Create pre and post install files in $buildroot/debian
142
+ # from supplied scripts.
143
+ # Note that all packages built for the plugin will invoke
144
+ # the same pre and post install scripts.
145
+ def create_pre_and_post_install(type)
146
+ if @plugin.preinstall
147
+ if !File.exists?(@plugin.preinstall)
148
+ puts "pre-install script '#{@plugin.preinstall}' not found."
149
+ raise(Errno::ENOENT, @plugin.preinstall)
150
+ else
151
+ FileUtils.cp(@plugin.preinstall, File.join(@build_dir, 'debian', "#{@package_name}-#{type}.preinst"))
152
+ end
153
+ end
154
+
155
+ if @plugin.postinstall
156
+ if !File.exists?(@plugin.postinstall)
157
+ puts "post-install script '#{@plugin.postinstall}' not found."
158
+ raise(Errno::ENOENT, @plugin.postinstall)
159
+ else
160
+ FileUtils.cp(@plugin.postinstall, File.join(@build_dir, 'debian', "#{@package_name}-#{type}.postinst"))
161
+ end
162
+ end
163
+ end
164
+
165
+ # Tar up source
166
+ # Expects directory : $mcollective-$agent_$version
167
+ # Creates file : $buildroot/$mcollective-$agent_$version.orig.tar.gz
168
+ def create_tar
169
+ name_and_version = "#{@package_name}_#{@plugin.metadata[:version]}"
170
+ tarfile = "#{name_and_version}.orig.tar.gz"
171
+ begin
172
+ PluginPackager.execute_verbosely(@verbose) do
173
+ Dir.chdir(@tmpdir) do
174
+ PluginPackager.safe_system("tar -Pcvzf #{File.join(@tmpdir, tarfile)} #{name_and_version}")
175
+ end
176
+ end
177
+ rescue Exception => e
178
+ puts "Could not create tarball - #{tarfile}"
179
+ raise e
180
+ end
181
+ end
182
+
183
+ def create_file(filename)
184
+ begin
185
+ file = ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', 'debian', "#{filename}.erb")), nil, '-')
186
+ File.open(File.join(@build_dir, 'debian', filename), 'w') do |f|
187
+ f.puts file.result(binding)
188
+ end
189
+ rescue => e
190
+ puts "Could not create file - '#{filename}'"
191
+ raise e
192
+ end
193
+ end
194
+
195
+ # Move files contained in the plugin to the correct directory
196
+ # relative to the build root.
197
+ def prepare_tmpdirs(data)
198
+ data[:files].each do |file|
199
+ begin
200
+ targetdir = File.join(@build_dir, @libdir, File.dirname(File.expand_path(file)).gsub(/^#{@plugin.target_path}/, ""))
201
+ FileUtils.mkdir_p(targetdir) unless File.directory?(targetdir)
202
+ FileUtils.cp_r(file, targetdir)
203
+ rescue Errno::EACCES => e
204
+ puts "Could not create directory '#{targetdir}'. Permission denied"
205
+ raise e
206
+ rescue Errno::ENOENT => e
207
+ puts "Could not copy file '#{file}' to '#{targetdir}'. File does not exist"
208
+ raise e
209
+ rescue => e
210
+ puts 'Could not prepare build directory'
211
+ raise e
212
+ end
213
+ end
214
+ end
215
+
216
+ # Create the $buildroot/debian directory
217
+ def create_debian_dir
218
+ deb_dir = File.join(@build_dir, 'debian')
219
+ begin
220
+ FileUtils.mkdir_p(deb_dir)
221
+ rescue => e
222
+ puts "Could not create directory '#{deb_dir}'"
223
+ raise e
224
+ end
225
+ end
226
+
227
+ def cleanup_tmpdirs
228
+ begin
229
+ FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
230
+ rescue => e
231
+ puts "Could not remove temporary build directory - '#{@tmpdir}'"
232
+ raise e
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,127 @@
1
+ module MCollective
2
+ module PluginPackager
3
+ class ModulepackagePackager
4
+ require 'erb'
5
+
6
+ def initialize(plugin, pluginpath = nil, signature = nil, verbose = false, keep_artifacts = nil, module_template = nil)
7
+ assert_new_enough_puppet
8
+ @plugin = plugin
9
+ @package_name = "#{@plugin.mcname}_#{@plugin.metadata[:name]}".gsub(/-/, '_')
10
+ @verbose = verbose
11
+ @keep_artifacts = keep_artifacts
12
+ @module_template = module_template || File.join(File.dirname(__FILE__), 'templates', 'module')
13
+ end
14
+
15
+ # Build Process :
16
+ # - create module directory
17
+ # - run 'puppet module build'
18
+ # - move generated package back to cwd
19
+ def create_packages
20
+ begin
21
+ puts "Building module for #{@package_name} plugin."
22
+
23
+ @tmpdir = Dir.mktmpdir('mcollective_packager')
24
+ make_module
25
+ run_build
26
+ move_package
27
+
28
+ puts "Completed building module for #{@package_name} plugin."
29
+ ensure
30
+ if @keep_artifacts
31
+ puts 'Keeping build artifacts'
32
+ puts "Build artifacts saved - #{@tmpdir}"
33
+ else
34
+ cleanup_tmpdirs
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def assert_new_enough_puppet
42
+ unless PluginPackager.command_available?('puppet')
43
+ raise("Cannot build package. 'puppet' is not present on the system.")
44
+ end
45
+
46
+ s = Shell.new('puppet --version')
47
+ s.runcommand
48
+ actual_version = s.stdout.chomp
49
+
50
+ required_version = '3.3.0'
51
+ if Util.versioncmp(actual_version, required_version) < 0
52
+ raise("Cannot build package. puppet #{required_version} or greater required. We have #{actual_version}.")
53
+ end
54
+ end
55
+
56
+ def make_module
57
+ targetdir = File.join(@tmpdir, 'manifests')
58
+ FileUtils.mkdir_p(targetdir) unless File.directory?(targetdir)
59
+
60
+ # for each subpackage make a subclass
61
+ @plugin.packagedata.each do |klass,data|
62
+ data[:files].each do |file|
63
+ relative_path = File.expand_path(file).gsub(/#{@plugin.target_path}|^\.\//, '')
64
+ targetdir = File.join(@tmpdir, 'files', klass.to_s, 'mcollective', File.dirname(relative_path))
65
+ FileUtils.mkdir_p(targetdir) unless File.directory?(targetdir)
66
+ FileUtils.cp_r(file, targetdir)
67
+ end
68
+
69
+ @klass = klass.to_s
70
+ render_template('_manifest.pp.erb', File.join(@tmpdir, 'manifests', "#{klass}.pp"))
71
+ end
72
+
73
+ # render all the templates we have
74
+ Dir.glob(File.join(@module_template, '*.erb')).each do |template|
75
+ filename = File.basename(template, '.erb')
76
+ next if filename =~ /^_/ # starting with underscore makes it private
77
+ render_template("#{filename}.erb", File.join(@tmpdir, filename))
78
+ end
79
+ end
80
+
81
+ def render_template(template, path)
82
+ begin
83
+ erb = ERB.new(File.read(File.join(@module_template, template)), nil, '-')
84
+ File.open(path, 'w') do |f|
85
+ f.puts erb.result(binding)
86
+ end
87
+ rescue => e
88
+ puts "Could not render template to path - '#{path}'"
89
+ raise e
90
+ end
91
+ end
92
+
93
+ def run_build
94
+ begin
95
+ PluginPackager.execute_verbosely(@verbose) do
96
+ Dir.chdir(@tmpdir) do
97
+ PluginPackager.safe_system('puppet module build')
98
+ end
99
+ end
100
+ rescue => e
101
+ puts 'Build process has failed'
102
+ raise e
103
+ end
104
+ end
105
+
106
+ # Move built package to cwd
107
+ def move_package
108
+ begin
109
+ package_file = File.join(@tmpdir, 'pkg', "#{@plugin.vendor}-#{@package_name}-#{@plugin.metadata[:version]}.tar.gz")
110
+ FileUtils.cp(package_file, '.')
111
+ rescue => e
112
+ puts 'Could not copy package to working directory'
113
+ raise e
114
+ end
115
+ end
116
+
117
+ def cleanup_tmpdirs
118
+ begin
119
+ FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
120
+ rescue => e
121
+ puts "Could not remove temporary build directory - '#{@tmpdir}'"
122
+ raise e
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,59 @@
1
+ module MCollective
2
+ module PluginPackager
3
+ # MCollective plugin packager general OS implementation.
4
+ class OspackagePackager
5
+
6
+ attr_accessor :package, :verbose, :packager, :package_type
7
+
8
+ # Create packager object with package parameter containing list of files,
9
+ # dependencies and package metadata.
10
+ def initialize(package, pluginpath = nil, signature = nil, verbose = false, keep_artifacts = false, module_template = nil)
11
+
12
+ if File.exists?("/etc/redhat-release")
13
+ @packager = PluginPackager["RpmpackagePackager"].new(package, pluginpath, signature, verbose, keep_artifacts, module_template)
14
+ @package_type = "RPM"
15
+ elsif File.exists?("/etc/debian_version")
16
+ @packager = PluginPackager["DebpackagePackager"].new(package, pluginpath, signature, verbose, keep_artifacts, module_template)
17
+ @package_type = "Deb"
18
+ else
19
+ raise "cannot identify operating system."
20
+ end
21
+
22
+ @package = package
23
+ @verbose = verbose
24
+ end
25
+
26
+ # Hands over package creation to the detected packager implementation
27
+ # based on operating system.
28
+ def create_packages
29
+ @packager.create_packages
30
+ end
31
+
32
+ # Displays the package metadata and detected files
33
+ def package_information
34
+ puts
35
+ puts "%30s%s" % ["Plugin information : ", @package.metadata[:name]]
36
+ puts "%30s%s" % ["-" * 22, "-" * 22]
37
+ puts "%30s%s" % ["Plugin Type : ", @package.plugintype.capitalize]
38
+ puts "%30s%s" % ["Package Output Format : ", @package_type]
39
+ puts "%30s%s" % ["Version : ", @package.metadata[:version]]
40
+ puts "%30s%s" % ["Revision : ", @package.revision]
41
+ puts "%30s%s" % ["Vendor : ", @package.vendor]
42
+ puts "%30s%s" % ["Post Install Script : ", @package.postinstall] if @package.postinstall
43
+ puts "%30s%s" % ["Author : ", @package.metadata[:author]]
44
+ puts "%30s%s" % ["License : ", @package.metadata[:license]]
45
+ puts "%30s%s" % ["URL : ", @package.metadata[:url]]
46
+
47
+ if @package.packagedata.size > 0
48
+ @package.packagedata.each_with_index do |values, i|
49
+ if i == 0
50
+ puts "%30s%s" % ["Identified Packages : ", values[0]]
51
+ else
52
+ puts "%30s%s" % [" ", values[0]]
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,180 @@
1
+ module MCollective
2
+ module PluginPackager
3
+ class RpmpackagePackager
4
+ require 'erb'
5
+
6
+ def initialize(plugin, pluginpath = nil, signature = nil, verbose = false, keep_artifacts = nil, module_template = nil)
7
+ if @buildtool = select_command
8
+ @plugin = plugin
9
+ @package_name = "#{@plugin.mcname}-#{@plugin.metadata[:name]}"
10
+ @package_name_and_version = "#{@package_name}-#{@plugin.metadata[:version]}"
11
+ @verbose = verbose
12
+ @libdir = pluginpath || '/usr/libexec/mcollective/mcollective/'
13
+ @signature = signature
14
+ @rpmdir = rpmdir
15
+ @srpmdir = srpmdir
16
+ @keep_artifacts = keep_artifacts
17
+ else
18
+ raise("Cannot build package. 'rpmbuild' or 'rpmbuild-md5' is not present on the system")
19
+ end
20
+ end
21
+
22
+ # Determine the build tool present on the system
23
+ def select_command
24
+ if PluginPackager.command_available?('rpmbuild-md5')
25
+ return 'rpmbuild-md5'
26
+ elsif PluginPackager.command_available?('rpmbuild')
27
+ return 'rpmbuild'
28
+ else
29
+ return nil
30
+ end
31
+ end
32
+
33
+ def rpmdir
34
+ `rpm --eval '%_rpmdir'`.chomp
35
+ end
36
+
37
+ def srpmdir
38
+ `rpm --eval '%_srcrpmdir'`.chomp
39
+ end
40
+
41
+ # Build Process :
42
+ # - create temporary buildroot
43
+ # - create the spec file
44
+ # - create the tarball
45
+ # - run the build script
46
+ # - move pacakges to cwd
47
+ # - clean up
48
+ def create_packages
49
+ begin
50
+ puts "Building packages for #{@package_name} plugin."
51
+
52
+ @tmpdir = Dir.mktmpdir('mcollective_packager')
53
+ prepare_tmpdirs
54
+
55
+ make_spec_file
56
+ run_build
57
+ move_packages
58
+
59
+ puts "Completed building all packages for #{@package_name} plugin."
60
+ ensure
61
+ if @keep_artifacts
62
+ puts 'Keeping build artifacts'
63
+ puts "Build artifacts saved - #{@tmpdir}"
64
+ else
65
+ cleanup_tmpdirs
66
+ end
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def run_build
73
+ begin
74
+ tarfile = create_tar
75
+ PluginPackager.execute_verbosely(@verbose) do
76
+ PluginPackager.safe_system("#{@buildtool} -ta#{" --quiet" unless @verbose}#{" --sign" if @signature} #{tarfile}")
77
+ end
78
+ rescue => e
79
+ puts 'Build process has failed'
80
+ raise e
81
+ end
82
+ end
83
+
84
+ # Tar up source
85
+ # Expects directory $mcollective-$agent-$version
86
+ # Creates file : $tmpbuildroot/$mcollective-$agent-$version
87
+ def create_tar
88
+ tarfile = File.join(@tmpdir, "#{@package_name_and_version}.tgz")
89
+ begin
90
+ PluginPackager.execute_verbosely(@verbose) do
91
+ Dir.chdir(@tmpdir) do
92
+ PluginPackager.safe_system("tar -cvzf #{tarfile} #{@package_name_and_version}")
93
+ end
94
+ end
95
+ rescue => e
96
+ puts "Could not create tarball - '#{tarfile}'"
97
+ raise e
98
+ end
99
+ tarfile
100
+ end
101
+
102
+ # Move rpm's and srpm's to cwd
103
+ def move_packages
104
+ begin
105
+ files_to_copy = []
106
+ files_to_copy += Dir.glob(File.join(@rpmdir, 'noarch', "#{@package_name}-*-#{@plugin.metadata[:version]}-#{@plugin.revision}*.noarch.rpm"))
107
+ files_to_copy += Dir.glob(File.join(@srpmdir, "#{@package_name}-#{@plugin.metadata[:version]}-#{@plugin.revision}*.src.rpm"))
108
+ FileUtils.cp(files_to_copy, '.')
109
+ rescue => e
110
+ puts 'Could not copy packages to working directory'
111
+ raise e
112
+ end
113
+ end
114
+
115
+ # Create the specfile and place as $tmpbuildroot/$mcollective-$agent-$version/$mcollective-$agent-$version.spec
116
+ def make_spec_file
117
+ spec_file = File.join(@tmpdir, @package_name_and_version, "#{@package_name_and_version}.spec")
118
+ begin
119
+ spec_template = ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', 'redhat', 'rpm_spec.erb')), nil, '-')
120
+ File.open(spec_file, 'w') do |f|
121
+ f.puts spec_template.result(binding)
122
+ end
123
+ rescue => e
124
+ puts "Could not create specfile - '#{spec_file}'"
125
+ raise e
126
+ end
127
+ end
128
+
129
+ # Move files contained in the plugin to the correct directory
130
+ # relative to the build root.
131
+ def prepare_tmpdirs
132
+ plugin_files.each do |file|
133
+ begin
134
+ targetdir = File.join(@tmpdir, @package_name_and_version, @libdir, File.dirname(File.expand_path(file)).gsub(@plugin.target_path, ""))
135
+ FileUtils.mkdir_p(targetdir) unless File.directory?(targetdir)
136
+ FileUtils.cp_r(file, targetdir)
137
+ rescue Errno::EACCES => e
138
+ puts "Could not create directory '#{targetdir}'. Permission denied"
139
+ raise e
140
+ rescue Errno::ENOENT => e
141
+ puts "Could not copy file '#{file}' to '#{targetdir}'. File does not exist"
142
+ raise e
143
+ rescue => e
144
+ puts 'Could not prepare temporary build directory'
145
+ raise e
146
+ end
147
+ end
148
+ end
149
+
150
+ # Extract all the package files from the plugin's package data hash
151
+ def plugin_files
152
+ files = []
153
+ @plugin.packagedata.each do |name, data|
154
+ files += data[:files].reject{ |f| File.directory?(f) }
155
+ end
156
+ files
157
+ end
158
+
159
+ # Extract the package specific files from the file list and omits directories
160
+ def package_files(files)
161
+ package_files = []
162
+ files.each do |f|
163
+ if !File.directory?(f)
164
+ package_files << File.join(@libdir, File.expand_path(f).gsub(/#{@plugin.target_path}|\.\//, ''))
165
+ end
166
+ end
167
+ package_files
168
+ end
169
+
170
+ def cleanup_tmpdirs
171
+ begin
172
+ FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
173
+ rescue => e
174
+ puts "Could not remove temporary build directory - '#{@tmpdir}'"
175
+ raise e
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,7 @@
1
+ DESTDIR=
2
+
3
+ build:
4
+
5
+ clean:
6
+
7
+ install:
@@ -0,0 +1,5 @@
1
+ <%= @package_name -%> (<%= @plugin.metadata[:version]-%>-<%= @plugin.revision-%>) unstable; urgency=low
2
+
3
+ * Automated release for <%= @package_name -%> by mco plugin packager.
4
+
5
+ -- The Marionette Collective <mcollective-dev@googlegroups.com> <%= Time.new.strftime('%a, %d %b %Y %H:%M:%S %z') %>
@@ -0,0 +1,15 @@
1
+ Source: <%= @package_name %>
2
+ Homepage: <%= @plugin.metadata[:url] %>
3
+ Section: utils
4
+ Priority: extra
5
+ Build-Depends: debhelper (>= 7), cdbs, dpatch
6
+ Maintainer: <%= @plugin.metadata[:author] %>
7
+ Standards-Version: 3.9.1
8
+ <% @plugin.packagedata.each do |type, data| %>
9
+ Package: <%= "#{@package_name}-#{type}" %>
10
+ Architecture: all
11
+ Depends: <%= build_dependency_string(data) %>
12
+ Description: <%= @plugin.metadata[:description]%>
13
+ <%= data[:description]%>
14
+ .
15
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ This package was generated by the MCollective plugin packager on
2
+ <%= Time.now%>
3
+
4
+ Upstream Author:
5
+ <%= @plugin.metadata[:author] %> <%= @plugin.metadata[:url] %>
6
+
7
+ License:
8
+ <%= @plugin.metadata[:license] -%>
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/make -f
2
+
3
+ include /usr/share/cdbs/1/rules/debhelper.mk
4
+ include /usr/share/cdbs/1/rules/dpatch.mk
5
+ include /usr/share/cdbs/1/class/makefile.mk
6
+ DEB_MAKE_INVOKE = $(DEB_MAKE_ENVVARS) make -f debian/Makefile -C $(DEB_BUILDDIR)
@@ -0,0 +1,5 @@
1
+ name '<%= @plugin.vendor %>-<%= @package_name %>'
2
+ version '<%= @plugin.metadata[:version] %>'
3
+ description '<%= @plugin.metadata[:description] %>'
4
+ project_page '<%= @plugin.metadata[:url]%>'
5
+ dependency 'puppetlabs/mcollective', '1.x'