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
@@ -116,6 +116,10 @@ Puppet::Type.newtype(:augeas) do
116
116
  : Sets the node at `PATH` to `NULL`, creating it if needed
117
117
 
118
118
 
119
+ `clearm <PATH> <SUB>`
120
+ : Sets multiple nodes (matching `SUB` relative to `PATH`) to `NULL`
121
+
122
+
119
123
  `ins <LABEL> (before|after) <PATH>`
120
124
  : Inserts an empty node `LABEL` either before or after `PATH`.
121
125
 
@@ -68,7 +68,7 @@ module Puppet
68
68
  end
69
69
  if mode
70
70
  Puppet::Util.withumask(000) do
71
- Dir.mkdir(@resource[:path], symbolic_mode_to_int(mode, 755, true))
71
+ Dir.mkdir(@resource[:path], symbolic_mode_to_int(mode, 0755, true))
72
72
  end
73
73
  else
74
74
  Dir.mkdir(@resource[:path])
@@ -1,7 +1,7 @@
1
1
  require 'puppet/util/posix'
2
2
 
3
- # Manage file group ownership.
4
3
  module Puppet
4
+ # Manage file group ownership.
5
5
  Puppet::Type.type(:file).newproperty(:group) do
6
6
  desc <<-EOT
7
7
  Which group should own the file. Argument can be either a group
@@ -1,6 +1,8 @@
1
1
  # Manage file modes. This state should support different formats
2
2
  # for specification (e.g., u+rwx, or -0011), but for now only supports
3
3
  # specifying the full mode.
4
+
5
+
4
6
  module Puppet
5
7
  Puppet::Type.type(:file).newproperty(:mode) do
6
8
  require 'puppet/util/symbolic_file_mode'
@@ -19,6 +19,7 @@
19
19
  #
20
20
  # See http://www.nsa.gov/selinux/ for complete docs on SELinux.
21
21
 
22
+
22
23
  module Puppet
23
24
  require 'puppet/util/selinux'
24
25
 
@@ -145,5 +145,17 @@ module Puppet
145
145
 
146
146
  defaultto false
147
147
  end
148
+
149
+ # This method has been exposed for puppet to manage users and groups of
150
+ # files in its settings and should not be considered available outside of
151
+ # puppet.
152
+ #
153
+ # (see Puppet::Settings#service_group_available?)
154
+ #
155
+ # @returns [Boolean] if the group exists on the system
156
+ # @api private
157
+ def exists?
158
+ provider.exists?
159
+ end
148
160
  end
149
161
  end
@@ -15,7 +15,7 @@ module Puppet
15
15
  # call code when sync is called.
16
16
  newproperty(:ensure) do
17
17
  desc "Control what to do with this mount. Set this attribute to
18
- `umounted` to make sure the filesystem is in the filesystem table
18
+ `unmounted` to make sure the filesystem is in the filesystem table
19
19
  but not mounted (if the filesystem is currently mounted, it will be
20
20
  unmounted). Set it to `absent` to unmount (if necessary) and remove
21
21
  the filesystem from the fstab. Set to `mounted` to add it to the
@@ -207,7 +207,7 @@ module Puppet
207
207
  newvalues(:true, :false)
208
208
  defaultto do
209
209
  case Facter.value(:operatingsystem)
210
- when "FreeBSD", "Darwin", "AIX"
210
+ when "FreeBSD", "Darwin", "AIX", "DragonFly"
211
211
  false
212
212
  else
213
213
  true
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Simple module for logging messages on the client-side
3
- #
3
+
4
4
 
5
5
  module Puppet
6
6
  newtype(:notify) do
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Manage a router abstraction
3
- #
3
+
4
4
 
5
5
  module Puppet
6
6
  newtype(:router) do
@@ -4,6 +4,7 @@
4
4
  # can only be managed through the interface of an init script
5
5
  # which is why they have a search path for initscripts and such
6
6
 
7
+
7
8
  module Puppet
8
9
 
9
10
  newtype(:service) do
@@ -27,7 +27,9 @@ module Puppet
27
27
  end
28
28
 
29
29
  newproperty(:key) do
