puppet 0.24.5 → 0.24.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. data/CHANGELOG +206 -0
  2. data/Rakefile +53 -0
  3. data/bin/filebucket +0 -0
  4. data/bin/puppet +32 -11
  5. data/bin/puppetca +1 -0
  6. data/bin/puppetd +0 -0
  7. data/bin/puppetdoc +0 -0
  8. data/bin/puppetmasterd +0 -0
  9. data/bin/puppetrun +16 -8
  10. data/bin/ralsh +0 -0
  11. data/conf/debian/rules +0 -0
  12. data/conf/gentoo/init.d/puppetmaster +0 -0
  13. data/conf/osx/PackageInfo.plist +36 -0
  14. data/conf/osx/createpackage.sh +167 -0
  15. data/conf/osx/preflight +12 -0
  16. data/conf/redhat/client.init +1 -1
  17. data/conf/redhat/puppet.spec +34 -6
  18. data/conf/redhat/server.init +42 -7
  19. data/conf/redhat/server.sysconfig +22 -0
  20. data/conf/solaris/smf/svc-puppetd +0 -0
  21. data/conf/solaris/smf/svc-puppetmasterd +0 -0
  22. data/examples/etc/init.d/sleeper +0 -0
  23. data/examples/mac_dscl.pp +0 -0
  24. data/examples/mac_dscl_revert.pp +0 -0
  25. data/examples/mac_netinfo.pp +0 -0
  26. data/examples/mac_pkgdmg.pp +0 -0
  27. data/ext/bin/sleeper +0 -0
  28. data/ext/module_puppet +0 -0
  29. data/ext/nagios/check_puppet.rb +0 -0
  30. data/ext/passenger/README +63 -0
  31. data/ext/passenger/apache2.conf +29 -0
  32. data/ext/passenger/config.ru +40 -0
  33. data/ext/puppet-test +0 -0
  34. data/ext/puppetlast +6 -31
  35. data/ext/puppetstoredconfigclean.rb +87 -0
  36. data/install.rb +75 -20
  37. data/lib/puppet.rb +1 -1
  38. data/lib/puppet/daemon.rb +0 -0
  39. data/lib/puppet/defaults.rb +3 -7
  40. data/lib/puppet/external/base64.rb +0 -0
  41. data/lib/puppet/external/nagios.rb +0 -0
  42. data/lib/puppet/external/nagios/base.rb +0 -0
  43. data/lib/puppet/file_serving/fileset.rb +2 -2
  44. data/lib/puppet/file_serving/metadata.rb +3 -3
  45. data/lib/puppet/indirector/facts/facter.rb +3 -2
  46. data/lib/puppet/indirector/yaml.rb +10 -1
  47. data/lib/puppet/module.rb +36 -12
  48. data/lib/puppet/network/authstore.rb +0 -0
  49. data/lib/puppet/network/client/master.rb +12 -11
  50. data/lib/puppet/network/handler/filebucket.rb +0 -0
  51. data/lib/puppet/network/handler/fileserver.rb +38 -46
  52. data/lib/puppet/network/handler/master.rb +1 -1
  53. data/lib/puppet/network/handler/report.rb +0 -0
  54. data/lib/puppet/network/handler/resource.rb +0 -0
  55. data/lib/puppet/network/handler/runner.rb +0 -0
  56. data/lib/puppet/network/http_server/rack.rb +148 -0
  57. data/lib/puppet/network/rights.rb +0 -0
  58. data/lib/puppet/network/xmlrpc/client.rb +5 -5
  59. data/lib/puppet/node.rb +5 -9
  60. data/lib/puppet/node/environment.rb +1 -17
  61. data/lib/puppet/node/facts.rb +0 -0
  62. data/lib/puppet/parameter.rb +1 -28
  63. data/lib/puppet/parser/ast.rb +6 -0
  64. data/lib/puppet/parser/ast/arithmetic_operator.rb +41 -0
  65. data/lib/puppet/parser/ast/boolean_operator.rb +48 -0
  66. data/lib/puppet/parser/ast/collexpr.rb +6 -1
  67. data/lib/puppet/parser/ast/comparison_operator.rb +37 -0
  68. data/lib/puppet/parser/ast/minus.rb +23 -0
  69. data/lib/puppet/parser/ast/nop.rb +11 -0
  70. data/lib/puppet/parser/ast/not.rb +19 -0
  71. data/lib/puppet/parser/ast/resource_override.rb +23 -16
  72. data/lib/puppet/parser/ast/resource_reference.rb +10 -6
  73. data/lib/puppet/parser/ast/vardef.rb +2 -2
  74. data/lib/puppet/parser/collector.rb +2 -1
  75. data/lib/puppet/parser/functions.rb +7 -217
  76. data/lib/puppet/parser/functions/defined.rb +27 -0
  77. data/lib/puppet/parser/functions/fail.rb +4 -0
  78. data/lib/puppet/parser/functions/file.rb +21 -0
  79. data/lib/puppet/parser/functions/fqdn_rand.rb +15 -0
  80. data/lib/puppet/parser/functions/generate.rb +35 -0
  81. data/lib/puppet/parser/functions/include.rb +26 -0
  82. data/lib/puppet/parser/functions/realize.rb +14 -0
  83. data/lib/puppet/parser/functions/search.rb +7 -0
  84. data/lib/puppet/parser/functions/sha1.rb +6 -0
  85. data/lib/puppet/parser/functions/tag.rb +6 -0
  86. data/lib/puppet/parser/functions/tagged.rb +18 -0
  87. data/lib/puppet/parser/functions/template.rb +22 -0
  88. data/lib/puppet/parser/lexer.rb +15 -5
  89. data/lib/puppet/parser/parser.rb +1073 -715
  90. data/lib/puppet/parser/parser_support.rb +18 -13
  91. data/lib/puppet/parser/resource.rb +1 -1
  92. data/lib/puppet/parser/resource/param.rb +10 -2
  93. data/lib/puppet/parser/scope.rb +63 -5
  94. data/lib/puppet/parser/templatewrapper.rb +61 -15
  95. data/lib/puppet/property.rb +7 -1
  96. data/lib/puppet/property/keyvalue.rb +96 -0
  97. data/lib/puppet/property/list.rb +78 -0
  98. data/lib/puppet/provider/confine.rb +1 -1
  99. data/lib/puppet/provider/confine/variable.rb +10 -1
  100. data/lib/puppet/provider/cron/crontab.rb +0 -0
  101. data/lib/puppet/provider/mailalias/aliases.rb +0 -0
  102. data/lib/puppet/provider/maillist/mailman.rb +0 -0
  103. data/lib/puppet/provider/mount/parsed.rb +0 -0
  104. data/lib/puppet/provider/nameservice.rb +24 -39
  105. data/lib/puppet/provider/nameservice/directoryservice.rb +12 -3
  106. data/lib/puppet/provider/nameservice/netinfo.rb +12 -2
  107. data/lib/puppet/provider/nameservice/objectadd.rb +1 -10
  108. data/lib/puppet/provider/package/appdmg.rb +1 -1
  109. data/lib/puppet/provider/package/apple.rb +0 -0
  110. data/lib/puppet/provider/package/apt.rb +14 -21
  111. data/lib/puppet/provider/package/aptitude.rb +0 -0
  112. data/lib/puppet/provider/package/blastwave.rb +2 -0
  113. data/lib/puppet/provider/package/darwinport.rb +0 -0
  114. data/lib/puppet/provider/package/dpkg.rb +33 -51
  115. data/lib/puppet/provider/package/fink.rb +1 -1
  116. data/lib/puppet/provider/package/freebsd.rb +0 -0
  117. data/lib/puppet/provider/package/gem.rb +0 -0
  118. data/lib/puppet/provider/package/hpux.rb +46 -0
  119. data/lib/puppet/provider/package/openbsd.rb +0 -0
  120. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  121. data/lib/puppet/provider/package/portage.rb +3 -1
  122. data/lib/puppet/provider/package/ports.rb +3 -3
  123. data/lib/puppet/provider/package/rpm.rb +8 -1
  124. data/lib/puppet/provider/package/rug.rb +2 -2
  125. data/lib/puppet/provider/package/sun.rb +2 -0
  126. data/lib/puppet/provider/package/sunfreeware.rb +3 -0
  127. data/lib/puppet/provider/package/yum.rb +24 -17
  128. data/lib/puppet/provider/package/yumhelper.py +92 -11
  129. data/lib/puppet/provider/parsedfile.rb +0 -0
  130. data/lib/puppet/provider/port/parsed.rb +0 -0
  131. data/lib/puppet/provider/selboolean/getsetsebool.rb +47 -0
  132. data/lib/puppet/provider/selmodule/semodule.rb +143 -0
  133. data/lib/puppet/provider/service/base.rb +0 -0
  134. data/lib/puppet/provider/service/daemontools.rb +154 -0
  135. data/lib/puppet/provider/service/debian.rb +1 -1
  136. data/lib/puppet/provider/service/freebsd.rb +2 -0
  137. data/lib/puppet/provider/service/gentoo.rb +2 -0
  138. data/lib/puppet/provider/service/init.rb +0 -0
  139. data/lib/puppet/provider/service/redhat.rb +1 -1
  140. data/lib/puppet/provider/service/runit.rb +93 -0
  141. data/lib/puppet/provider/service/smf.rb +2 -0
  142. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -1
  143. data/lib/puppet/provider/sshkey/parsed.rb +0 -0
  144. data/lib/puppet/provider/user/hpux.rb +30 -0
  145. data/lib/puppet/provider/user/user_role_add.rb +156 -0
  146. data/lib/puppet/provider/user/useradd.rb +23 -14
  147. data/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb +17 -0
  148. data/lib/puppet/rails/database/schema.rb +0 -8
  149. data/lib/puppet/rails/resource.rb +6 -6
  150. data/lib/puppet/reference/configuration.rb +0 -7
  151. data/lib/puppet/reports.rb +0 -0
  152. data/lib/puppet/reports/rrdgraph.rb +3 -2
  153. data/lib/puppet/sslcertificates.rb +0 -0
  154. data/lib/puppet/sslcertificates/inventory.rb +3 -2
  155. data/lib/puppet/sslcertificates/support.rb +3 -0
  156. data/lib/puppet/transaction/report.rb +1 -7
  157. data/lib/puppet/transportable.rb +10 -7
  158. data/lib/puppet/type.rb +2110 -14
  159. data/lib/puppet/type/cron.rb +0 -0
  160. data/lib/puppet/type/exec.rb +0 -0
  161. data/lib/puppet/type/file.rb +12 -2
  162. data/lib/puppet/type/file/checksum.rb +4 -0
  163. data/lib/puppet/type/file/content.rb +0 -0
  164. data/lib/puppet/type/file/ensure.rb +0 -0
  165. data/lib/puppet/type/file/group.rb +30 -43
  166. data/lib/puppet/type/file/mode.rb +0 -0
  167. data/lib/puppet/type/file/owner.rb +0 -0
  168. data/lib/puppet/type/file/selcontext.rb +104 -0
  169. data/lib/puppet/type/file/source.rb +0 -0
  170. data/lib/puppet/type/file/type.rb +0 -0
  171. data/lib/puppet/type/filebucket.rb +0 -0
  172. data/lib/puppet/type/group.rb +0 -8
  173. data/lib/puppet/type/host.rb +0 -0
  174. data/lib/puppet/type/mailalias.rb +0 -0
  175. data/lib/puppet/type/maillist.rb +0 -0
  176. data/lib/puppet/type/mount.rb +0 -0
  177. data/lib/puppet/type/package.rb +2 -2
  178. data/lib/puppet/type/port.rb +0 -0
  179. data/lib/puppet/type/schedule.rb +0 -0
  180. data/lib/puppet/type/selboolean.rb +31 -0
  181. data/lib/puppet/type/selmodule.rb +54 -0
  182. data/lib/puppet/type/ssh_authorized_key.rb +3 -3
  183. data/lib/puppet/type/sshkey.rb +0 -0
  184. data/lib/puppet/type/tidy.rb +0 -0
  185. data/lib/puppet/type/user.rb +153 -137
  186. data/lib/puppet/type/yumrepo.rb +18 -2
  187. data/lib/puppet/type/zone.rb +5 -1
  188. data/lib/puppet/util.rb +7 -7
  189. data/lib/puppet/util/filetype.rb +7 -0
  190. data/lib/puppet/util/instance_loader.rb +0 -0
  191. data/lib/puppet/util/ldap/connection.rb +11 -1
  192. data/lib/puppet/util/ldap/manager.rb +1 -1
  193. data/lib/puppet/util/loadedfile.rb +0 -0
  194. data/lib/puppet/util/log.rb +42 -43
  195. data/lib/puppet/util/metric.rb +23 -9
  196. data/lib/puppet/util/posix.rb +69 -18
  197. data/lib/puppet/util/selinux.rb +139 -0
  198. data/lib/puppet/util/settings.rb +5 -7
  199. data/lib/puppet/util/user_attr.rb +21 -0
  200. data/test/certmgr/ca.rb +0 -0
  201. data/test/certmgr/certmgr.rb +0 -0
  202. data/test/certmgr/inventory.rb +0 -0
  203. data/test/certmgr/support.rb +0 -0
  204. data/test/data/providers/ssh_authorized_key/parsed/authorized_keys1 +3 -0
  205. data/test/data/snippets/append.pp +11 -0
  206. data/test/data/snippets/arithmetic_expression.pp +8 -0
  207. data/test/data/snippets/arraytrailingcomma.pp +3 -0
  208. data/test/data/snippets/emptyifelse.pp +9 -0
  209. data/test/data/snippets/funccomma.pp +5 -0
  210. data/test/data/snippets/ifexpression.rb +6 -0
  211. data/test/data/snippets/subclass_name_duplication.pp +0 -0
  212. data/test/executables/filebucket.rb +0 -0
  213. data/test/executables/puppetbin.rb +0 -0
  214. data/test/executables/puppetca.rb +0 -0
  215. data/test/executables/puppetd.rb +0 -0
  216. data/test/executables/puppetmasterd.rb +0 -0
  217. data/test/executables/puppetmodule.rb +0 -0
  218. data/test/language/ast.rb +0 -0
  219. data/test/language/ast/casestatement.rb +0 -0
  220. data/test/language/ast/resource.rb +0 -0
  221. data/test/language/ast/resource_reference.rb +0 -28
  222. data/test/language/ast/selector.rb +0 -0
  223. data/test/language/ast/variable.rb +0 -0
  224. data/test/language/functions.rb +91 -12
  225. data/test/language/parser.rb +21 -0
  226. data/test/language/resource.rb +0 -0
  227. data/test/language/scope.rb +28 -0
  228. data/test/language/snippets.rb +14 -0
  229. data/test/language/transportable.rb +0 -0
  230. data/test/lib/puppettest.rb +0 -0
  231. data/test/lib/puppettest/reporttesting.rb +0 -2
  232. data/test/lib/puppettest/runnable_test.rb +2 -0
  233. data/test/lib/puppettest/support/resources.rb +0 -0
  234. data/test/network/authconfig.rb +0 -0
  235. data/test/network/authorization.rb +0 -0
  236. data/test/network/authstore.rb +0 -0
  237. data/test/network/client/ca.rb +0 -0
  238. data/test/network/client/client.rb +0 -0
  239. data/test/network/client/dipper.rb +0 -0
  240. data/test/network/client/master.rb +2 -6
  241. data/test/network/client/resource.rb +0 -0
  242. data/test/network/client_request.rb +0 -0
  243. data/test/network/daemon.rb +0 -0
  244. data/test/network/handler/bucket.rb +0 -0
  245. data/test/network/handler/ca.rb +0 -0
  246. data/test/network/handler/fileserver.rb +8 -0
  247. data/test/network/handler/handler.rb +0 -0
  248. data/test/network/handler/master.rb +3 -1
  249. data/test/network/handler/report.rb +0 -0
  250. data/test/network/handler/resource.rb +0 -0
  251. data/test/network/handler/runner.rb +0 -0
  252. data/test/network/rights.rb +0 -0
  253. data/test/network/server/mongrel_test.rb +0 -0
  254. data/test/network/server/webrick.rb +0 -0
  255. data/test/network/xmlrpc/client.rb +0 -0
  256. data/test/network/xmlrpc/processor.rb +0 -0
  257. data/test/network/xmlrpc/server.rb +0 -0
  258. data/test/network/xmlrpc/webrick_servlet.rb +0 -0
  259. data/test/other/dsl.rb +0 -0
  260. data/test/other/events.rb +0 -0
  261. data/test/other/overrides.rb +0 -0
  262. data/test/other/provider.rb +0 -0
  263. data/test/other/puppet.rb +0 -0
  264. data/test/other/relationships.rb +0 -0
  265. data/test/other/report.rb +2 -4
  266. data/test/other/transactions.rb +1 -1
  267. data/test/puppet/conffiles.rb +0 -0
  268. data/test/puppet/defaults.rb +0 -0
  269. data/test/puppet/errortest.rb +0 -0
  270. data/test/puppet/tc_suidmanager.rb +0 -0
  271. data/test/rails/ast.rb +0 -0
  272. data/test/rails/configuration.rb +0 -0
  273. data/test/rails/host.rb +0 -0
  274. data/test/rails/rails.rb +0 -0
  275. data/test/rails/railsparameter.rb +0 -0
  276. data/test/rails/railsresource.rb +0 -0
  277. data/test/ral/manager/attributes.rb +0 -0
  278. data/test/ral/manager/instances.rb +0 -0
  279. data/test/ral/manager/manager.rb +0 -0
  280. data/test/ral/manager/provider.rb +0 -0
  281. data/test/ral/manager/type.rb +0 -0
  282. data/test/ral/providers/cron/crontab.rb +0 -0
  283. data/test/ral/providers/group.rb +14 -13
  284. data/test/ral/providers/host/netinfo.rb +0 -0
  285. data/test/ral/providers/host/parsed.rb +0 -0
  286. data/test/ral/providers/mailalias/aliases.rb +0 -0
  287. data/test/ral/providers/mount/netinfo.rb +0 -0
  288. data/test/ral/providers/nameservice.rb +0 -0
  289. data/test/ral/providers/package.rb +0 -31
  290. data/test/ral/providers/package/aptitude.rb +1 -2
  291. data/test/ral/providers/package/aptrpm.rb +2 -2
  292. data/test/ral/providers/parsedfile.rb +0 -0
  293. data/test/ral/providers/port/parsed.rb +0 -0
  294. data/test/ral/providers/provider.rb +0 -0
  295. data/test/ral/providers/service/base.rb +0 -0
  296. data/test/ral/providers/service/debian.rb +0 -0
  297. data/test/ral/providers/sshkey/parsed.rb +0 -0
  298. data/test/ral/providers/user.rb +8 -8
  299. data/test/ral/providers/user/useradd.rb +0 -0
  300. data/test/ral/type/basic.rb +0 -0
  301. data/test/ral/type/cron.rb +0 -0
  302. data/test/ral/type/exec.rb +0 -0
  303. data/test/ral/type/file.rb +0 -0
  304. data/test/ral/type/file/target.rb +0 -0
  305. data/test/ral/type/filebucket.rb +0 -0
  306. data/test/ral/type/fileignoresource.rb +0 -0
  307. data/test/ral/type/filesources.rb +1 -3
  308. data/test/ral/type/group.rb +0 -0
  309. data/test/ral/type/host.rb +0 -0
  310. data/test/ral/type/mailalias.rb +1 -2
  311. data/test/ral/type/parameter.rb +0 -0
  312. data/test/ral/type/port.rb +0 -0
  313. data/test/ral/type/property.rb +0 -0
  314. data/test/ral/type/resources.rb +0 -0
  315. data/test/ral/type/service.rb +0 -0
  316. data/test/ral/type/sshkey.rb +0 -0
  317. data/test/ral/type/tidy.rb +0 -0
  318. data/test/ral/type/user.rb +0 -50
  319. data/test/ral/type/yumrepo.rb +7 -1
  320. data/test/ral/type/zone.rb +0 -0
  321. data/test/test +0 -0
  322. data/test/util/autoload.rb +0 -0
  323. data/test/util/classgen.rb +0 -0
  324. data/test/util/execution.rb +0 -0
  325. data/test/util/features.rb +0 -0
  326. data/test/util/fileparsing.rb +0 -0
  327. data/test/util/filetype.rb +0 -0
  328. data/test/util/inifile.rb +0 -0
  329. data/test/util/instance_loader.rb +0 -0
  330. data/test/util/log.rb +0 -59
  331. data/test/util/metrics.rb +0 -0
  332. data/test/util/package.rb +0 -0
  333. data/test/util/pidlock.rb +0 -0
  334. data/test/util/settings.rb +0 -0
  335. data/test/util/storage.rb +0 -0
  336. data/test/util/subclass_loader.rb +0 -0
  337. data/test/util/utiltest.rb +0 -0
  338. metadata +54 -19
  339. data/lib/puppet/metatype/attributes.rb +0 -685
  340. data/lib/puppet/metatype/closure.rb +0 -49
  341. data/lib/puppet/metatype/container.rb +0 -50
  342. data/lib/puppet/metatype/evaluation.rb +0 -163
  343. data/lib/puppet/metatype/instances.rb +0 -305
  344. data/lib/puppet/metatype/metaparams.rb +0 -423
  345. data/lib/puppet/metatype/providers.rb +0 -247
  346. data/lib/puppet/metatype/relationships.rb +0 -115
  347. data/lib/puppet/metatype/schedules.rb +0 -33
  348. data/lib/puppet/metatype/tags.rb +0 -38
  349. data/lib/puppet/util/plist.rb +0 -23
  350. data/lib/puppet/util/plist/generator.rb +0 -225
  351. data/lib/puppet/util/plist/parser.rb +0 -226
  352. data/test/ral/providers/package/apt.rb +0 -169
  353. data/test/ral/providers/package/dpkg.rb +0 -64
  354. data/test/util/posixtest.rb +0 -169
