puppet 3.0.2 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (320) hide show
  1. data/Gemfile +13 -11
  2. data/README.md +9 -7
  3. data/README_DEVELOPER.md +21 -30
  4. data/bin/extlookup2hiera +0 -0
  5. data/conf/auth.conf +42 -26
  6. data/conf/fileserver.conf +41 -0
  7. data/conf/tagmail.conf +16 -0
  8. data/examples/hiera/modules/data/manifests/common.pp +2 -1
  9. data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
  10. data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
  11. data/examples/hiera/modules/users/manifests/common.pp +2 -1
  12. data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
  13. data/examples/hiera/modules/users/manifests/development.pp +2 -1
  14. data/examples/hiera/site.pp +1 -1
  15. data/ext/debian/fileserver.conf +39 -15
  16. data/ext/envpuppet +2 -0
  17. data/ext/gentoo/puppet/fileserver.conf +41 -12
  18. data/ext/ips/puppet-agent +1 -6
  19. data/ext/ips/puppetagent.xml +0 -4
  20. data/ext/osx/postflight.erb +109 -0
  21. data/ext/project_data.yaml +2 -2
  22. data/ext/redhat/fileserver.conf +41 -12
  23. data/ext/redhat/puppet.spec.erb +8 -13
  24. data/install.rb +2 -5
  25. data/lib/puppet.rb +30 -13
  26. data/lib/puppet/application.rb +34 -16
  27. data/lib/puppet/application/agent.rb +4 -4
  28. data/lib/puppet/application/master.rb +25 -5
  29. data/lib/puppet/defaults.rb +11 -7
  30. data/lib/puppet/dsl.rb +7 -3
  31. data/lib/puppet/dsl/actions.rb +283 -0
  32. data/lib/puppet/dsl/blank_slate.rb +55 -0
  33. data/lib/puppet/dsl/context.rb +393 -0
  34. data/lib/puppet/dsl/parser.rb +57 -0
  35. data/lib/puppet/dsl/resource_decorator.rb +56 -0
  36. data/lib/puppet/dsl/resource_reference.rb +95 -0
  37. data/lib/puppet/dsl/type_reference.rb +102 -0
  38. data/lib/puppet/error.rb +1 -1
  39. data/lib/puppet/face/help.rb +2 -4
  40. data/lib/puppet/face/man.rb +8 -2
  41. data/lib/puppet/feature/pson.rb +1 -3
  42. data/lib/puppet/indirector/catalog/active_record.rb +3 -0
  43. data/lib/puppet/indirector/catalog/compiler.rb +1 -2
  44. data/lib/puppet/indirector/catalog/queue.rb +4 -0
  45. data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
  46. data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
  47. data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
  48. data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
  49. data/lib/puppet/indirector/certificate_status/file.rb +4 -0
  50. data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
  51. data/lib/puppet/indirector/facts/active_record.rb +3 -0
  52. data/lib/puppet/indirector/facts/couch.rb +3 -0
  53. data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
  54. data/lib/puppet/indirector/facts/store_configs.rb +3 -0
  55. data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
  56. data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
  57. data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
  58. data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
  59. data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
  60. data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
  61. data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
  62. data/lib/puppet/indirector/node/active_record.rb +3 -0
  63. data/lib/puppet/indirector/node/rest.rb +2 -2
  64. data/lib/puppet/indirector/node/store_configs.rb +3 -0
  65. data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
  66. data/lib/puppet/indirector/queue.rb +0 -1
  67. data/lib/puppet/indirector/request.rb +1 -2
  68. data/lib/puppet/indirector/resource/active_record.rb +4 -0
  69. data/lib/puppet/indirector/resource/ral.rb +3 -0
  70. data/lib/puppet/indirector/resource/rest.rb +3 -0
  71. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  72. data/lib/puppet/indirector/run/local.rb +3 -0
  73. data/lib/puppet/indirector/ssl_file.rb +16 -14
  74. data/lib/puppet/indirector/status/local.rb +3 -0
  75. data/lib/puppet/indirector/status/rest.rb +4 -0
  76. data/lib/puppet/interface.rb +78 -3
  77. data/lib/puppet/interface/action.rb +39 -3
  78. data/lib/puppet/interface/action_builder.rb +74 -1
  79. data/lib/puppet/interface/action_manager.rb +33 -3
  80. data/lib/puppet/interface/documentation.rb +116 -5
  81. data/lib/puppet/interface/face_collection.rb +6 -7
  82. data/lib/puppet/interface/option.rb +10 -1
  83. data/lib/puppet/interface/option_builder.rb +29 -1
  84. data/lib/puppet/interface/option_manager.rb +21 -6
  85. data/lib/puppet/metatype/manager.rb +47 -9
  86. data/lib/puppet/module_tool.rb +0 -1
  87. data/lib/puppet/network/formats.rb +0 -2
  88. data/lib/puppet/node.rb +2 -3
  89. data/lib/puppet/node/environment.rb +14 -1
  90. data/lib/puppet/parameter.rb +309 -44
  91. data/lib/puppet/parameter/package_options.rb +5 -0
  92. data/lib/puppet/parameter/path.rb +26 -3
  93. data/lib/puppet/parameter/value.rb +30 -6
  94. data/lib/puppet/parameter/value_collection.rb +82 -20
  95. data/lib/puppet/parser.rb +3 -0
  96. data/lib/puppet/parser/ast/definition.rb +2 -5
  97. data/lib/puppet/parser/ast/hostclass.rb +2 -3
  98. data/lib/puppet/parser/ast/node.rb +2 -5
  99. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +10 -0
  101. data/lib/puppet/parser/functions.rb +111 -7
  102. data/lib/puppet/parser/functions/create_resources.rb +23 -2
  103. data/lib/puppet/parser/functions/defined.rb +1 -1
  104. data/lib/puppet/parser/functions/extlookup.rb +2 -1
  105. data/lib/puppet/parser/functions/fail.rb +1 -1
  106. data/lib/puppet/parser/functions/file.rb +1 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/generate.rb +1 -1
  109. data/lib/puppet/parser/functions/hiera.rb +1 -1
  110. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  111. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  112. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  113. data/lib/puppet/parser/functions/include.rb +1 -1
  114. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  115. data/lib/puppet/parser/functions/md5.rb +1 -1
  116. data/lib/puppet/parser/functions/realize.rb +1 -1
  117. data/lib/puppet/parser/functions/regsubst.rb +54 -57
  118. data/lib/puppet/parser/functions/require.rb +1 -0
  119. data/lib/puppet/parser/functions/search.rb +1 -1
  120. data/lib/puppet/parser/functions/sha1.rb +1 -1
  121. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  122. data/lib/puppet/parser/functions/split.rb +1 -2
  123. data/lib/puppet/parser/functions/sprintf.rb +7 -10
  124. data/lib/puppet/parser/functions/tag.rb +1 -1
  125. data/lib/puppet/parser/functions/tagged.rb +1 -1
  126. data/lib/puppet/parser/functions/template.rb +1 -1
  127. data/lib/puppet/parser/functions/versioncmp.rb +1 -5
  128. data/lib/puppet/parser/parser_support.rb +11 -27
  129. data/lib/puppet/parser/scope.rb +48 -4
  130. data/lib/puppet/parser/type_loader.rb +31 -7
  131. data/lib/puppet/property.rb +304 -70
  132. data/lib/puppet/property/ensure.rb +14 -1
  133. data/lib/puppet/property/keyvalue.rb +17 -8
  134. data/lib/puppet/property/list.rb +3 -0
  135. data/lib/puppet/property/ordered_list.rb +7 -0
  136. data/lib/puppet/provider.rb +275 -53
  137. data/lib/puppet/provider/augeas/augeas.rb +17 -3
  138. data/lib/puppet/provider/confiner.rb +30 -1
  139. data/lib/puppet/provider/group/pw.rb +2 -2
  140. data/lib/puppet/provider/package/pip.rb +0 -1
  141. data/lib/puppet/provider/package/pkgin.rb +2 -0
  142. data/lib/puppet/provider/service/bsd.rb +1 -1
  143. data/lib/puppet/provider/service/freebsd.rb +10 -6
  144. data/lib/puppet/provider/service/init.rb +1 -1
  145. data/lib/puppet/provider/service/service.rb +1 -1
  146. data/lib/puppet/provider/user/pw.rb +2 -2
  147. data/lib/puppet/provider/user/useradd.rb +2 -3
  148. data/lib/puppet/reference/configuration.rb +6 -0
  149. data/lib/puppet/reports.rb +44 -4
  150. data/lib/puppet/reports/tagmail.rb +1 -1
  151. data/lib/puppet/resource.rb +38 -25
  152. data/lib/puppet/resource/type.rb +14 -6
  153. data/lib/puppet/settings.rb +66 -142
  154. data/lib/puppet/settings/config_file.rb +99 -0
  155. data/lib/puppet/settings/file_setting.rb +92 -24
  156. data/lib/puppet/settings/value_translator.rb +15 -0
  157. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  158. data/lib/puppet/test/test_helper.rb +8 -3
  159. data/lib/puppet/transaction.rb +1 -2
  160. data/lib/puppet/transaction/report.rb +122 -13
  161. data/lib/puppet/type.rb +763 -150
  162. data/lib/puppet/type/augeas.rb +4 -0
  163. data/lib/puppet/type/file/ensure.rb +1 -1
  164. data/lib/puppet/type/file/group.rb +1 -1
  165. data/lib/puppet/type/file/mode.rb +2 -0
  166. data/lib/puppet/type/file/selcontext.rb +1 -0
  167. data/lib/puppet/type/group.rb +12 -0
  168. data/lib/puppet/type/mount.rb +2 -2
  169. data/lib/puppet/type/notify.rb +1 -1
  170. data/lib/puppet/type/router.rb +1 -1
  171. data/lib/puppet/type/service.rb +1 -0
  172. data/lib/puppet/type/ssh_authorized_key.rb +3 -1
  173. data/lib/puppet/type/user.rb +8 -1
  174. data/lib/puppet/util.rb +8 -0
  175. data/lib/puppet/util/autoload.rb +7 -10
  176. data/lib/puppet/util/classgen.rb +58 -33
  177. data/lib/puppet/util/command_line.rb +120 -77
  178. data/lib/puppet/util/constant_inflector.rb +2 -0
  179. data/lib/puppet/util/execution.rb +63 -33
  180. data/lib/puppet/util/filetype.rb +1 -1
  181. data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
  182. data/lib/puppet/util/methodhelper.rb +19 -0
  183. data/lib/puppet/util/monkey_patches.rb +46 -0
  184. data/lib/puppet/util/plugins.rb +2 -2
  185. data/lib/puppet/util/provider_features.rb +24 -8
  186. data/lib/puppet/util/rubygems.rb +8 -1
  187. data/lib/puppet/util/zaml.rb +1 -1
  188. data/lib/puppet/version.rb +74 -3
  189. data/spec/integration/application/apply_spec.rb +1 -1
  190. data/spec/integration/defaults_spec.rb +1 -0
  191. data/spec/integration/dsl/classes_spec.rb +191 -0
  192. data/spec/integration/dsl/defaults_spec.rb +38 -0
  193. data/spec/integration/dsl/definitions_spec.rb +73 -0
  194. data/spec/integration/dsl/functions_spec.rb +95 -0
  195. data/spec/integration/dsl/nodes_spec.rb +96 -0
  196. data/spec/integration/dsl/params_spec.rb +146 -0
  197. data/spec/integration/dsl/relationships_spec.rb +46 -0
  198. data/spec/integration/dsl/resources_spec.rb +202 -0
  199. data/spec/integration/dsl/type_loading_spec.rb +64 -0
  200. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  201. data/spec/integration/network/formats_spec.rb +32 -45
  202. data/spec/integration/parser/collector_spec.rb +105 -25
  203. data/spec/integration/parser/scope_spec.rb +64 -1
  204. data/spec/integration/resource/catalog_spec.rb +2 -4
  205. data/spec/integration/type/package_spec.rb +1 -1
  206. data/spec/lib/matchers/catalog.rb +50 -0
  207. data/spec/lib/puppet_spec/compiler.rb +11 -0
  208. data/spec/lib/puppet_spec/dsl.rb +29 -0
  209. data/spec/spec_helper.rb +17 -3
  210. data/spec/unit/application/agent_spec.rb +0 -1
  211. data/spec/unit/application/apply_spec.rb +1 -1
  212. data/spec/unit/application/face_base_spec.rb +11 -4
  213. data/spec/unit/application/indirection_base_spec.rb +4 -8
  214. data/spec/unit/application/kick_spec.rb +5 -2
  215. data/spec/unit/application/master_spec.rb +0 -6
  216. data/spec/unit/application_spec.rb +38 -14
  217. data/spec/unit/dsl/actions_spec.rb +402 -0
  218. data/spec/unit/dsl/blank_slate_spec.rb +27 -0
  219. data/spec/unit/dsl/context_spec.rb +678 -0
  220. data/spec/unit/dsl/parser_spec.rb +56 -0
  221. data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
  222. data/spec/unit/dsl/resource_reference_spec.rb +150 -0
  223. data/spec/unit/dsl/type_reference_spec.rb +164 -0
  224. data/spec/unit/face/help_spec.rb +5 -7
  225. data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
  226. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
  227. data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
  228. data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
  229. data/spec/unit/indirector/hiera_spec.rb +3 -1
  230. data/spec/unit/indirector/queue_spec.rb +1 -7
  231. data/spec/unit/indirector/ssl_file_spec.rb +66 -39
  232. data/spec/unit/module_spec.rb +1 -1
  233. data/spec/unit/network/authstore_spec.rb +22 -1
  234. data/spec/unit/network/formats_spec.rb +1 -1
  235. data/spec/unit/node/environment_spec.rb +13 -0
  236. data/spec/unit/parser/collector_spec.rb +1 -1
  237. data/spec/unit/parser/compiler_spec.rb +26 -0
  238. data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
  239. data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
  240. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  241. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  242. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  243. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  244. data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
  245. data/spec/unit/parser/functions/split_spec.rb +4 -4
  246. data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
  247. data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
  248. data/spec/unit/parser/functions_spec.rb +51 -1
  249. data/spec/unit/parser/parser_spec.rb +0 -14
  250. data/spec/unit/parser/type_loader_spec.rb +15 -1
  251. data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
  252. data/spec/unit/provider/package/apt_spec.rb +0 -2
  253. data/spec/unit/provider/package/pip_spec.rb +12 -2
  254. data/spec/unit/provider/service/freebsd_spec.rb +8 -0
  255. data/spec/unit/provider/service/gentoo_spec.rb +20 -20
  256. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  257. data/spec/unit/provider/service/src_spec.rb +4 -4
  258. data/spec/unit/provider/service/systemd_spec.rb +0 -8
  259. data/spec/unit/provider/service/windows_spec.rb +1 -1
  260. data/spec/unit/provider/user/useradd_spec.rb +2 -9
  261. data/spec/unit/relationship_spec.rb +2 -2
  262. data/spec/unit/resource/catalog_spec.rb +2 -2
  263. data/spec/unit/resource/type_spec.rb +49 -25
  264. data/spec/unit/resource_spec.rb +34 -2
  265. data/spec/unit/settings/config_file_spec.rb +100 -0
  266. data/spec/unit/settings/file_setting_spec.rb +87 -84
  267. data/spec/unit/settings/value_translator_spec.rb +77 -0
  268. data/spec/unit/settings_spec.rb +96 -29
  269. data/spec/unit/type/file/ensure_spec.rb +75 -36
  270. data/spec/unit/type/file_spec.rb +0 -68
  271. data/spec/unit/type/group_spec.rb +10 -0
  272. data/spec/unit/util/autoload_spec.rb +6 -0
  273. data/spec/unit/util/command_line_spec.rb +54 -62
  274. data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
  275. data/spec/unit/util/metric_spec.rb +0 -9
  276. data/spec/unit/util/posix_spec.rb +0 -4
  277. data/spec/unit/util/rdoc_spec.rb +0 -12
  278. data/spec/unit/util/zaml_spec.rb +188 -130
  279. data/spec/unit/version_spec.rb +42 -0
  280. metadata +123 -90
  281. data/README_HIERA.md +0 -148
  282. data/conf/epm.list +0 -8
  283. data/conf/namespaceauth.conf +0 -20
  284. data/conf/puppet-queue.conf +0 -10
  285. data/examples/allatonce +0 -13
  286. data/examples/assignments +0 -11
  287. data/examples/components +0 -73
  288. data/examples/etc/init.d/sleeper +0 -70
  289. data/examples/etc/otherfile +0 -0
  290. data/examples/etc/puppet/fileserver.conf +0 -13
  291. data/examples/etc/puppet/namespaceauth.conf +0 -20
  292. data/examples/etc/puppet/puppet.conf +0 -10
  293. data/examples/etc/puppet/tagmail.conf +0 -1
  294. data/examples/execs +0 -16
  295. data/examples/file.bl +0 -11
  296. data/examples/filedefaults +0 -10
  297. data/examples/fileparsing +0 -116
  298. data/examples/filerecursion +0 -15
  299. data/examples/functions +0 -3
  300. data/examples/groups +0 -7
  301. data/examples/head +0 -30
  302. data/examples/importing +0 -8
  303. data/examples/mac_dscl.pp +0 -28
  304. data/examples/mac_dscl_revert.pp +0 -26
  305. data/examples/mac_pkgdmg.pp +0 -7
  306. data/examples/modules/sample_module.pp +0 -10
  307. data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
  308. data/examples/modules/sample_module/manifests/init.pp +0 -12
  309. data/examples/modules/sample_module/templates/sample.erb +0 -5
  310. data/examples/nodes +0 -20
  311. data/examples/one +0 -8
  312. data/examples/relationships +0 -34
  313. data/examples/selectors +0 -28
  314. data/examples/simpletests +0 -11
  315. data/examples/svncommit +0 -13
  316. data/lib/puppet/dsl/resource_api.rb +0 -120
  317. data/lib/puppet/dsl/resource_type_api.rb +0 -34
  318. data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
  319. data/spec/unit/dsl/resource_api_spec.rb +0 -180
  320. data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -1,8 +1,11 @@