30
- desc "The key itself; generally a long string of hex digits."
30
+ desc "The public key itself; generally a long string of hex characters. The key attribute
31
+ may not contain whitespace: Omit key headers (e.g. 'ssh-rsa') and key identifiers
32
+ (e.g. 'joe@joescomputer.local') found in the public key file."
31
33
 
32
34
  validate do |value|
33
35
  raise Puppet::Error, "Key must not contain whitespace: #{value}" if value =~ /\s/
@@ -355,7 +355,14 @@ module Puppet
355
355
  autos
356
356
  end
357
357
 
358
- # Provide an external hook. Yay breaking out of APIs.
358
+ # This method has been exposed for puppet to manage users and groups of
359
+ # files in its settings and should not be considered available outside of
360
+ # puppet.
361
+ #
362
+ # (see Puppet::Settings#service_user_available?)
363
+ #
364
+ # @returns [Boolean] if the user exists on the system
365
+ # @api private
359
366
  def exists?
360
367
  provider.exists?
361
368
  end
@@ -185,6 +185,13 @@ module Util
185
185
  end
186
186
  end
187
187
 
188
+ # Resolve a path for an executable to the absolute path. This tries to behave
189
+ # in the same manner as the unix `which` command and uses the `PATH`
190
+ # environment variable.
191
+ #
192
+ # @api public
193
+ # @param bin [String] the name of the executable to find.
194
+ # @return [String] the absolute path to the found executable.
188
195
  def which(bin)
189
196
  if absolute_path?(bin)
190
197
  return bin if FileTest.file? bin and FileTest.executable? bin
@@ -489,6 +496,7 @@ module Util
489
496
  # Executes a block of code, wrapped with some special exception handling. Causes the ruby interpreter to
490
497
  # exit if the block throws an exception.
491
498
  #
499
+ # @api public
492
500
  # @param [String] message a message to log if the block fails
493
501
  # @param [Integer] code the exit code that the ruby interpreter should return if the block fails
494
502
  # @yield
@@ -19,13 +19,6 @@ class Puppet::Util::Autoload
19
19
  @gem_source ||= Puppet::Util::RubyGems::Source.new
20
20
  end
21
21
 
22
- # List all loaded files.
23
- def list_loaded
24
- loaded.keys.sort { |a,b| a[0] <=> b[0] }.collect do |path, hash|
25
- "#{path}: #{hash[:file]}"
26
- end
27
- end
28
-
29
22
  # Has a given path been loaded? This is used for testing whether a
30
23
  # changed file should be loaded or just ignored. This is only
31
24
  # used in network/client/master, when downloading plugins, to
@@ -205,7 +198,7 @@ class Puppet::Util::Autoload
205
198
  end
206
199
 
207
200
  def load(name, env=nil)
208
- self.class.load_file(File.join(@path, name.to_s), env)
201
+ self.class.load_file(expand(name), env)
209
202
  end
210
203
 
211
204
  # Load all instances that we can. This uses require, rather than load,
@@ -215,14 +208,18 @@ class Puppet::Util::Autoload
215
208
  end
216
209
 
217
210
  def loaded?(name)
218
- self.class.loaded?(File.join(@path, name.to_s))
211
+ self.class.loaded?(expand(name))
219
212
  end
220
213
 
221
214
  def changed?(name)
222
- self.class.changed?(File.join(@path, name.to_s))
215
+ self.class.changed?(expand(name))
223
216
  end
224
217
 
225
218
  def files_to_load
226
219
  self.class.files_to_load(@path)
227
220
  end
221
+
222
+ def expand(name)
223
+ ::File.join(@path, name.to_s)
224
+ end
228
225
  end
@@ -3,51 +3,66 @@ module Puppet
3
3
  class SubclassAlreadyDefined < Error; end
4
4
  end
5
5
 
6
+ # This is a utility module for generating classes.
7
+ # @api public
8
+ #
6
9
  module Puppet::Util::ClassGen
7
10
  include Puppet::Util::MethodHelper
8
11
  include Puppet::Util
9
12
 