@@ -3,7 +3,7 @@ require 'puppet/parser/ast/branch'
3
3
  class Puppet::Parser::AST
4
4
  # Define a variable. Stores the value in the current scope.
5
5
  class VarDef < AST::Branch
6
- attr_accessor :name, :value
6
+ attr_accessor :name, :value, :append
7
7
 
8
8
  @settor = true
9
9
 
@@ -14,7 +14,7 @@ class Puppet::Parser::AST
14
14
  value = @value.safeevaluate(scope)
15
15
 
16
16
  parsewrap do
17
- scope.setvar(name,value, @file, @line)
17
+ scope.setvar(name,value, @file, @line, @append)
18
18
  end
19
19
  end
20
20
 
@@ -72,7 +72,8 @@ class Puppet::Parser::Collector
72
72
  def collect_exported
73
73
  # First get everything from the export table. Just reuse our
74
74
  # collect_virtual method but tell it to use 'exported? for the test.
75
- resources = collect_virtual(true).reject { |r| ! r.virtual? }
75
+ resources = collect_virtual(true).reject { |r| ! r.virtual? }.each { |r| r.exported = false }
76
+ #resources = collect_virtual(true).reject { |r| ! r.virtual? }
76
77
 
77
78
  count = resources.length
78
79
 
@@ -6,6 +6,8 @@ module Functions
6
6
  # A module for managing parser functions. Each specified function