1
1
  require 'optparse'
2
+ require 'puppet/util/command_line'
2
3
  require 'puppet/util/plugins'
3
4
  require 'puppet/util/constant_inflector'
4
5
  require 'puppet/error'
5
6
 
7
+ module Puppet
8
+
6
9
  # This class handles all the aspects of a Puppet application/executable
7
10
  # * setting up options
8
11
  # * setting up logs
@@ -116,13 +119,14 @@ require 'puppet/error'
116
119
  # process_member(member)
117
120
  # end
118
121
  # end
119
- module Puppet
120
122
  class Application
121
123
  require 'puppet/util'
122
124
  include Puppet::Util
123
125
 
124
126
  DOCPATTERN = ::File.expand_path(::File.dirname(__FILE__) + "/util/command_line/*" )
127
+ CommandLineArgs = Struct.new(:subcommand_name, :args)
125
128
 
129
+ @loader = Puppet::Util::Autoload.new(self, 'puppet/application')
126
130
 
127
131
  class << self
128
132
  include Puppet::Util
@@ -219,17 +223,32 @@ class Application
219
223
  @option_parser_commands
220
224
  end
221
225
 
222
- def find(file_name)
223
- # This should probably be using the autoloader, but due to concerns about the fact that
224
- # the autoloader currently considers the modulepath when looking for things to load,
225
- # we're delaying that for now.
226
+ # @return [Array<String>] the names of available applications
227
+ # @api public
228
+ def available_application_names
229
+ @loader.files_to_load.map do |fn|
230
+ ::File.basename(fn, '.rb')
231
+ end.uniq
232
+ end
233
+
234
+ # Finds the class for a given application and loads the class. This does
235
+ # not create an instance of the application, it only gets a handle to the
236
+ # class. The code for the application is expected to live in a ruby file
237
+ # `puppet/application/#{name}.rb` that is available on the `$LOAD_PATH`.
238
+ #
239
+ # @param application_name [String] the name of the application to find (eg. "apply").
240
+ # @return [Class] the Class instance of the application that was found.
241
+ # @raise [Puppet::Error] if the application class was not found.
242
+ # @raise [LoadError] if there was a problem loading the application file.
243
+ # @api public
244
+ def find(application_name)
226
245
  begin