10
- # Create a new subclass. Valid options are:
11
- # * <tt>:array</tt>: An array of existing classes. If specified, the new
12
- # class is added to this array.
13
- # * <tt>:attributes</tt>: A hash of attributes to set before the block is
14
- # evaluated.
15
- # * <tt>:block</tt>: The block to evaluate in the context of the class.
16
- # You can also just pass the block normally, but it will still be evaluated
17
- # with <tt>class_eval</tt>.
18
- # * <tt>:constant</tt>: What to set the constant as. Defaults to the
19
- # capitalized name.
20
- # * <tt>:hash</tt>: A hash of existing classes. If specified, the new
21
- # class is added to this hash, and it is also used for overwrite tests.
22
- # * <tt>:overwrite</tt>: Whether to overwrite an existing class.
23
- # * <tt>:parent</tt>: The parent class for the generated class. Defaults to
24
- # self.
25
- # * <tt>:prefix</tt>: The constant prefix. Default to nothing; if specified,
26
- # the capitalized name is appended and the result is set as the constant.
13
+ # Create a new class.
14
+ # @param name [String] the name of the generated class
15
+ # @param options [Hash] a hash of options
16
+ # @option options [Array<Class>] :array if specified, the generated class is appended to this array
17
+ # @option options [Hash<{String => Object}>] :attributes a hash that is applied to the generated class
18
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
19
+ # block is evaluated.
20
+ # @option options [Proc] :block a block to evaluate in the context of the class (this block can be provided
21
+ # this way, or as a normal yield block).
22
+ # @option options [String] :constant (name with first letter capitalized) what to set the constant that references
23
+ # the generated class to.
24
+ # @option options [Hash] :hash a hash of existing classes that this class is appended to (name => class).
25
+ # This hash must be specified if the `:overwrite` option is set to `true`.
26
+ # @option options [Boolean] :overwrite whether an overwrite of an existing class should be allowed (requires also
27
+ # defining the `:hash` with existing classes as the test is based on the content of this hash).
28
+ # @option options [Class] :parent (self) the parent class of the generated class.
29
+ # @option options [String] ('') :prefix the constant prefix to prepend to the constant name referencing the
30
+ # generated class.
31
+ # @return [Class] the generated class
32
+ #
27
33
  def genclass(name, options = {}, &block)
28
34
  genthing(name, Class, options, block)
29
35
  end
30
36
 
31
- # Create a new module. Valid options are:
32
- # * <tt>:array</tt>: An array of existing classes. If specified, the new
33
- # class is added to this array.
34
- # * <tt>:attributes</tt>: A hash of attributes to set before the block is
35
- # evaluated.
36
- # * <tt>:block</tt>: The block to evaluate in the context of the class.
37
- # You can also just pass the block normally, but it will still be evaluated
38
- # with <tt>class_eval</tt>.
39
- # * <tt>:constant</tt>: What to set the constant as. Defaults to the
40
- # capitalized name.
41
- # * <tt>:hash</tt>: A hash of existing classes. If specified, the new
42
- # class is added to this hash, and it is also used for overwrite tests.
43
- # * <tt>:overwrite</tt>: Whether to overwrite an existing class.
44
- # * <tt>:prefix</tt>: The constant prefix. Default to nothing; if specified,
37
+ # Creates a new module.
38
+ # @param name [String] the name of the generated module
39
+ # @param optinos [Hash] hash with options
40
+ # @option options [Array<Class>] :array if specified, the generated class is appended to this array
41
+ # @option options [Hash<{String => Object}>] :attributes a hash that is applied to the generated class
42
+ # by calling setter methods corresponding to this hash's keys/value pairs. This is done before the given
43
+ # block is evaluated.
44
+ # @option options [Proc] :block a block to evaluate in the context of the class (this block can be provided
45
+ # this way, or as a normal yield block).
46
+ # @option options [String] :constant (name with first letter capitalized) what to set the constant that references
47
+ # the generated class to.
48
+ # @option options [Hash] :hash a hash of existing classes that this class is appended to (name => class).
49
+ # This hash must be specified if the `:overwrite` option is set to `true`.
50
+ # @option options [Boolean] :overwrite whether an overwrite of an existing class should be allowed (requires also
51
+ # defining the `:hash` with existing classes as the test is based on the content of this hash).
45
52
  # the capitalized name is appended and the result is set as the constant.