7
7
  # becomes an instance method on the Scope class.
8
8
 
9
+ @functions = {}
10
+
9
11
  class << self
10
12
  include Puppet::Util
11
13
  end
@@ -23,7 +25,6 @@ module Functions
23
25
 
24
26
  # Create a new function type.
25
27
  def self.newfunction(name, options = {}, &block)
26
- @functions ||= {}
27
28
  name = symbolize(name)
28
29
 
29
30
  if @functions.include? name
@@ -105,226 +106,15 @@ module Functions
105
106
  return false
106
107
  end
107
108
  end
108
-
109
- # Include the specified classes
110
- newfunction(:include, :doc => "Evaluate one or more classes.") do |vals|
111
- vals = [vals] unless vals.is_a?(Array)
112
-
113
- # The 'false' disables lazy evaluation.
114
- klasses = compiler.evaluate_classes(vals, self, false)
115
-
116
- missing = vals.find_all do |klass|
117
- ! klasses.include?(klass)
118
- end
119
-
120
- unless missing.empty?
121
- # Throw an error if we didn't evaluate all of the classes.
122
- str = "Could not find class"
123
- if missing.length > 1
124
- str += "es"
125
- end
126
-
127
- str += " " + missing.join(", ")
128
-
129
- if n = namespaces and ! n.empty? and n != [""]
130
- str += " in namespaces %s" % @namespaces.join(", ")
131
- end
132
- self.fail Puppet::ParseError, str
133
- end
134
- end
135
-
136
- # Tag the current scope with each passed name
137
- newfunction(:tag, :doc => "Add the specified tags to the containing class
138
- or definition. All contained objects will then acquire that tag, also.
139
- ") do |vals|
140
- self.resource.tag(*vals)
141
- end
142
-
143
- # Test whether a given tag is set. This functions as a big OR -- if any of the
144
- # specified tags are unset, we return false.
145
- newfunction(:tagged, :type => :rvalue, :doc => "A boolean function that
146
- tells you whether the current container is tagged with the specified tags.
147
- The tags are ANDed, so that all of the specified tags must be included for
148
- the function to return true.") do |vals|
149
- configtags = compiler.catalog.tags
150
- resourcetags = resource.tags
151
-
152
- retval = true
153
- vals.each do |val|
154
- unless configtags.include?(val) or resourcetags.include?(val)
155
- retval = false
156
- break
157
- end
158
- end
159
-
160
- return retval
161
- end
162
-
163
- # Test whether a given class or definition is defined
164
- newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given
165
- type is defined, either as a native type or a defined type, or whether a class is defined.
166
- This is useful for checking whether a class is defined and only including it if it is.
167
- This function can also test whether a resource has been defined, using resource references
168
- (e.g., ``if defined(File['/tmp/myfile']) { ... }``). This function is unfortunately
169
- dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals|
170
- result = false
171
- vals.each do |val|
172
- case val
173
- when String:
174
- # For some reason, it doesn't want me to return from here.
175
- if Puppet::Type.type(val) or finddefine(val) or findclass(val)
176
- result = true
177
- break
178
- end
179
- when Puppet::Parser::Resource::Reference:
180
- if findresource(val.to_s)
181
- result = true
182
- break
183
- end
184
- else
185
- raise ArgumentError, "Invalid argument of type %s to 'defined'" % val.class
186
- end
187
- end
188
- result
189
- end
190
-
191
- newfunction(:fqdn_rand, :type => :rvalue, :doc => "Generates random
192
- numbers based on the node's fqdn. The first argument sets the range.
193
- The second argument specifies a number to add to the seed and is
194
- optional.") do |args|
195
- require 'md5'
196
- max = args[0]
197
- if args[1] then
198
- seed = args[1]
199
- else
200
- seed = 1
201
- end
202
- fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex
203
- srand(seed+fqdn_seed)
204
- rand(max).to_s
205
- end
206
-
207
- newfunction(:fail, :doc => "Fail with a parse error.") do |vals|
208
- vals = vals.collect { |s| s.to_s }.join(" ") if vals.is_a? Array
209
- raise Puppet::ParseError, vals.to_s
210
- end
211
-
109
+
212
110
  # Runs a newfunction to create a function for each of the log levels
213
- Puppet::Util::Log.levels.each do |level|
214
- newfunction(level, :doc => "Log a message on the server at level
215
- #{level.to_s}.") do |vals|
216
- send(level, vals.join(" "))
217
- end
218
- end
219
-
220
- newfunction(:template, :type => :rvalue, :doc => "Evaluate a template and
221
- return its value. See `the templating docs </trac/puppet/wiki/PuppetTemplating>`_
222
- for more information. Note that if multiple templates are specified, their
223
- output is all concatenated and returned as the output of the function.
224
- ") do |vals|
225
- require 'erb'
226
-
227
- vals.collect do |file|
228
- # Use a wrapper, so the template can't get access to the full
229
- # Scope object.
230
- debug "Retrieving template %s" % file
231
- wrapper = Puppet::Parser::TemplateWrapper.new(self, file)
232
-
233
- begin
234
- wrapper.result()
235
- rescue => detail
236
- raise Puppet::ParseError,
237
- "Failed to parse template %s: %s" %
238
- [file, detail]
239
- end
240
- end.join("")
241
- end
242
-
243
- # This is just syntactic sugar for a collection, although it will generally
244
- # be a good bit faster.
245
- newfunction(:realize, :doc => "Make a virtual object real. This is useful
246
- when you want to know the name of the virtual object and don't want to
247
- bother with a full collection. It is slightly faster than a collection,
248
- and, of course, is a bit shorter. You must pass the object using a
249
- reference; e.g.: ``realize User[luke]``." ) do |vals|
250
- coll = Puppet::Parser::Collector.new(self, :nomatter, nil, nil, :virtual)
251
- vals = [vals] unless vals.is_a?(Array)
252
- coll.resources = vals
253
111
 
254
- compiler.add_collection(coll)
255
- end
256
-
257
- newfunction(:search, :doc => "Add another namespace for this class to search.
258
- This allows you to create classes with sets of definitions and add
259
- those classes to another class's search path.") do |vals|
260
- vals.each do |val|
261
- add_namespace(val)
112
+ Puppet::Util::Log.levels.each do |level|
113
+ newfunction(level, :doc => "Log a message on the server at level
114
+ #{level.to_s}.") do |vals|
115
+ send(level, vals.join(" "))
262
116
  end
263
117
  end
264
118
 
265
- newfunction(:file, :type => :rvalue,
266
- :doc => "Return the contents of a file. Multiple files
267
- can be passed, and the first file that exists will be read in.") do |vals|
268
- ret = nil
269
- vals.each do |file|
270
- unless file =~ /^#{File::SEPARATOR}/
271
- raise Puppet::ParseError, "Files must be fully qualified"
272
- end
273
- if FileTest.exists?(file)
274
- ret = File.read(file)
275
- break
276
- end
277
- end
278
- if ret
279
- ret
280
- else
281
- raise Puppet::ParseError, "Could not find any files from %s" %
282
- vals.join(", ")
283
- end
284
- end
285
-
286
- newfunction(:generate, :type => :rvalue,
287
- :doc => "Calls an external command and returns the results of the
288
- command. Any arguments are passed to the external command as
289
- arguments. If the generator does not exit with return code of 0,
290
- the generator is considered to have failed and a parse error is
291
- thrown. Generators can only have file separators, alphanumerics, dashes,
292
- and periods in them. This function will attempt to protect you from
293
- malicious generator calls (e.g., those with '..' in them), but it can
294
- never be entirely safe. No subshell is used to execute
295
- generators, so all shell metacharacters are passed directly to
296
- the generator.") do |args|
297
-
298
- unless args[0] =~ /^#{File::SEPARATOR}/
299
- raise Puppet::ParseError, "Generators must be fully qualified"
300
- end
301
-
302
- unless args[0] =~ /^[-#{File::SEPARATOR}\w.]+$/
303
- raise Puppet::ParseError,
304
- "Generators can only contain alphanumerics, file separators, and dashes"
305
- end
306
-
307
- if args[0] =~ /\.\./
308
- raise Puppet::ParseError,
309
- "Can not use generators with '..' in them."
310
- end
311
-
312
- begin
313
- output = Puppet::Util.execute(args)
314
- rescue Puppet::ExecutionFailure => detail
315
- raise Puppet::ParseError, "Failed to execute generator %s: %s" %
316
- [args[0], detail]
317
- end
318
- output
319
- end
320
-
321
- newfunction(:sha1, :type => :rvalue,
322
- :doc => "Returns a SHA1 hash value from a provided string.") do |args|
323
- require 'sha1'
324
-
325
- Digest::SHA1.hexdigest(args[0])
326
- end
327
-
328
119
  end
329
120
  end
330
-
@@ -0,0 +1,27 @@
1
+ # Test whether a given class or definition is defined
2
+ Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given
3
+ type is defined, either as a native type or a defined type, or whether a class is defined.
4
+ This is useful for checking whether a class is defined and only including it if it is.
5
+ This function can also test whether a resource has been defined, using resource references
6
+ (e.g., ``if defined(File['/tmp/myfile']) { ... }``). This function is unfortunately
7
+ dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals|
8
+ result = false
9
+ vals.each do |val|
10
+ case val
11
+ when String:
12
+ # For some reason, it doesn't want me to return from here.
13
+ if Puppet::Type.type(val) or finddefine(val) or findclass(val)
14
+ result = true
15
+ break
16
+ end
17
+ when Puppet::Parser::Resource::Reference:
18
+ if findresource(val.to_s)
19
+ result = true
20
+ break
21
+ end
22
+ else
23
+ raise ArgumentError, "Invalid argument of type %s to 'defined'" % val.class
24
+ end
25
+ end
26
+ result
27
+ end
@@ -0,0 +1,4 @@
1
+ Puppet::Parser::Functions::newfunction(:fail, :doc => "Fail with a parse error.") do |vals|
2
+ vals = vals.collect { |s| s.to_s }.join(" ") if vals.is_a? Array
3
+ raise Puppet::ParseError, vals.to_s
4
+ end
@@ -0,0 +1,21 @@
1
+ # Returns the contents of a file
2
+ Puppet::Parser::Functions::newfunction(:file, :type => :rvalue,
3
+ :doc => "Return the contents of a file. Multiple files
4
+ can be passed, and the first file that exists will be read in.") do |vals|
5
+ ret = nil
6
+ vals.each do |file|
7
+ unless file =~ /^#{File::SEPARATOR}/
8
+ raise Puppet::ParseError, "Files must be fully qualified"
9
+ end
10
+ if FileTest.exists?(file)
11
+ ret = File.read(file)
12
+ break
13
+ end
14
+ end
15
+ if ret
16
+ ret
17
+ else
18
+ raise Puppet::ParseError, "Could not find any files from %s" %
19
+ vals.join(", ")
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
2
+ "Generates random numbers based on the node's fqdn. The first argument
3
+ sets the range. The second argument specifies a number to add to the
4
+ seed and is optional.") do |args|
5
+ require 'md5'
6
+ max = args[0]
7
+ if args[1] then
8
+ seed = args[1]
9
+ else
10
+ seed = 1
11
+ end
12
+ fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex
13
+ srand(seed+fqdn_seed)
14
+ rand(max).to_s
15
+ end
@@ -0,0 +1,35 @@
1
+ # Runs an external command and returns the results
2
+ Puppet::Parser::Functions::newfunction(:generate, :type => :rvalue,
3
+ :doc => "Calls an external command and returns the results of the
4
+ command. Any arguments are passed to the external command as
5
+ arguments. If the generator does not exit with return code of 0,
6
+ the generator is considered to have failed and a parse error is
7
+ thrown. Generators can only have file separators, alphanumerics, dashes,
8
+ and periods in them. This function will attempt to protect you from
9
+ malicious generator calls (e.g., those with '..' in them), but it can
10
+ never be entirely safe. No subshell is used to execute
11
+ generators, so all shell metacharacters are passed directly to
12
+ the generator.") do |args|
13
+
14
+ unless args[0] =~ /^#{File::SEPARATOR}/
15
+ raise Puppet::ParseError, "Generators must be fully qualified"
16
+ end
17
+
18
+ unless args[0] =~ /^[-#{File::SEPARATOR}\w.]+$/
19
+ raise Puppet::ParseError,
20
+ "Generators can only contain alphanumerics, file separators, and dashes"
21
+ end
22
+
23
+ if args[0] =~ /\.\./
24
+ raise Puppet::ParseError,
25
+ "Can not use generators with '..' in them."
26
+ end
27
+
28
+ begin
29
+ output = Puppet::Util.execute(args)
30
+ rescue Puppet::ExecutionFailure => detail
31
+ raise Puppet::ParseError, "Failed to execute generator %s: %s" %
32
+ [args[0], detail]
33
+ end
34
+ output
35
+ end
@@ -0,0 +1,26 @@
1
+ # Include the specified classes
2
+ Puppet::Parser::Functions::newfunction(:include, :doc => "Evaluate one or more classes.") do |vals|
3
+ vals = [vals] unless vals.is_a?(Array)
4
+
5
+ # The 'false' disables lazy evaluation.
6
+ klasses = compiler.evaluate_classes(vals, self, false)
7
+
8
+ missing = vals.find_all do |klass|
9
+ ! klasses.include?(klass)
10
+ end
11
+
12
+ unless missing.empty?
13
+ # Throw an error if we didn't evaluate all of the classes.
14
+ str = "Could not find class"
15
+ if missing.length > 1
16
+ str += "es"
17
+ end
18
+
19
+ str += " " + missing.join(", ")
20
+
21
+ if n = namespaces and ! n.empty? and n != [""]
22
+ str += " in namespaces %s" % @namespaces.join(", ")
23
+ end
24
+ self.fail Puppet::ParseError, str
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # This is just syntactic sugar for a collection, although it will generally
2
+ # be a good bit faster.
3
+
4
+ Puppet::Parser::Functions::newfunction(:realize, :doc => "Make a virtual object real. This is useful
5
+ when you want to know the name of the virtual object and don't want to
6
+ bother with a full collection. It is slightly faster than a collection,
7
+ and, of course, is a bit shorter. You must pass the object using a
8
+ reference; e.g.: ``realize User[luke]``." ) do |vals|
9
+ coll = Puppet::Parser::Collector.new(self, :nomatter, nil, nil, :virtual)
10
+ vals = [vals] unless vals.is_a?(Array)
11
+ coll.resources = vals
12
+
13
+ compiler.add_collection(coll)
14
+ end
@@ -0,0 +1,7 @@
1
+ Puppet::Parser::Functions::newfunction(:search, :doc => "Add another namespace for this class to search.
2
+ This allows you to create classes with sets of definitions and add
3
+ those classes to another class's search path.") do |vals|
4
+ vals.each do |val|
5
+ add_namespace(val)
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue,
2
+ :doc => "Returns a SHA1 hash value from a provided string.") do |args|
3
+ require 'sha1'
4
+
5
+ Digest::SHA1.hexdigest(args[0])
6
+ end
@@ -0,0 +1,6 @@
1
+ # Tag the current scope with each passed name
2
+ Puppet::Parser::Functions::newfunction(:tag, :doc => "Add the specified tags to the containing class
3
+ or definition. All contained objects will then acquire that tag, also.
4
+ ") do |vals|
5
+ self.resource.tag(*vals)
6
+ end