227
- require ::File.join('puppet', 'application', file_name.to_s.downcase)
246
+ require @loader.expand(application_name.to_s.downcase)
228
247
  rescue LoadError => e
229
- Puppet.log_and_raise(e, "Unable to find application '#{file_name}'. #{e}")
248
+ Puppet.log_and_raise(e, "Unable to find application '#{application_name}'. #{e}")
230
249
  end
231
250
 
232
- class_name = Puppet::Util::ConstantInflector.file2constant(file_name.to_s)
251
+ class_name = Puppet::Util::ConstantInflector.file2constant(application_name.to_s)
233
252
 
234
253
  clazz = try_load_class(class_name)
235
254
 
@@ -239,7 +258,7 @@ class Application
239
258
  #### and then get rid of this stanza in a subsequent release.
240
259
  ################################################################
241
260
  if (clazz.nil?)
242
- class_name = file_name.capitalize
261
+ class_name = application_name.capitalize
243
262
  clazz = try_load_class(class_name)
244
263
  end
245
264
  ################################################################
@@ -247,7 +266,7 @@ class Application
247
266
  ################################################################
248
267
 
249
268
  if clazz.nil?
250
- raise Puppet::Error.new("Unable to load application class '#{class_name}' from file 'puppet/application/#{file_name}.rb'")
269
+ raise Puppet::Error.new("Unable to load application class '#{class_name}' from file 'puppet/application/#{application_name}.rb'")
251
270
  end