53
+ # @option options [String] ('') :prefix the constant prefix to prepend to the constant name referencing the
54
+ # generated class.
55
+ # @return [Module] the generated Module
46
56
  def genmodule(name, options = {}, &block)
47
57
  genthing(name, Module, options, block)
48
58
  end
49
59
 
50
- # Remove an existing class
60
+ # Removes an existing class.
61
+ # @param name [String] the name of the class to remove
62
+ # @param options [Hash] options
63
+ # @option options [Hash] :hash a hash of existing classes from which the class to be removed is also removed
64
+ # @return [Boolean] whether the class was removed or not
65
+ #
51
66
  def rmclass(name, options)
52
67
  options = symbolize_options(options)
53
68
  const = genconst_string(name, options)
@@ -68,7 +83,8 @@ module Puppet::Util::ClassGen
68
83
 
69
84
  private
70
85
 
71
- # Generate the constant to create or remove.
86
+ # Generates the constant to create or remove.
87
+ # @api private
72
88
  def genconst_string(name, options)
73
89
  unless const = options[:constant]
74
90
  prefix = options[:prefix] || ""
@@ -80,6 +96,7 @@ module Puppet::Util::ClassGen
80
96
 
81
97
  # This does the actual work of creating our class or module. It's just a
82
98
  # slightly abstract version of genclass.
99
+ # @api private
83
100
  def genthing(name, type, options, block)
84
101
  options = symbolize_options(options)
85
102
 
@@ -128,6 +145,8 @@ module Puppet::Util::ClassGen
128
145
  # of which class hierarchy it polls for nested namespaces
129
146
  #
130
147
  # See http://redmine.ruby-lang.org/issues/show/1915
148
+ # @api private
149
+ #
131
150
  def is_constant_defined?(const)
132
151
  if ::RUBY_VERSION =~ /1.9/
133
152
  const_defined?(const, false)
@@ -137,6 +156,8 @@ module Puppet::Util::ClassGen
137
156
  end
138
157
 
139
158
  # Handle the setting and/or removing of the associated constant.
159
+ # @api private
160
+ #
140
161
  def handleclassconst(klass, name, options)
141
162
  const = genconst_string(name, options)
142
163
 
@@ -155,6 +176,8 @@ module Puppet::Util::ClassGen
155
176
  end
156
177
 
157
178
  # Perform the initializations on the class.
179
+ # @api private
180
+ #
158
181
  def initclass(klass, options)
159
182
  klass.initvars if klass.respond_to? :initvars
160
183
 
@@ -178,11 +201,13 @@ module Puppet::Util::ClassGen
178
201
  end
179
202
 
180
203
  # Convert our name to a constant.
204
+ # @api private
181
205
  def name2const(name)
182
206
  name.to_s.capitalize
183
207
  end
184
208
 
185
209
  # Store the class in the appropriate places.
210
+ # @api private
186
211
  def storeclass(klass, klassname, options)
187
212
  if hash = options[:hash]
188
213
  if hash.include? klassname and ! options[:overwrite]
@@ -10,125 +10,168 @@ if not defined? ::Bundler
10
10
  end
11
11
 
12
12
  require 'puppet'
13
+ require 'puppet/util'
13
14
  require "puppet/util/plugins"
14
15
  require "puppet/util/rubygems"
15
16
 
16
17
  module Puppet
17
18
  module Util
19
+ # This is the main entry point for all puppet applications / faces; it
20
+ # is basically where the bootstrapping process / lifecycle of an app
21
+ # begins.
18
22
  class CommandLine
23
+ OPTION_OR_MANIFEST_FILE = /^-|\.pp$|\.rb$/
19
24
 
25
+ # @param zero [String] the name of the executable
26
+ # @param argv [Array<String>] the arguments passed on the command line
27
+ # @param stdin [IO] (unused)
20
28
  def initialize(zero = $0, argv = ARGV, stdin = STDIN)
21
- @zero = zero
22
- @argv = argv.dup
23
- @stdin = stdin
24
-
25
- @subcommand_name, @args = subcommand_and_args(@zero, @argv, @stdin)
29
+ @command = File.basename(zero, '.rb')
30
+ @argv = argv
26
31
  Puppet::Plugins.on_commandline_initialization(:command_line_object => self)