252
271
 
253
272
  return clazz
@@ -315,15 +334,14 @@ class Application
315
334
  def preinit
316
335
  end
317
336
 
318
- def initialize(command_line = nil)
319
-
320
- require 'puppet/util/command_line'
321
- @command_line = command_line || Puppet::Util::CommandLine.new
337
+ def initialize(command_line = Puppet::Util::CommandLine.new)
338
+ @command_line = CommandLineArgs.new(command_line.subcommand_name, command_line.args.dup)
322
339
  @options = {}
323
-
324
340
  end
325
341
 
326
- # This is the main application entry point
342
+ # Execute the application.
343
+ # @api public
344
+ # @return [void]
327
345
  def run
328
346
 
329
347
  # I don't really like the names of these lifecycle phases. It would be nice to change them to some more meaningful
@@ -241,10 +241,10 @@ configuration options can also be generated by running puppet agent with
241
241
  debugging or verbosity is enabled.
242
242
 
243
243
  * --no-client:
244
- Do not create a config client. This will cause the daemon to run
245
- without ever checking for its configuration automatically, and only
246
- makes sense when puppet agent is being run with listen = true in puppet.conf
247
- or was started with the `--listen` option.
244
+ Do not create a config client. This will cause the daemon to start
245
+ but not check configuration unless it is triggered with `puppet
246
+ kick`. This only makes sense when puppet agent is being run with
247
+ listen = true in puppet.conf or was started with the `--listen` option.
248
248
 
249
249
  * --noop:
250
250
  Use 'noop' mode where the daemon runs in a no-op or dry-run mode. This
@@ -120,18 +120,27 @@ Luke Kanies
120
120
 
121
121
  COPYRIGHT
122
122
  ---------
123
- Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
123
+ Copyright (c) 2012 Puppet Labs, LLC Licensed under the Apache 2.0 License
124
124
 
125
125
  HELP
126
126
  end
127
127
 
128
- def app_defaults()
129
- super.merge :facts_terminus => 'yaml'
128
+ # Sets up the 'node_cache_terminus' default to use the Write Only Yaml terminus :write_only_yaml.
129
+ # If this is not wanted, the setting ´node_cache_terminus´ should be set to nil.
130
+ # @see Puppet::Node::WriteOnlyYaml
131
+ # @see #setup_node_cache
132
+ # @see puppet issue 16753
133
+ #
134
+ def app_defaults
135
+ super.merge({
136
+ :node_cache_terminus => :write_only_yaml,
137
+ :facts_terminus => 'yaml'
138
+ })
130
139
  end
131
140
 
132
141
  def preinit
133
142
  Signal.trap(:INT) do
134
- $stderr.puts "Cancelling startup"
143
+ $stderr.puts "Canceling startup"
135
144
  exit(0)
136
145
  end
137
146
 
@@ -151,7 +160,6 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
151
160
 
152
161
  def compile
153
162
  Puppet::Util::Log.newdestination :console
154
- raise ArgumentError, "Cannot render compiled catalogs without pson support" unless Puppet.features.pson?
155
163
  begin