27
32
  end
28
33
 
29
- attr :subcommand_name
30
- attr :args
34
+ # @return [String] name of the subcommand is being executed
35
+ # @api public
36
+ def subcommand_name
37
+ return @command if @command != 'puppet'
31
38
 
32
- def appdir
33
- File.join('puppet', 'application')
39
+ if @argv.first =~ OPTION_OR_MANIFEST_FILE
40
+ nil
41
+ else
42
+ @argv.first
43
+ end
34
44
  end
35
45
 
46
+ # @return [Array<String>] the command line arguments being passed to the subcommand
47
+ # @api public
48
+ def args
49
+ return @argv if @command != 'puppet'
50
+
51
+ if subcommand_name.nil?
52
+ @argv
53
+ else
54
+ @argv[1..-1]
55
+ end
56
+ end
57
+
58
+ # @api private
59
+ # @deprecated
36
60
  def self.available_subcommands
37
- # Eventually we probably want to replace this with a call to the
38
- # autoloader. however, at the moment the autoloader considers the
39
- # module path when loading, and we don't want to allow apps / faces to
40
- # load from there. Once that is resolved, this should be replaced.
41
- # --cprice 2012-03-06
42
- #
43
- # But we do want to load from rubygems --hightower
44
- search_path = Puppet::Util::RubyGems::Source.new.directories + $LOAD_PATH
45
- absolute_appdirs = search_path.uniq.collect do |x|
46
- File.join(x,'puppet','application')
47
- end.select{ |x| File.directory?(x) }
48
- absolute_appdirs.inject([]) do |commands, dir|
49
- commands + Dir[File.join(dir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
50
- end.uniq
61
+ Puppet.deprecation_warning('Puppet::Util::CommandLine.available_subcommands is deprecated; please use Puppet::Application.available_application_names instead.')
62
+ Puppet::Application.available_application_names
51
63
  end
64
+
52
65
  # available_subcommands was previously an instance method, not a class
53
66
  # method, and we have an unknown number of user-implemented applications
54
67
  # that depend on that behaviour. Forwarding allows us to preserve a
55
68
  # backward compatible API. --daniel 2011-04-11
69
+ # @api private
70
+ # @deprecated
56
71
  def available_subcommands
57
- self.class.available_subcommands
58
- end
59
-
60
- def require_application(application)
61
- require File.join(appdir, application)
72
+ Puppet.deprecation_warning('Puppet::Util::CommandLine#available_subcommands is deprecated; please use Puppet::Application.available_application_names instead.')
73
+ Puppet::Application.available_application_names
62
74
  end
63
75
 
64
- # This is the main entry point for all puppet applications / faces; it
65
- # is basically where the bootstrapping process / lifecycle of an app
66
- # begins.
76
+ # Run the puppet subcommand. If the subcommand is determined to be an
77
+ # external executable, this method will never return and the current
78
+ # process will be replaced via {Kernel#exec}.
79
+ #
80
+ # @return [void]
67
81
  def execute
68
- # Build up our settings - we don't need that until after version check.
69
82
  Puppet::Util.exit_on_fail("intialize global default settings") do
70
- Puppet.settings.initialize_global_settings(args)
83
+ Puppet.initialize_settings(args)
71
84
  end
72
85
 
73
- # OK, now that we've processed the command line options and the config
74
- # files, we should be able to say that we definitively know where the
75
- # libdir is... which means that we can now look for our available
76
- # applications / subcommands / faces.
86
+ find_subcommand.run
87
+ end
77
88
 
78
- if subcommand_name and available_subcommands.include?(subcommand_name) then
79
- require_application subcommand_name
80
- # This will need to be cleaned up to do something that is not so
81
- # application-specific (i.e.. so that we can load faces).
82
- # Longer-term, use the autoloader. See comments in
83
- # #available_subcommands method above. --cprice 2012-03-06
84
- app = Puppet::Application.find(subcommand_name).new(self)
85
- Puppet::Plugins.on_application_initialization(:application_object => self)
89
+ # @api private
90
+ def external_subcommand
91
+ Puppet::Util.which("puppet-#{subcommand_name}")
92
+ end
86
93
 
87
- app.run
88
- elsif ! execute_external_subcommand then
89
- unless subcommand_name.nil? then
90
- puts "Error: Unknown Puppet subcommand '#{subcommand_name}'"
91
- end
94
+ private
92
95
 
93
- # If the user is just checking the version, print that and exit
94
- if @argv.include? "--version" or @argv.include? "-V"
95
- puts Puppet.version
96
- else
97
- puts "See 'puppet help' for help on available puppet subcommands"
98
- end
96
+ def find_subcommand
97
+ if subcommand_name.nil?
98
+ NilSubcommand.new(self)
99
+ elsif Puppet::Application.available_application_names.include?(subcommand_name)
100
+ ApplicationSubcommand.new(subcommand_name, self)
101
+ elsif path_to_subcommand = external_subcommand
102
+ ExternalSubcommand.new(path_to_subcommand, self)
103
+ else
104
+ UnknownSubcommand.new(subcommand_name, self)
99
105
  end
100
106
  end
101
107
 
102
- def execute_external_subcommand
103
- external_command = "puppet-#{subcommand_name}"
108
+ # @api private
109
+ class ApplicationSubcommand
110
+ def initialize(subcommand_name, command_line)
111
+ @subcommand_name = subcommand_name
112
+ @command_line = command_line
113
+ end
114
+
115
+ def run
116
+ # For most applications, we want to be able to load code from the modulepath,
117
+ # such as apply, describe, resource, and faces.
118
+ # For agent, we only want to load pluginsync'ed code from libdir.
119
+ # For master, we shouldn't ever be loading per-enviroment code into the master's
120
+ # ruby process, but that requires fixing (#17210, #12173, #8750). So for now
121
+ # we try to restrict to only code that can be autoloaded from the node's
122
+ # environment.
123
+ if @subcommand_name != 'master' and @subcommand_name != 'agent'
124
+ Puppet::Node::Environment.new.each_plugin_directory do |dir|
125
+ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
126
+ end
127
+ end
104
128
 
105
- require 'puppet/util'
106
- path_to_subcommand = Puppet::Util.which(external_command)
107
- return false unless path_to_subcommand
129
+ app = Puppet::Application.find(@subcommand_name).new(@command_line)
130
+ Puppet::Plugins.on_application_initialization(:application_object => @command_line)
108
131
 
109
- exec(path_to_subcommand, *args)
132
+ app.run
133
+ end
110
134
  end
111
135
 
112
- private
136
+ # @api private
137
+ class ExternalSubcommand
138
+ def initialize(path_to_subcommand, command_line)
139
+ @path_to_subcommand = path_to_subcommand
140
+ @command_line = command_line
141
+ end
142
+
143
+ def run
144
+ Kernel.exec(@path_to_subcommand, *@command_line.args)
145
+ end
146
+ end
113
147
 
114
- def subcommand_and_args(zero, argv, stdin)
115
- zero = File.basename(zero, '.rb')
116
-
117
- if zero == 'puppet'
118
- case argv.first
119
- # if they didn't pass a command, or passed a help flag, we will
120
- # fall back to showing a usage message. we no longer default to
121
- # 'apply'
122
- when nil, "--help", "-h", /^-|\.pp$|\.rb$/
123
- [nil, argv]
124
- else
125
- [argv.first, argv[1..-1]]
148
+ # @api private
149
+ class NilSubcommand
150
+ def initialize(command_line)
151
+ @command_line = command_line
152
+ end
153
+
154
+ def run
155
+ if @command_line.args.include? "--version" or @command_line.args.include? "-V"
156
+ puts Puppet.version
157
+ else
158
+ puts "See 'puppet help' for help on available puppet subcommands"
126
159
  end
127
- else
128
- [zero, argv]
129
160
  end
130
161
  end
131
162
 
163
+ # @api private
164
+ class UnknownSubcommand < NilSubcommand
165
+ def initialize(subcommand_name, command_line)
166
+ @subcommand_name = subcommand_name
167
+ super(command_line)
168
+ end
169
+
170
+ def run
171
+ puts "Error: Unknown Puppet subcommand '#{@subcommand_name}'"
172
+ super
173
+ end
174
+ end
132
175
  end
133
176
  end
134
177
  end