156
164
  unless catalog = Puppet::Resource::Catalog.indirection.find(options[:node])
157
165
  raise "Could not compile catalog for #{options[:node]}"
@@ -241,6 +249,16 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
241
249
  end
242
250
  end
243
251
 
252
+ # Sets up a special node cache "write only yaml" that collects and stores node data in yaml
253
+ # but never finds or reads anything (this since a real cache causes stale data to be served
254
+ # in circumstances when the cache can not be cleared).
255
+ # @see puppet issue 16753
256
+ # @see Puppet::Node::WriteOnlyYaml
257
+ # @return [void]
258
+ def setup_node_cache
259
+ Puppet::Node.indirection.cache_class = Puppet[:node_cache_terminus]
260
+ end
261
+
244
262
  def setup
245
263
  raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?
246
264
 
@@ -252,6 +270,8 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
252
270
 
253
271
  setup_terminuses
254
272
 
273
+ setup_node_cache
274
+
255
275
  setup_ssl
256
276
  end
257
277
  end
@@ -1,4 +1,6 @@
1
1
  # The majority of Puppet's configuration settings are set in this file.
2
+
3
+
2
4
  module Puppet
3
5
 
4
6
  ############################################################################################
@@ -155,12 +157,6 @@ module Puppet
155
157
  "all files referenced with `import` statements to exist. This setting was primarily\n" +
156
158
  "designed for use with commit hooks for parse-checking.",
157
159
  },
158
- :authconfig => {
159
- :default => "$confdir/namespaceauth.conf",
160
- :desc => "The configuration file that defines the rights to the different\n" +
161
- "namespaces and methods. This can be used as a coarse-grained\n" +
162
- "authorization system for both `puppet agent` and `puppet master`.",
163
- },
164
160
  :environment => {
165
161
  :default => "production",
166
162
  :desc => "The environment Puppet is running in. For clients\n" +
@@ -215,6 +211,13 @@ module Puppet
215
211
  :default => "plain",
216
212
  :desc => "Where to find information about nodes.",
217
213
  },
214
+ :node_cache_terminus => {
215
+ :type => :terminus,
216
+ :default => nil,
217
+ :desc => "How to store cached nodes.
218
+ Valid values are (none), 'json', 'yaml' or write only yaml ('write_only_yaml').
219
+ The master application defaults to 'write_only_yaml', all others to none.",
220
+ },
218
221
  :data_binding_terminus => {
219
222
  :type => :terminus,
220
223
  :default => "hiera",
@@ -676,7 +679,8 @@ EOT
676
679
  :ca_ttl => {
677
680
  :default => "5y",
678
681
  :type => :duration,
679
- :desc => "The default TTL for new certificates. Can be specified as a duration."
682
+ :desc => "The default TTL for new certificates. If this setting is set, ca_days is ignored.
683
+ Can be specified as a duration."
680
684
  },
681
685
  :ca_md => {
682
686
  :default => "md5",
@@ -1,7 +1,11 @@
1
1
  require 'puppet'
2
+ require 'puppet/dsl/parser'
3
+ require 'puppet/dsl/context'
2
4
 
3
- module Puppet::DSL
5
+ module Puppet
6
+ # @since 3.1
7
+ # @status EXPERIMENTALx
8
+ module DSL
9
+ end
4
10
  end
5
11
 
6
- require 'puppet/dsl/resource_type_api'
7
- require 'puppet/dsl/resource_api'
@@ -0,0 +1,283 @@
1
+ require 'puppet/dsl/resource_decorator'
2
+ require 'puppet/dsl/type_reference'
3
+ require 'puppet/util/methodhelper'
4
+
5
+ module Puppet
6
+ # @since 3.1
7
+ # @status EXPERIMENTAL
8
+ module DSL
9
+
10
+ # {Puppet::DSL::Context} delegates most calls to this class since itself is based
11
+ # on {BlankSlate}. This simplifies the implementation and makes debugging easier.
12
+ ##
13
+ class Actions
14
+ include Puppet::Util::MethodHelper
15
+
16
+ # The filename argument is only used when creating new nodes, definitions
17
+ # or classes.
18
+ # @overload initialize()
19
+ # @overload initialize(filename)
20
+ # @param filename [String] required when creating nodes, definitions and classes
21
+ #
22
+ def initialize(filename)
23
+ @filename = filename
24
+ @exporting = false
25
+ @virtualizing = false
26
+ end
27
+
28
+ # Returns type reference to the given type.
29
+ # @param name [String] a type name string
30
+ # @return [TypeReference] to the type of the given name
31
+ def type_reference(name)
32
+ TypeReference.new name
33
+ end
34
+
35
+ # Checks whether resource type exists
36
+ # @param name [String] the name of the type
37
+ #
38
+ def is_resource_type?(name)
39
+ type = Puppet::Resource.canonicalize_type(name)
40
+ !!(["Node", "Class"].include? type or
41
+ Puppet::Type.type type or
42
+ Parser.known_resource_types.find_definition '', type or
43
+ Parser.known_resource_types.find_hostclass '', type)
44
+ end
45
+
46
+ # Checks whether Puppet function exists
47
+ # @param [String] the name of the function
48
+ def is_function?(name)
49
+ !!Puppet::Parser::Functions.function(name)
50
+ end
51
+
52
+ # Returns object for accessing params hash (an object that responds to #[]).
53
+ # All keys will be stringified
54
+ # @return [#[]] object for looking up parameters
55
+ #
56
+ def params
57
+ Parser.current_scope
58
+ end
59
+
60
+ # Creates a new Puppet node. All arguments have to be passed.
61
+ # Nesting is the number of nested blocks in Ruby DSL (this can be
62
+ # basically 0 or 1). Nodes can be only created in the top level scope
63
+ #
64
+ # @param name [String, Regexp] the name match for hostname
65
+ # @option options [String] :inherits name of parent/super node
66
+ # @param nesting [Fixnum] 0 if topscope else > 0
67
+ # @param code [Proc] the body of the created node, evaluated later as Ruby DSL
68
+ #
69
+ # @return [void]
70
+ # @raise [NoMethodError] if nesting > 0
71
+ # @raise [ArgumentError] if block is missing
72
+ #
73
+ def create_node(name, options, nesting, &code)
74
+ raise NoMethodError, "nodes can be only created in top level scope" if nesting > 0
75
+ raise ArgumentError, "no block supplied" if code.nil?
76
+
77
+ validate_options [:inherits], options
78
+
79
+ name = name.to_s unless name.is_a? Regexp
80
+ parent = options[:inherits].to_s if options[:inherits]
81
+ node = Puppet::Resource::Type.new :node, name, :parent => parent
82
+ node.ruby_code << Context.new(code, :filename => @filename, :nesting => nesting + 1)
83
+
84
+ Parser.known_resource_types.add_node node
85
+ end
86
+
87
+ # Creates a new hostclass. All arguments are required.
88
+ # Nesting is the number of nested blocks in Ruby DSL (this can be
89
+ # basically 0 or 1). Classes can be only created in the top level scope.
90
+ #
91
+ # @param name [String] the name of the class
92
+ # @option options [String] :inherits name of parent/super class
93
+ # @option options [Hash] :arguments map of parameter name to value
94
+ # @param nesting [Fixnum] 0 if topscope else > 0
95
+ # @param code [Proc] the body of the created hostclass, evaluated later as Ruby DSL
96
+ #
97
+ # @return [void]
98
+ # @raise [NoMethodError] if nesting > 0
99
+ # @raise [ArgumentError] if block is missing
100
+ #
101
+ def create_hostclass(name, options, nesting, &code)
102
+ raise NoMethodError, "classes can be only created in top level scope" if nesting > 0
103
+ raise ArgumentError, "no block supplied" if code.nil?
104
+
105
+ validate_options [:inherits, :arguments], options
106
+
107
+ hostclass = Puppet::Resource::Type.new :hostclass, name.to_s, :arguments => options[:arguments], :parent => options[:inherits].to_s
108
+ hostclass.ruby_code << Context.new(code, :filename => @filename, :nesting => nesting + 1)
109
+
110
+ Parser.known_resource_types.add_hostclass hostclass
111
+ end
112
+
113
+ # Creates a new definition. All arguments are required.
114
+ # Nesting is the number of nested blocks in Ruby DSL (this can be
115
+ # basically 0 or 1). Definitions can be only created in the top level scope.
116
+ #
117
+ # @param name [String] the name of the definition
118
+ # @option options [Hash] :arguments map of parameter name to value
119
+ # @param nesting [Fixnum] 0 if topscope else > 0
120
+ # @param code [Proc] the body of the created definition, evaluated later as Ruby DSL
121
+ #
122
+ # @return [void]
123
+ # @raise [NoMethodError] if nesting > 0
124
+ # @raise [ArgumentError] if block is missing
125
+ #
126
+ def create_definition(name, options, nesting, &code)
127
+ raise NoMethodError, "definitions can be only created in top level scope" if nesting > 0
128
+ raise ArgumentError, "no block supplied" if code.nil?
129
+
130
+ validate_options [:arguments], options
131
+
132
+ definition = Puppet::Resource::Type.new :definition, name.to_s, options
133
+ definition.ruby_code << Context.new(code, :filename => @filename, :nesting => nesting + 1)
134
+
135
+ Parser.known_resource_types.add_definition definition
136
+ end
137
+
138
+ # Creates a resource, all arguments are required.
139
+ # Type is a Puppet Type of a resource,
140
+ # Code is a proc that will set additional parameters, can be nil.
141
+ #
142
+ # @overload create_resource(type, args, options, {|r| block})
143
+ # @param type [Symbol] name of resource type
144
+ # @param args [String, Array<String>] one or several instance names
145
+ # @param options [Hash] mapping from resource attribute name to value, including mapping of
146
+ # non attribute names :export and :virtual. The set of valid names is determined by the resource type.
147
+ # @yieldparam r [ResourceDecorator] allows manipulating the created resource
148
+ # @param block [ruby] evaluated immediately to allow further manipulation of parameters (can be nil)
149
+ # @return [Puppet::Parser::Resource] the created resource
150
+ #
151
+ # @raise [NoMethodError] if attempt is made to create resource while manifest is imported
152
+ #
153
+ def create_resource(type, args, options, code)
154
+ # when performing type import the scope is nil
155
+ raise NoMethodError, "resources can't be created in top level scope when importing a manifest" if Parser.current_scope.nil?
156
+
157
+ ResourceDecorator.new(options, &code) if code
158
+
159
+ Array(args).flatten.map do |name|
160
+ # Implementation based on
161
+ # lib/puppet/parser/functions/create_resources.rb
162
+ #
163
+ name = name.to_s
164
+ scope = Parser.current_scope
165
+
166
+ case type
167
+ when :class
168
+ klass = Parser.known_resource_types.find_hostclass '', name
169
+ resource = klass.ensure_in_catalog scope, options
170
+ else
171
+ resource = Puppet::Parser::Resource.new type, name,
172
+ :scope => scope,
173
+ :source => scope.source
174
+ options.each do |key, val|
175
+ resource[key] = get_resource(val)
176
+ end
177
+
178
+ resource.virtual = true if virtualizing? or options[:virtual]
179
+ resource.exported = true if exporting? or options[:export]
180
+
181
+ definition = Parser.known_resource_types.definition name
182
+ definition.instantiate_resource scope, resource if definition
183
+
184
+ scope.compiler.add_resource scope, resource
185
+ end
186
+ resource
187
+ end
188
+ end
189
+
190
+ # Calls a puppet function.
191
+ # It does not validate arguments to the function.
192
+ #
193
+ # @example
194
+ # call_function :notice, "foo"
195
+ #
196
+ # @param name [Symbol] the name of the function
197
+ # @param *args arguments passed to the called function
198
+ # @return [Object, void] what the function returns, or void if function does not produce a r-value.
199
+ #
200
+ # @raise [NoMethodError] if function is not found
201
+ #
202
+ def call_function(name, *args)
203
+ # when performing type import the scope is nil
204
+ raise NoMethodError, "functions can't be called in top level scope when importing a manifest" if Parser.current_scope.nil?
205
+ Parser.current_scope.send name, *args
206
+ end
207
+
208
+
209
+ # @return [Boolean] flag indicating the _export_ state of a resource
210
+ attr_accessor :exporting
211
+ # @return [Boolean] flag indicating the _virtual_ state of a resource
212
+ attr_accessor :virtualizing
213
+
214
+ # Predicate accessor for :exporting
215
+ # @return [Boolean] true of resource is _export_ state, false otherwise
216
+ #
217
+ def exporting?
218
+ !!@exporting
219
+ end
220
+
221
+ # Predicate accessor for :virtualizing
222
+ # @return [Boolean] true of resource is _virtual_ state, false otherwise
223
+ def virtualizing?
224
+ !!@virtualizing
225
+ end
226
+
227
+ # Exports given resources. Resource references can be used.
228
+ # @see #get_resource #get_resource for what can be passed as a reference
229
+ # @param resources [Array<Object>] resources (via reference) to set in _export_ state.
230
+ # @return [void]
231
+ #
232
+ def export_resources(resources)
233
+ resources.flatten.each do |r|
234
+ get_resource(r).exported = true
235
+ end
236
+ end
237
+
238
+ # Virtualizes resources passed in as an array. Resource references can be used.
239
+ # @param resources [Array<Puppet::Parser::Resource] resources to set in _virtual_ state.
240
+ # @return [void]
241
+ #
242
+ def virtualize_resources(resources)
243
+ resources.flatten.each do |r|
244
+ get_resource(r).virtual = true
245
+ end
246
+ end
247
+
248
+ private
249
+
250
+ # Returns a resource for the passed reference
251
+ # @todo the return of o.to_s is somewhat mysterious and needs an explanation
252
+ #
253
+ # @overload get_resource(resource)
254
+ # @param resource [Puppet::Resource] a resource
255
+ # @overload get_resource(reference)
256
+ # @param reference [ResourceReference] a reference to a resource
257
+ # @overload get_resource(name)
258
+ # @param name [String] a resource name
259
+ # @overload get_resource(o)
260
+ # @param o [#to_s] ???
261
+ # @return [Puppet::Resource] the dereferenced resource
262
+ # @return [String] if reference can not be dereferenced, or not Resource, ResourceReference or String
263
+ #
264
+ def get_resource(reference)
265
+ case reference
266
+ when Puppet::Resource
267
+ reference
268
+ when ResourceReference
269
+ reference.resource
270
+ when String
271
+ # Try to look up a resource by String, if it fails (function returns
272
+ # nil) just return the string
273
+ resource = Puppet::DSL::Parser.current_scope.findresource(reference)
274
+ resource ||= reference
275
+ else
276
+ # All values have to be stringified before passing to Puppet Core
277
+ reference.to_s
278
+ end
279
+ end
280
+
281
+ end
282
+ end
283
+ end