puppet 0.18.4 → 0.22.4

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 (673) hide show
  1. data/CHANGELOG +288 -0
  2. data/README +2 -2
  3. data/Rakefile +78 -5
  4. data/bin/puppet +28 -36
  5. data/bin/puppetca +81 -38
  6. data/bin/puppetd +65 -62
  7. data/bin/puppetdoc +409 -140
  8. data/bin/puppetmasterd +59 -47
  9. data/bin/puppetrun +38 -23
  10. data/conf/freebsd/puppetd +26 -0
  11. data/conf/freebsd/puppetmasterd +26 -0
  12. data/conf/gentoo/conf.d/puppet +5 -0
  13. data/conf/gentoo/conf.d/puppetmaster +12 -0
  14. data/conf/gentoo/init.d/puppet +38 -0
  15. data/conf/gentoo/init.d/puppetmaster +50 -0
  16. data/conf/gentoo/puppet/fileserver.conf +12 -0
  17. data/conf/gentoo/puppet/puppetca.conf +29 -0
  18. data/conf/gentoo/puppet/puppetd.conf +29 -0
  19. data/conf/gentoo/puppet/puppetmasterd.conf +29 -0
  20. data/conf/redhat/client.init +10 -5
  21. data/conf/redhat/client.sysconfig +1 -1
  22. data/conf/redhat/fileserver.conf +2 -2
  23. data/conf/redhat/logrotate +1 -1
  24. data/conf/redhat/no-lockdir.patch +13 -0
  25. data/conf/redhat/puppet.spec +65 -8
  26. data/conf/redhat/puppetd.conf +0 -4
  27. data/conf/redhat/server.init +3 -6
  28. data/conf/solaris/pkginfo +1 -1
  29. data/conf/solaris/smf/svc-puppetd +2 -2
  30. data/conf/suse/client.init +142 -0
  31. data/conf/suse/puppet.spec +221 -0
  32. data/conf/suse/server.init +162 -0
  33. data/examples/code/mac_automount.pp +16 -0
  34. data/examples/root/bin/sleeper +3 -5
  35. data/examples/root/etc/init.d/sleeper +8 -2
  36. data/examples/root/etc/puppet/fileserver.conf +12 -2
  37. data/examples/root/etc/puppet/namespaceauth.conf +20 -0
  38. data/examples/root/etc/puppet/puppetd.conf +4 -0
  39. data/examples/root/etc/puppet/puppetmasterd.conf +6 -9
  40. data/examples/root/etc/puppet/tagmail.conf +1 -0
  41. data/ext/emacs/puppet-mode.el +46 -1
  42. data/ext/logcheck/puppet +15 -0
  43. data/ext/module_puppet +15 -23
  44. data/ext/vim/puppet.vim +4 -2
  45. data/install.rb +2 -1
  46. data/lib/puppet.rb +76 -207
  47. data/lib/puppet/configuration.rb +331 -0
  48. data/lib/puppet/daemon.rb +63 -246
  49. data/lib/puppet/dsl.rb +371 -0
  50. data/lib/puppet/element.rb +8 -26
  51. data/lib/puppet/error.rb +54 -0
  52. data/lib/puppet/event.rb +8 -243
  53. data/lib/puppet/{base64.rb → external/base64.rb} +0 -0
  54. data/lib/puppet/external/event-loop.rb +1 -0
  55. data/lib/puppet/{event-loop → external/event-loop}/better-definers.rb +0 -0
  56. data/lib/puppet/{event-loop → external/event-loop}/event-loop.rb +2 -2
  57. data/lib/puppet/{event-loop → external/event-loop}/signal-system.rb +1 -1
  58. data/lib/puppet/external/gratr.rb +33 -0
  59. data/lib/puppet/external/gratr/adjacency_graph.rb +257 -0
  60. data/lib/puppet/external/gratr/base.rb +34 -0
  61. data/lib/puppet/external/gratr/biconnected.rb +116 -0
  62. data/lib/puppet/external/gratr/chinese_postman.rb +123 -0
  63. data/lib/puppet/external/gratr/common.rb +73 -0
  64. data/lib/puppet/external/gratr/comparability.rb +92 -0
  65. data/lib/puppet/external/gratr/digraph.rb +116 -0
  66. data/lib/puppet/external/gratr/digraph_distance.rb +185 -0
  67. data/lib/puppet/external/gratr/dot.rb +90 -0
  68. data/lib/puppet/external/gratr/edge.rb +145 -0
  69. data/lib/puppet/external/gratr/graph.rb +303 -0
  70. data/lib/puppet/external/gratr/graph_api.rb +83 -0
  71. data/lib/puppet/external/gratr/import.rb +44 -0
  72. data/lib/puppet/external/gratr/labels.rb +90 -0
  73. data/lib/puppet/external/gratr/maximum_flow.rb +64 -0
  74. data/lib/puppet/external/gratr/rdot.rb +327 -0
  75. data/lib/puppet/external/gratr/search.rb +409 -0
  76. data/lib/puppet/external/gratr/strong_components.rb +127 -0
  77. data/lib/puppet/external/gratr/undirected_graph.rb +153 -0
  78. data/lib/puppet/{lock.rb → external/lock.rb} +1 -1
  79. data/lib/puppet/feature/base.rb +20 -0
  80. data/lib/puppet/feature/rails.rb +52 -0
  81. data/lib/puppet/metatype/attributes.rb +719 -0
  82. data/lib/puppet/metatype/closure.rb +111 -0
  83. data/lib/puppet/metatype/container.rb +94 -0
  84. data/lib/puppet/metatype/evaluation.rb +118 -0
  85. data/lib/puppet/metatype/instances.rb +261 -0
  86. data/lib/puppet/metatype/manager.rb +169 -0
  87. data/lib/puppet/metatype/metaparams.rb +409 -0
  88. data/lib/puppet/metatype/providers.rb +260 -0
  89. data/lib/puppet/metatype/relationships.rb +116 -0
  90. data/lib/puppet/metatype/schedules.rb +39 -0
  91. data/lib/puppet/metatype/tags.rb +39 -0
  92. data/lib/puppet/modules.rb +113 -0
  93. data/lib/puppet/network/authconfig.rb +168 -0
  94. data/lib/puppet/network/authorization.rb +84 -0
  95. data/lib/puppet/network/authstore.rb +293 -0
  96. data/lib/puppet/network/client.rb +187 -0
  97. data/lib/puppet/network/client/ca.rb +56 -0
  98. data/lib/puppet/network/client/dipper.rb +81 -0
  99. data/lib/puppet/network/client/file.rb +7 -0
  100. data/lib/puppet/network/client/logger.rb +6 -0
  101. data/lib/puppet/network/client/master.rb +644 -0
  102. data/lib/puppet/{client → network/client}/proxy.rb +3 -3
  103. data/lib/puppet/{client/reporter.rb → network/client/report.rb} +4 -7
  104. data/lib/puppet/{client/pelement.rb → network/client/resource.rb} +6 -19
  105. data/lib/puppet/network/client/runner.rb +13 -0
  106. data/lib/puppet/network/client/status.rb +5 -0
  107. data/lib/puppet/network/client_request.rb +32 -0
  108. data/lib/puppet/network/handler.rb +33 -0
  109. data/lib/puppet/{server → network/handler}/ca.rb +5 -6
  110. data/lib/puppet/network/handler/filebucket.rb +180 -0
  111. data/lib/puppet/{server → network/handler}/fileserver.rb +277 -219
  112. data/lib/puppet/{server → network/handler}/logger.rb +3 -5
  113. data/lib/puppet/{server → network/handler}/master.rb +42 -8
  114. data/lib/puppet/network/handler/report.rb +158 -0
  115. data/lib/puppet/network/handler/resource.rb +190 -0
  116. data/lib/puppet/{server → network/handler}/runner.rb +17 -18
  117. data/lib/puppet/network/handler/status.rb +13 -0
  118. data/lib/puppet/network/rights.rb +74 -0
  119. data/lib/puppet/network/server.rb +5 -0
  120. data/lib/puppet/network/server/mongrel.rb +138 -0
  121. data/lib/puppet/network/server/webrick.rb +153 -0
  122. data/lib/puppet/network/xmlrpc/client.rb +129 -0
  123. data/lib/puppet/network/xmlrpc/processor.rb +91 -0
  124. data/lib/puppet/network/xmlrpc/server.rb +20 -0
  125. data/lib/puppet/network/xmlrpc/webrick_servlet.rb +121 -0
  126. data/lib/puppet/parameter.rb +390 -346
  127. data/lib/puppet/parser/ast.rb +116 -147
  128. data/lib/puppet/parser/ast/astarray.rb +17 -33
  129. data/lib/puppet/parser/ast/branch.rb +2 -0
  130. data/lib/puppet/parser/ast/caseopt.rb +7 -12
  131. data/lib/puppet/parser/ast/casestatement.rb +23 -32
  132. data/lib/puppet/parser/ast/collection.rb +19 -80
  133. data/lib/puppet/parser/ast/collexpr.rb +81 -0
  134. data/lib/puppet/parser/ast/component.rb +160 -89
  135. data/lib/puppet/parser/ast/else.rb +30 -0
  136. data/lib/puppet/parser/ast/function.rb +9 -2
  137. data/lib/puppet/parser/ast/hostclass.rb +47 -131
  138. data/lib/puppet/parser/ast/ifstatement.rb +43 -0
  139. data/lib/puppet/parser/ast/leaf.rb +10 -21
  140. data/lib/puppet/parser/ast/node.rb +32 -79
  141. data/lib/puppet/parser/ast/resourcedef.rb +222 -0
  142. data/lib/puppet/parser/ast/{typedefaults.rb → resourcedefaults.rb} +10 -16
  143. data/lib/puppet/parser/ast/resourceoverride.rb +62 -0
  144. data/lib/puppet/parser/ast/{objectparam.rb → resourceparam.rb} +12 -6
  145. data/lib/puppet/parser/ast/resourceref.rb +44 -0
  146. data/lib/puppet/parser/ast/selector.rb +16 -8
  147. data/lib/puppet/parser/ast/tag.rb +3 -1
  148. data/lib/puppet/parser/ast/vardef.rb +8 -12
  149. data/lib/puppet/parser/collector.rb +181 -0
  150. data/lib/puppet/parser/functions.rb +191 -36
  151. data/lib/puppet/parser/interpreter.rb +802 -380
  152. data/lib/puppet/parser/lexer.rb +86 -19
  153. data/lib/puppet/parser/parser.rb +1123 -960
  154. data/lib/puppet/parser/resource.rb +353 -0
  155. data/lib/puppet/parser/resource/param.rb +57 -0
  156. data/lib/puppet/parser/resource/reference.rb +71 -0
  157. data/lib/puppet/parser/scope.rb +573 -1000
  158. data/lib/puppet/parser/templatewrapper.rb +54 -0
  159. data/lib/puppet/pgraph.rb +208 -0
  160. data/lib/puppet/propertychange.rb +143 -0
  161. data/lib/puppet/provider.rb +302 -0
  162. data/lib/puppet/provider/cron/crontab.rb +187 -0
  163. data/lib/puppet/provider/group/groupadd.rb +29 -0
  164. data/lib/puppet/provider/group/netinfo.rb +12 -0
  165. data/lib/puppet/provider/group/pw.rb +31 -0
  166. data/lib/puppet/provider/host/netinfo.rb +18 -0
  167. data/lib/puppet/provider/host/parsed.rb +73 -0
  168. data/lib/puppet/provider/mount.rb +57 -0
  169. data/lib/puppet/provider/mount/netinfo.rb +38 -0
  170. data/lib/puppet/provider/mount/parsed.rb +37 -0
  171. data/lib/puppet/provider/nameservice.rb +344 -0
  172. data/lib/puppet/provider/nameservice/netinfo.rb +210 -0
  173. data/lib/puppet/provider/nameservice/objectadd.rb +45 -0
  174. data/lib/puppet/provider/nameservice/pw.rb +22 -0
  175. data/lib/puppet/provider/package/apple.rb +53 -0
  176. data/lib/puppet/provider/package/apt.rb +119 -0
  177. data/lib/puppet/provider/package/aptitude.rb +30 -0
  178. data/lib/puppet/provider/package/aptrpm.rb +79 -0
  179. data/lib/puppet/provider/package/blastwave.rb +114 -0
  180. data/lib/puppet/provider/package/darwinport.rb +88 -0
  181. data/lib/puppet/provider/package/dpkg.rb +109 -0
  182. data/lib/puppet/provider/package/freebsd.rb +43 -0
  183. data/lib/puppet/provider/package/gem.rb +104 -0
  184. data/lib/puppet/provider/package/openbsd.rb +93 -0
  185. data/lib/puppet/provider/package/pkgdmg.rb +119 -0
  186. data/lib/puppet/provider/package/portage.rb +112 -0
  187. data/lib/puppet/provider/package/ports.rb +94 -0
  188. data/lib/puppet/provider/package/rpm.rb +125 -0
  189. data/lib/puppet/provider/package/rug.rb +53 -0
  190. data/lib/puppet/provider/package/sun.rb +168 -0
  191. data/lib/puppet/provider/package/sunfreeware.rb +9 -0
  192. data/lib/puppet/provider/package/up2date.rb +45 -0
  193. data/lib/puppet/provider/package/yum.rb +54 -0
  194. data/lib/puppet/provider/parsedfile.rb +342 -0
  195. data/lib/puppet/provider/port/parsed.rb +174 -0
  196. data/lib/puppet/provider/service/base.rb +136 -0
  197. data/lib/puppet/provider/service/debian.rb +32 -0
  198. data/lib/puppet/provider/service/gentoo.rb +49 -0
  199. data/lib/puppet/{type → provider}/service/init.rb +42 -40
  200. data/lib/puppet/provider/service/redhat.rb +59 -0
  201. data/lib/puppet/{type → provider}/service/smf.rb +24 -13
  202. data/lib/puppet/provider/sshkey/parsed.rb +36 -0
  203. data/lib/puppet/provider/user/netinfo.rb +106 -0
  204. data/lib/puppet/provider/user/pw.rb +41 -0
  205. data/lib/puppet/provider/user/useradd.rb +67 -0
  206. data/lib/puppet/provider/zone/solaris.rb +208 -0
  207. data/lib/puppet/rails.rb +102 -66
  208. data/lib/puppet/rails/database/001_add_indexes.rb +38 -0
  209. data/lib/puppet/rails/database/schema.rb +89 -0
  210. data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +62 -0
  211. data/lib/puppet/rails/external/tagging/init.rb +5 -0
  212. data/lib/puppet/rails/external/tagging/tag.rb +50 -0
  213. data/lib/puppet/rails/external/tagging/tagging.rb +12 -0
  214. data/lib/puppet/rails/fact_name.rb +7 -0
  215. data/lib/puppet/rails/fact_value.rb +5 -0
  216. data/lib/puppet/rails/host.rb +95 -46
  217. data/lib/puppet/rails/param_name.rb +28 -0
  218. data/lib/puppet/rails/param_value.rb +5 -0
  219. data/lib/puppet/rails/puppet_class.rb +9 -0
  220. data/lib/puppet/rails/resource.rb +95 -0
  221. data/lib/puppet/rails/source_file.rb +5 -0
  222. data/lib/puppet/relationship.rb +63 -0
  223. data/lib/puppet/reports/log.rb +14 -0
  224. data/lib/puppet/reports/rrdgraph.rb +114 -10
  225. data/lib/puppet/reports/store.rb +64 -0
  226. data/lib/puppet/reports/tagmail.rb +144 -71
  227. data/lib/puppet/sslcertificates.rb +38 -5
  228. data/lib/puppet/sslcertificates/ca.rb +142 -37
  229. data/lib/puppet/sslcertificates/certificate.rb +3 -3
  230. data/lib/puppet/sslcertificates/inventory.rb +53 -0
  231. data/lib/puppet/sslcertificates/support.rb +128 -0
  232. data/lib/puppet/transaction.rb +568 -189
  233. data/lib/puppet/transaction/report.rb +14 -3
  234. data/lib/puppet/transportable.rb +18 -10
  235. data/lib/puppet/type.rb +279 -2299
  236. data/lib/puppet/type/component.rb +63 -63
  237. data/lib/puppet/type/cron.rb +294 -710
  238. data/lib/puppet/type/exec.rb +185 -129
  239. data/lib/puppet/type/group.rb +38 -89
  240. data/lib/puppet/type/host.rb +110 -0
  241. data/lib/puppet/type/mount.rb +189 -0
  242. data/lib/puppet/type/notify.rb +47 -0
  243. data/lib/puppet/type/package.rb +129 -257
  244. data/lib/puppet/type/parsedtype.rb +172 -297
  245. data/lib/puppet/type/pfile.rb +540 -319
  246. data/lib/puppet/type/pfile/checksum.rb +103 -76
  247. data/lib/puppet/type/pfile/content.rb +16 -10
  248. data/lib/puppet/type/pfile/ensure.rb +52 -34
  249. data/lib/puppet/type/pfile/group.rb +25 -18
  250. data/lib/puppet/type/pfile/mode.rb +7 -4
  251. data/lib/puppet/type/pfile/{uid.rb → owner.rb} +21 -17
  252. data/lib/puppet/type/pfile/source.rb +119 -124
  253. data/lib/puppet/type/pfile/target.rb +29 -45
  254. data/lib/puppet/type/pfile/type.rb +2 -2
  255. data/lib/puppet/type/pfilebucket.rb +18 -14
  256. data/lib/puppet/type/port.rb +121 -0
  257. data/lib/puppet/type/property.rb +530 -0
  258. data/lib/puppet/type/resources.rb +150 -0
  259. data/lib/puppet/type/schedule.rb +38 -22
  260. data/lib/puppet/type/service.rb +70 -326
  261. data/lib/puppet/type/sshkey.rb +76 -0
  262. data/lib/puppet/type/tidy.rb +197 -97
  263. data/lib/puppet/type/user.rb +107 -183
  264. data/lib/puppet/type/yumrepo.rb +53 -34
  265. data/lib/puppet/type/zone.rb +55 -208
  266. data/lib/puppet/util.rb +239 -201
  267. data/lib/puppet/util/autoload.rb +107 -0
  268. data/lib/puppet/util/classgen.rb +208 -0
  269. data/lib/puppet/{config.rb → util/config.rb} +102 -54
  270. data/lib/puppet/util/docs.rb +104 -0
  271. data/lib/puppet/util/errors.rb +55 -0
  272. data/lib/puppet/util/execution.rb +22 -0
  273. data/lib/puppet/util/feature.rb +76 -0
  274. data/lib/puppet/util/fileparsing.rb +380 -0
  275. data/lib/puppet/util/filetype.rb +300 -0
  276. data/lib/puppet/util/graph.rb +39 -0
  277. data/lib/puppet/util/inifile.rb +209 -0
  278. data/lib/puppet/util/loadedfile.rb +71 -0
  279. data/lib/puppet/util/log.rb +549 -0
  280. data/lib/puppet/util/logging.rb +20 -0
  281. data/lib/puppet/util/metaid.rb +22 -0
  282. data/lib/puppet/util/methodhelper.rb +37 -0
  283. data/lib/puppet/util/metric.rb +160 -0
  284. data/lib/puppet/util/package.rb +31 -0
  285. data/lib/puppet/util/pidlock.rb +68 -0
  286. data/lib/puppet/util/plist.rb +24 -0
  287. data/lib/puppet/util/plist/generator.rb +226 -0
  288. data/lib/puppet/util/plist/parser.rb +227 -0
  289. data/lib/puppet/util/posix.rb +87 -0
  290. data/lib/puppet/util/provider_features.rb +170 -0
  291. data/lib/puppet/util/rails/collection_merger.rb +42 -0
  292. data/lib/puppet/util/storage.rb +103 -0
  293. data/lib/puppet/util/subclass_loader.rb +83 -0
  294. data/lib/puppet/util/suidmanager.rb +86 -0
  295. data/lib/puppet/util/variables.rb +39 -0
  296. data/lib/puppet/util/warnings.rb +15 -0
  297. data/test/Rakefile +97 -0
  298. data/test/certmgr/ca.rb +81 -0
  299. data/test/certmgr/certmgr.rb +77 -50
  300. data/test/certmgr/inventory.rb +79 -0
  301. data/test/certmgr/support.rb +81 -0
  302. data/test/executables/filebucket.rb +49 -0
  303. data/test/executables/puppetbin.rb +28 -12
  304. data/test/executables/puppetca.rb +75 -54
  305. data/test/executables/puppetd.rb +10 -13
  306. data/test/executables/puppetmasterd.rb +12 -17
  307. data/test/executables/puppetmodule.rb +18 -17
  308. data/test/language/ast.rb +242 -798
  309. data/test/language/ast/casestatement.rb +104 -0
  310. data/test/language/ast/component.rb +133 -0
  311. data/test/language/ast/hostclass.rb +162 -0
  312. data/test/language/ast/selector.rb +62 -0
  313. data/test/language/ast/variable.rb +31 -0
  314. data/test/language/collector.rb +369 -0
  315. data/test/language/functions.rb +305 -18
  316. data/test/language/interpreter.rb +894 -125
  317. data/test/language/lexer.rb +98 -12
  318. data/test/language/node.rb +37 -53
  319. data/test/language/parser.rb +455 -148
  320. data/test/language/resource.rb +535 -0
  321. data/test/language/scope.rb +451 -561
  322. data/test/language/snippets.rb +101 -111
  323. data/test/language/transportable.rb +6 -8
  324. data/test/lib/mocha.rb +19 -0
  325. data/test/lib/mocha/any_instance_method.rb +35 -0
  326. data/test/lib/mocha/auto_verify.rb +113 -0
  327. data/test/lib/mocha/central.rb +35 -0
  328. data/test/lib/mocha/class_method.rb +62 -0
  329. data/test/lib/mocha/expectation.rb +295 -0
  330. data/test/lib/mocha/expectation_error.rb +6 -0
  331. data/test/lib/mocha/infinite_range.rb +27 -0
  332. data/test/lib/mocha/inspect.rb +37 -0
  333. data/test/lib/mocha/instance_method.rb +8 -0
  334. data/test/lib/mocha/metaclass.rb +7 -0
  335. data/test/lib/mocha/mock.rb +20 -0
  336. data/test/lib/mocha/mock_methods.rb +122 -0
  337. data/test/lib/mocha/object.rb +100 -0
  338. data/test/lib/mocha/pretty_parameters.rb +28 -0
  339. data/test/lib/mocha/setup_and_teardown.rb +23 -0
  340. data/test/lib/mocha/standalone.rb +30 -0
  341. data/test/lib/mocha/test_case_adapter.rb +49 -0
  342. data/test/lib/mocha_standalone.rb +2 -0
  343. data/test/lib/puppettest.rb +294 -0
  344. data/test/lib/puppettest/certificates.rb +61 -0
  345. data/test/lib/puppettest/exetest.rb +123 -0
  346. data/test/lib/puppettest/fakes.rb +194 -0
  347. data/test/lib/puppettest/fileparsing.rb +33 -0
  348. data/test/lib/puppettest/filetesting.rb +231 -0
  349. data/test/lib/puppettest/graph.rb +41 -0
  350. data/test/lib/puppettest/parsertesting.rb +392 -0
  351. data/test/lib/puppettest/railstesting.rb +56 -0
  352. data/test/lib/puppettest/reporttesting.rb +19 -0
  353. data/test/lib/puppettest/resourcetesting.rb +73 -0
  354. data/test/lib/puppettest/servertest.rb +72 -0
  355. data/test/lib/puppettest/support.rb +8 -0
  356. data/test/lib/puppettest/support/assertions.rb +101 -0
  357. data/test/lib/puppettest/support/helpers.rb +23 -0
  358. data/test/lib/puppettest/support/resources.rb +37 -0
  359. data/test/lib/puppettest/support/utils.rb +160 -0
  360. data/test/lib/puppettest/testcase.rb +48 -0
  361. data/test/lib/rake/puppet_test_loader.rb +17 -0
  362. data/test/lib/rake/puppet_testtask.rb +17 -0
  363. data/test/lib/spec.rb +8 -0
  364. data/test/lib/spec/callback.rb +11 -0
  365. data/test/lib/spec/callback/callback_container.rb +60 -0
  366. data/test/lib/spec/callback/extensions/module.rb +24 -0
  367. data/test/lib/spec/callback/extensions/object.rb +37 -0
  368. data/test/lib/spec/deprecated.rb +3 -0
  369. data/test/lib/spec/expectations.rb +59 -0
  370. data/test/lib/spec/expectations/differs/default.rb +62 -0
  371. data/test/lib/spec/expectations/errors.rb +6 -0
  372. data/test/lib/spec/expectations/extensions.rb +3 -0
  373. data/test/lib/spec/expectations/extensions/object.rb +109 -0
  374. data/test/lib/spec/expectations/extensions/proc.rb +57 -0
  375. data/test/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
  376. data/test/lib/spec/expectations/handler.rb +47 -0
  377. data/test/lib/spec/expectations/should.rb +5 -0
  378. data/test/lib/spec/expectations/should/base.rb +64 -0
  379. data/test/lib/spec/expectations/should/change.rb +69 -0
  380. data/test/lib/spec/expectations/should/have.rb +128 -0
  381. data/test/lib/spec/expectations/should/not.rb +74 -0
  382. data/test/lib/spec/expectations/should/should.rb +81 -0
  383. data/test/lib/spec/expectations/sugar.rb +47 -0
  384. data/test/lib/spec/matchers.rb +160 -0
  385. data/test/lib/spec/matchers/be.rb +161 -0
  386. data/test/lib/spec/matchers/be_close.rb +37 -0
  387. data/test/lib/spec/matchers/change.rb +120 -0
  388. data/test/lib/spec/matchers/eql.rb +43 -0
  389. data/test/lib/spec/matchers/equal.rb +43 -0
  390. data/test/lib/spec/matchers/has.rb +44 -0
  391. data/test/lib/spec/matchers/have.rb +140 -0
  392. data/test/lib/spec/matchers/include.rb +50 -0
  393. data/test/lib/spec/matchers/match.rb +41 -0
  394. data/test/lib/spec/matchers/raise_error.rb +100 -0
  395. data/test/lib/spec/matchers/respond_to.rb +35 -0
  396. data/test/lib/spec/matchers/satisfy.rb +47 -0
  397. data/test/lib/spec/matchers/throw_symbol.rb +75 -0
  398. data/test/lib/spec/mocks.rb +232 -0
  399. data/test/lib/spec/mocks/argument_expectation.rb +132 -0
  400. data/test/lib/spec/mocks/error_generator.rb +85 -0
  401. data/test/lib/spec/mocks/errors.rb +10 -0
  402. data/test/lib/spec/mocks/extensions/object.rb +3 -0
  403. data/test/lib/spec/mocks/message_expectation.rb +231 -0
  404. data/test/lib/spec/mocks/methods.rb +40 -0
  405. data/test/lib/spec/mocks/mock.rb +26 -0
  406. data/test/lib/spec/mocks/mock_handler.rb +166 -0
  407. data/test/lib/spec/mocks/order_group.rb +29 -0
  408. data/test/lib/spec/rake/spectask.rb +173 -0
  409. data/test/lib/spec/rake/verify_rcov.rb +47 -0
  410. data/test/lib/spec/runner.rb +132 -0
  411. data/test/lib/spec/runner/backtrace_tweaker.rb +55 -0
  412. data/test/lib/spec/runner/command_line.rb +34 -0
  413. data/test/lib/spec/runner/context.rb +154 -0
  414. data/test/lib/spec/runner/context_eval.rb +142 -0
  415. data/test/lib/spec/runner/context_runner.rb +55 -0
  416. data/test/lib/spec/runner/drb_command_line.rb +21 -0
  417. data/test/lib/spec/runner/execution_context.rb +17 -0
  418. data/test/lib/spec/runner/extensions/kernel.rb +17 -0
  419. data/test/lib/spec/runner/extensions/object.rb +32 -0
  420. data/test/lib/spec/runner/formatter.rb +5 -0
  421. data/test/lib/spec/runner/formatter/base_text_formatter.rb +118 -0
  422. data/test/lib/spec/runner/formatter/html_formatter.rb +219 -0
  423. data/test/lib/spec/runner/formatter/progress_bar_formatter.rb +27 -0
  424. data/test/lib/spec/runner/formatter/rdoc_formatter.rb +22 -0
  425. data/test/lib/spec/runner/formatter/specdoc_formatter.rb +23 -0
  426. data/test/lib/spec/runner/heckle_runner.rb +71 -0
  427. data/test/lib/spec/runner/heckle_runner_win.rb +10 -0
  428. data/test/lib/spec/runner/option_parser.rb +224 -0
  429. data/test/lib/spec/runner/reporter.rb +105 -0
  430. data/test/lib/spec/runner/spec_matcher.rb +25 -0
  431. data/test/lib/spec/runner/spec_parser.rb +41 -0
  432. data/test/lib/spec/runner/spec_should_raise_handler.rb +74 -0
  433. data/test/lib/spec/runner/specification.rb +114 -0
  434. data/test/lib/spec/translator.rb +87 -0
  435. data/test/lib/spec/version.rb +30 -0
  436. data/test/lib/stubba.rb +2 -0
  437. data/test/network/authconfig.rb +72 -0
  438. data/test/network/authorization.rb +138 -0
  439. data/test/network/authstore.rb +450 -0
  440. data/test/network/client/ca.rb +38 -0
  441. data/test/{client → network/client}/client.rb +107 -24
  442. data/test/network/client/dipper.rb +35 -0
  443. data/test/network/client/master.rb +627 -0
  444. data/test/{client/pelement.rb → network/client/resource.rb} +13 -29
  445. data/test/network/client_request.rb +39 -0
  446. data/test/network/daemon.rb +71 -0
  447. data/test/{server → network/handler}/bucket.rb +103 -27
  448. data/test/{server → network/handler}/ca.rb +14 -19
  449. data/test/{server → network/handler}/fileserver.rb +443 -68
  450. data/test/network/handler/handler.rb +64 -0
  451. data/test/{server → network/handler}/logger.rb +26 -26
  452. data/test/network/handler/master.rb +352 -0
  453. data/test/network/handler/report.rb +185 -0
  454. data/test/{server/pelement.rb → network/handler/resource.rb} +25 -38
  455. data/test/{server → network/handler}/runner.rb +17 -16
  456. data/test/network/rights.rb +38 -0
  457. data/test/network/server/webrick.rb +140 -0
  458. data/test/network/xmlrpc/client.rb +68 -0
  459. data/test/network/xmlrpc/processor.rb +80 -0
  460. data/test/network/xmlrpc/server.rb +28 -0
  461. data/test/network/xmlrpc/webrick_servlet.rb +26 -0
  462. data/test/other/dsl.rb +218 -0
  463. data/test/other/events.rb +22 -15
  464. data/test/other/overrides.rb +9 -14
  465. data/test/other/pgraph.rb +289 -0
  466. data/test/other/propertychange.rb +142 -0
  467. data/test/other/provider.rb +162 -0
  468. data/test/other/puppet.rb +63 -10
  469. data/test/other/relationship.rb +74 -0
  470. data/test/other/relationships.rb +199 -123
  471. data/test/other/report.rb +152 -23
  472. data/test/other/transactions.rb +824 -78
  473. data/test/puppet/conffiles.rb +16 -11
  474. data/test/puppet/defaults.rb +7 -10
  475. data/test/puppet/{error.rb → errortest.rb} +5 -8
  476. data/test/puppet/modules.rb +58 -0
  477. data/test/puppet/tc_suidmanager.rb +107 -0
  478. data/test/rails/host.rb +177 -0
  479. data/test/rails/rails.rb +27 -0
  480. data/test/rails/railsparameter.rb +62 -0
  481. data/test/rails/railsresource.rb +100 -0
  482. data/test/ral/manager/attributes.rb +296 -0
  483. data/test/ral/manager/manager.rb +55 -0
  484. data/test/ral/manager/provider.rb +54 -0
  485. data/test/ral/manager/type.rb +837 -0
  486. data/test/ral/providers/cron/crontab.rb +346 -0
  487. data/test/ral/providers/group.rb +252 -0
  488. data/test/ral/providers/host/netinfo.rb +58 -0
  489. data/test/ral/providers/host/parsed.rb +226 -0
  490. data/test/ral/providers/mount/netinfo.rb +80 -0
  491. data/test/ral/providers/mount/parsed.rb +223 -0
  492. data/test/ral/providers/nameservice.rb +33 -0
  493. data/test/ral/providers/package.rb +253 -0
  494. data/test/ral/providers/package/apt.rb +89 -0
  495. data/test/ral/providers/package/aptitude.rb +69 -0
  496. data/test/ral/providers/package/aptrpm.rb +89 -0
  497. data/test/ral/providers/package/dpkg.rb +64 -0
  498. data/test/ral/providers/parsedfile.rb +668 -0
  499. data/test/ral/providers/parsedport.rb +233 -0
  500. data/test/ral/providers/provider.rb +423 -0
  501. data/test/{types → ral/providers}/service.rb +20 -121
  502. data/test/ral/providers/service/base.rb +75 -0
  503. data/test/ral/providers/sshkey/parsed.rb +111 -0
  504. data/test/ral/providers/user.rb +567 -0
  505. data/test/ral/providers/user/useradd.rb +250 -0
  506. data/test/ral/types/basic.rb +90 -0
  507. data/test/ral/types/component.rb +113 -0
  508. data/test/ral/types/cron.rb +480 -0
  509. data/test/{types → ral/types}/exec.rb +278 -82
  510. data/test/ral/types/file.rb +1799 -0
  511. data/test/ral/types/file/target.rb +363 -0
  512. data/test/{types → ral/types}/filebucket.rb +15 -17
  513. data/test/{types → ral/types}/fileignoresource.rb +9 -15
  514. data/test/ral/types/filesources.rb +1046 -0
  515. data/test/ral/types/group.rb +169 -0
  516. data/test/ral/types/host.rb +155 -0
  517. data/test/ral/types/mount.rb +312 -0
  518. data/test/ral/types/package.rb +85 -0
  519. data/test/ral/types/parameter.rb +172 -0
  520. data/test/ral/types/port.rb +148 -0
  521. data/test/ral/types/property.rb +343 -0
  522. data/test/ral/types/resources.rb +221 -0
  523. data/test/{types → ral/types}/schedule.rb +34 -12
  524. data/test/ral/types/service.rb +37 -0
  525. data/test/{types → ral/types}/sshkey.rb +75 -65
  526. data/test/ral/types/tidy.rb +240 -0
  527. data/test/ral/types/user.rb +493 -0
  528. data/test/{types → ral/types}/yumrepo.rb +7 -11
  529. data/test/{types → ral/types}/zone.rb +45 -45
  530. data/test/tagging/tagging.rb +17 -26
  531. data/test/util/autoload.rb +130 -0
  532. data/test/util/classgen.rb +227 -0
  533. data/test/{other → util}/config.rb +373 -113
  534. data/test/util/execution.rb +34 -0
  535. data/test/util/features.rb +94 -0
  536. data/test/util/fileparsing.rb +677 -0
  537. data/test/{other → util}/filetype.rb +9 -12
  538. data/test/util/graph.rb +108 -0
  539. data/test/{other → util}/inifile.rb +24 -11
  540. data/test/util/loadedfile.rb +106 -0
  541. data/test/{other → util}/log.rb +96 -50
  542. data/test/{other → util}/metrics.rb +7 -17
  543. data/test/util/package.rb +27 -0
  544. data/test/util/pidlock.rb +126 -0
  545. data/test/util/posixtest.rb +173 -0
  546. data/test/util/storage.rb +123 -0
  547. data/test/util/subclass_loader.rb +100 -0
  548. data/test/util/utiltest.rb +368 -0
  549. metadata +449 -169
  550. data/examples/code/classing +0 -35
  551. data/examples/code/failers/badclassnoparam +0 -10
  552. data/examples/code/failers/badclassparam +0 -10
  553. data/examples/code/failers/badcompnoparam +0 -9
  554. data/examples/code/failers/badcompparam +0 -9
  555. data/examples/code/failers/badtypeparam +0 -3
  556. data/examples/code/failers/noobjectrvalue +0 -1
  557. data/examples/code/snippets/aliastest.pp +0 -16
  558. data/examples/code/snippets/argumentdefaults +0 -14
  559. data/examples/code/snippets/casestatement.pp +0 -58
  560. data/examples/code/snippets/classheirarchy.pp +0 -15
  561. data/examples/code/snippets/classincludes.pp +0 -17
  562. data/examples/code/snippets/classpathtest +0 -11
  563. data/examples/code/snippets/componentmetaparams.pp +0 -11
  564. data/examples/code/snippets/deepclassheirarchy.pp +0 -23
  565. data/examples/code/snippets/defineoverrides.pp +0 -17
  566. data/examples/code/snippets/dirchmod +0 -19
  567. data/examples/code/snippets/emptyclass.pp +0 -9
  568. data/examples/code/snippets/emptyexec.pp +0 -3
  569. data/examples/code/snippets/failmissingexecpath.pp +0 -13
  570. data/examples/code/snippets/falsevalues.pp +0 -3
  571. data/examples/code/snippets/filecreate +0 -11
  572. data/examples/code/snippets/implicititeration +0 -15
  573. data/examples/code/snippets/multipleinstances +0 -7
  574. data/examples/code/snippets/namevartest +0 -9
  575. data/examples/code/snippets/scopetest +0 -13
  576. data/examples/code/snippets/selectorvalues.pp +0 -42
  577. data/examples/code/snippets/simpledefaults +0 -5
  578. data/examples/code/snippets/simpleselector +0 -38
  579. data/examples/code/snippets/singleary.pp +0 -19
  580. data/examples/code/snippets/singlequote.pp +0 -11
  581. data/examples/code/snippets/singleselector.pp +0 -22
  582. data/examples/code/snippets/tag.pp +0 -9
  583. data/examples/code/snippets/tagged.pp +0 -35
  584. data/lib/puppet/client.rb +0 -177
  585. data/lib/puppet/client/ca.rb +0 -21
  586. data/lib/puppet/client/dipper.rb +0 -76
  587. data/lib/puppet/client/file.rb +0 -20
  588. data/lib/puppet/client/log.rb +0 -17
  589. data/lib/puppet/client/master.rb +0 -531
  590. data/lib/puppet/client/runner.rb +0 -17
  591. data/lib/puppet/client/status.rb +0 -7
  592. data/lib/puppet/event-loop.rb +0 -1
  593. data/lib/puppet/filetype.rb +0 -308
  594. data/lib/puppet/inifile.rb +0 -201
  595. data/lib/puppet/log.rb +0 -524
  596. data/lib/puppet/metric.rb +0 -132
  597. data/lib/puppet/networkclient.rb +0 -175
  598. data/lib/puppet/parsedfile.rb +0 -58
  599. data/lib/puppet/parser/ast/classdef.rb +0 -79
  600. data/lib/puppet/parser/ast/compdef.rb +0 -75
  601. data/lib/puppet/parser/ast/nodedef.rb +0 -73
  602. data/lib/puppet/parser/ast/objectdef.rb +0 -284
  603. data/lib/puppet/parser/ast/objectref.rb +0 -77
  604. data/lib/puppet/rails/database.rb +0 -40
  605. data/lib/puppet/rails/rails_object.rb +0 -42
  606. data/lib/puppet/rails/rails_parameter.rb +0 -5
  607. data/lib/puppet/server.rb +0 -196
  608. data/lib/puppet/server/authconfig.rb +0 -177
  609. data/lib/puppet/server/authstore.rb +0 -226
  610. data/lib/puppet/server/filebucket.rb +0 -155
  611. data/lib/puppet/server/pelement.rb +0 -188
  612. data/lib/puppet/server/report.rb +0 -184
  613. data/lib/puppet/server/rights.rb +0 -78
  614. data/lib/puppet/server/servlet.rb +0 -274
  615. data/lib/puppet/statechange.rb +0 -129
  616. data/lib/puppet/storage.rb +0 -98
  617. data/lib/puppet/type/nameservice.rb +0 -264
  618. data/lib/puppet/type/nameservice/netinfo.rb +0 -232
  619. data/lib/puppet/type/nameservice/objectadd.rb +0 -146
  620. data/lib/puppet/type/nameservice/posix.rb +0 -12
  621. data/lib/puppet/type/nameservice/pw.rb +0 -107
  622. data/lib/puppet/type/package/apple.rb +0 -41
  623. data/lib/puppet/type/package/apt.rb +0 -107
  624. data/lib/puppet/type/package/blastwave.rb +0 -136
  625. data/lib/puppet/type/package/darwinport.rb +0 -97
  626. data/lib/puppet/type/package/dpkg.rb +0 -113
  627. data/lib/puppet/type/package/freebsd.rb +0 -19
  628. data/lib/puppet/type/package/gem.rb +0 -119
  629. data/lib/puppet/type/package/openbsd.rb +0 -112
  630. data/lib/puppet/type/package/ports.rb +0 -103
  631. data/lib/puppet/type/package/rpm.rb +0 -121
  632. data/lib/puppet/type/package/sun.rb +0 -174
  633. data/lib/puppet/type/package/sunfreeware.rb +0 -7
  634. data/lib/puppet/type/package/yum.rb +0 -52
  635. data/lib/puppet/type/parsedtype/host.rb +0 -144
  636. data/lib/puppet/type/parsedtype/mount.rb +0 -271
  637. data/lib/puppet/type/parsedtype/port.rb +0 -261
  638. data/lib/puppet/type/parsedtype/sshkey.rb +0 -123
  639. data/lib/puppet/type/service/base.rb +0 -12
  640. data/lib/puppet/type/service/debian.rb +0 -46
  641. data/lib/puppet/type/service/redhat.rb +0 -38
  642. data/lib/puppet/type/state.rb +0 -393
  643. data/lib/puppet/type/symlink.rb +0 -186
  644. data/test/client/master.rb +0 -207
  645. data/test/language/rails.rb +0 -105
  646. data/test/other/parsedfile.rb +0 -58
  647. data/test/other/storage.rb +0 -100
  648. data/test/puppet/utiltest.rb +0 -299
  649. data/test/puppettest.rb +0 -1170
  650. data/test/server/authconfig.rb +0 -56
  651. data/test/server/authstore.rb +0 -218
  652. data/test/server/master.rb +0 -201
  653. data/test/server/report.rb +0 -93
  654. data/test/server/rights.rb +0 -41
  655. data/test/server/server.rb +0 -152
  656. data/test/test +0 -61
  657. data/test/types/basic.rb +0 -117
  658. data/test/types/component.rb +0 -298
  659. data/test/types/cron.rb +0 -718
  660. data/test/types/file.rb +0 -1314
  661. data/test/types/filesources.rb +0 -590
  662. data/test/types/group.rb +0 -323
  663. data/test/types/host.rb +0 -186
  664. data/test/types/mount.rb +0 -294
  665. data/test/types/package.rb +0 -538
  666. data/test/types/parameter.rb +0 -107
  667. data/test/types/port.rb +0 -201
  668. data/test/types/query.rb +0 -101
  669. data/test/types/state.rb +0 -92
  670. data/test/types/symlink.rb +0 -120
  671. data/test/types/tidy.rb +0 -102
  672. data/test/types/type.rb +0 -469
  673. data/test/types/user.rb +0 -563
@@ -6,6 +6,11 @@ require 'puppet'
6
6
  # in the transaction.
7
7
  class Puppet::Transaction::Report
8
8
  attr_accessor :logs, :metrics, :time, :host
9
+
10
+ def <<(msg)
11
+ @logs << msg
12
+ return self
13
+ end
9
14
 
10
15
  def initialize
11
16
  @metrics = {}
@@ -15,12 +20,18 @@ class Puppet::Transaction::Report
15
20
  hash[key] = []
16
21
  end
17
22
 
18
- @host = [Facter.value("hostname"), Facter.value("domain")].join(".")
23
+ domain = Facter.value("domain")
24
+ hostname = Facter.value("hostname")
25
+ if !domain || domain.empty? then
26
+ @host = hostname
27
+ else
28
+ @host = [hostname, domain].join(".")
29
+ end
19
30
  end
20
31
 
21
32
  # Create a new metric.
22
33
  def newmetric(name, hash)
23
- metric = Puppet::Metric.new(name)
34
+ metric = Puppet::Util::Metric.new(name)
24
35
 
25
36
  hash.each do |name, value|
26
37
  metric.newvalue(name, value)
@@ -39,4 +50,4 @@ class Puppet::Transaction::Report
39
50
  end
40
51
  end
41
52
 
42
- # $Id: report.rb 1361 2006-07-04 16:43:16Z luke $
53
+ # $Id: report.rb 2246 2007-02-28 17:03:21Z luke $
@@ -47,8 +47,12 @@ module Puppet
47
47
  end
48
48
 
49
49
  def to_manifest
50
- "#{self.type.to_s} { \"#{self.name}\":\n%s\n}" % @params.collect { |p, v|
51
- " #{p} => \"#{v}\""
50
+ "#{self.type.to_s} { \'#{self.name}\':\n%s\n}" % @params.collect { |p, v|
51
+ if v.is_a? Array
52
+ " #{p} => [\'#{v.join("','")}\']"
53
+ else
54
+ " #{p} => \'#{v}\'"
55
+ end
52
56
  }.join(",\n")
53
57
  end
54
58
 
@@ -137,8 +141,8 @@ module Puppet
137
141
  end.flatten
138
142
  end
139
143
 
140
- def initialize
141
- @children = []
144
+ def initialize(children = [])
145
+ @children = children
142
146
  end
143
147
 
144
148
  def push(*args)
@@ -215,7 +219,7 @@ module Puppet
215
219
  else
216
220
  #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
217
221
  end
218
- container = Puppet.type(:component).create(trans)
222
+ container = Puppet::Type::Component.create(trans)
219
223
  else
220
224
  hash = {
221
225
  :name => self.name,
@@ -234,7 +238,7 @@ module Puppet
234
238
  #if parent
235
239
  # hash[:parent] = parent
236
240
  #end
237
- container = Puppet.type(:component).create(hash)
241
+ container = Puppet::Type::Component.create(hash)
238
242
  end
239
243
  #Puppet.info container.inspect
240
244
 
@@ -260,9 +264,13 @@ module Puppet
260
264
  end
261
265
 
262
266
  # Now just call to_type on them with the container as a parent
263
- unless obj = child.to_type(container)
264
- # nothing; we assume the method already warned
265
- #Puppet.warning "Could not create child %s" % child.name
267
+ begin
268
+ child.to_type(container)
269
+ rescue => detail
270
+ if Puppet[:trace] and ! detail.is_a?(Puppet::Error)
271
+ puts detail.backtrace
272
+ end
273
+ Puppet.err detail.to_s
266
274
  end
267
275
  }
268
276
 
@@ -282,4 +290,4 @@ module Puppet
282
290
  #------------------------------------------------------------
283
291
  end
284
292
 
285
- # $Id: transportable.rb 1256 2006-06-13 15:57:06Z luke $
293
+ # $Id: transportable.rb 2068 2007-01-10 03:25:25Z lutter $
@@ -1,51 +1,47 @@
1
1
  require 'puppet'
2
- require 'puppet/log'
2
+ require 'puppet/util/log'
3
3
  require 'puppet/element'
4
4
  require 'puppet/event'
5
- require 'puppet/metric'
6
- require 'puppet/type/state'
5
+ require 'puppet/util/metric'
6
+ require 'puppet/type/property'
7
7
  require 'puppet/parameter'
8
8
  require 'puppet/util'
9
+ require 'puppet/util/autoload'
10
+ require 'puppet/metatype/manager'
11
+
9
12
  # see the bottom of the file for the rest of the inclusions
10
13
 
11
14
  module Puppet
12
- # The type is unknown
13
- class UnknownTypeError < Puppet::Error; end
14
15
  class Type < Puppet::Element
16
+ # Nearly all of the code in this class is stored in files in the
17
+ # metatype/ directory. This is a temporary measure until I get a chance
18
+ # to refactor this class entirely. There's still more simplification to
19
+ # do, but this works for now.
20
+ require 'puppet/metatype/attributes'
21
+ require 'puppet/metatype/closure'
22
+ require 'puppet/metatype/container'
23
+ require 'puppet/metatype/evaluation'
24
+ require 'puppet/metatype/instances'
25
+ require 'puppet/metatype/metaparams'
26
+ require 'puppet/metatype/providers'
27
+ require 'puppet/metatype/relationships'
28
+ require 'puppet/metatype/schedules'
29
+ require 'puppet/metatype/tags'
15
30
 
16
31
  # Types (which map to elements in the languages) are entirely composed of
17
32
  # attribute value pairs. Generally, Puppet calls any of these things an
18
33
  # 'attribute', but these attributes always take one of three specific
19
- # forms: parameters, metaparams, or states.
34
+ # forms: parameters, metaparams, or properties.
20
35
 
21
36
  # In naming methods, I have tried to consistently name the method so
22
37
  # that it is clear whether it operates on all attributes (thus has 'attr' in
23
38
  # the method name, or whether it operates on a specific type of attributes.
24
- attr_accessor :children
25
39
  attr_accessor :file, :line
26
- attr_reader :tags, :parent
40
+ attr_reader :parent
27
41
 
28
- attr_writer :implicit
29
- def implicit?
30
- if defined? @implicit and @implicit
31
- return true
32
- else
33
- return false
34
- end
35
- end
42
+ attr_writer :title
36
43
 
37
44
  include Enumerable
38
-
39
- # a little fakery, since Puppet itself isn't a type
40
- # I don't think this is used any more, now that the language can't
41
- # call methods
42
- #@name = :puppet
43
-
44
- # set it to something to silence the tests, but otherwise not used
45
- #@namevar = :notused
46
-
47
- # again, silence the tests; the :notused has to be there because it's
48
- # the namevar
49
45
 
50
46
  # class methods dealing with Type management
51
47
 
@@ -53,64 +49,10 @@ class Type < Puppet::Element
53
49
 
54
50
  # the Type class attribute accessors
55
51
  class << self
56
- attr_reader :name, :states
57
-
58
- include Enumerable
59
-
60
- #def inspect
61
- # "Type(%s)" % self.name
62
- #end
63
-
64
- # This class is aggregatable, meaning that instances are defined on
65
- # one system but instantiated on another
66
- def isaggregatable
67
- @aggregatable = true
68
- end
69
-
70
- # Is this one aggregatable?
71
- def aggregatable?
72
- if defined? @aggregatable
73
- return @aggregatable
74
- else
75
- return false
76
- end
77
- end
78
- end
79
-
80
- # iterate across all of the subclasses of Type
81
- def self.eachtype
82
- @types.each do |name, type|
83
- # Only consider types that have names
84
- #if ! type.parameters.empty? or ! type.validstates.empty?
85
- yield type
86
- #end
87
- end
88
- end
89
-
90
- # Create the 'ensure' class. This is a separate method so other types
91
- # can easily call it and create their own 'ensure' values.
92
- def self.ensurable(&block)
93
- if block_given?
94
- self.newstate(:ensure, Puppet::State::Ensure, &block)
95
- else
96
- self.newstate(:ensure, Puppet::State::Ensure) do
97
- self.defaultvalues
98
- end
99
- end
100
- end
101
-
102
- # Should we add the 'ensure' state to this class?
103
- def self.ensurable?
104
- # If the class has all three of these methods defined, then it's
105
- # ensurable.
106
- #ens = [:create, :destroy].inject { |set, method|
107
- ens = [:exists?, :create, :destroy].inject { |set, method|
108
- set &&= self.public_method_defined?(method)
109
- }
110
-
111
- #puts "%s ensurability: %s" % [self.name, ens]
112
-
113
- return ens
52
+ attr_reader :name
53
+ attr_accessor :self_refresh
54
+ include Enumerable, Puppet::Util::ClassGen
55
+ include Puppet::MetaType::Manager
114
56
  end
115
57
 
116
58
  # all of the variables that must be initialized for each subclass
@@ -119,11 +61,19 @@ class Type < Puppet::Element
119
61
  @objects = Hash.new
120
62
  @aliases = Hash.new
121
63
 
64
+ @providers = Hash.new
65
+ @defaults = {}
66
+
122
67
  unless defined? @parameters
123
68
  @parameters = []
124
69
  end
125
70
 
126
- @validstates = {}
71
+ @validproperties = {}
72
+ @properties = []
73
+ @parameters = []
74
+ @paramhash = {}
75
+
76
+ @attr_aliases = {}
127
77
 
128
78
  @paramdoc = Hash.new { |hash,key|
129
79
  if key.is_a?(String)
@@ -140,2301 +90,331 @@ class Type < Puppet::Element
140
90
  @doc = ""
141
91
  end
142
92
 
143
- unless defined? @states
144
- @states = []
93
+ end
94
+
95
+ def self.to_s
96
+ if defined? @name
97
+ "Puppet::Type::" + @name.to_s.capitalize
98
+ else
99
+ super
145
100
  end
101
+ end
146
102
 
103
+ # Create a block to validate that our object is set up entirely. This will
104
+ # be run before the object is operated on.
105
+ def self.validate(&block)
106
+ define_method(:validate, &block)
107
+ #@validate = block
147
108
  end
148
109
 
149
- # Do an on-demand plugin load
150
- def self.loadplugin(name)
151
- unless Puppet[:pluginpath].split(":").include?(Puppet[:plugindest])
152
- Puppet.notice "Adding plugin destination %s to plugin search path" %
153
- Puppet[:plugindest]
154
- Puppet[:pluginpath] += ":" + Puppet[:plugindest]
110
+ # iterate across all children, and then iterate across properties
111
+ # we do children first so we're sure that all dependent objects
112
+ # are checked first
113
+ # we ignore parameters here, because they only modify how work gets
114
+ # done, they don't ever actually result in work specifically
115
+ def each
116
+ # we want to return the properties in the order that each type
117
+ # specifies it, because it may (as in the case of File#create)
118
+ # be important
119
+ if self.class.depthfirst?
120
+ @children.each { |child|
121
+ yield child
122
+ }
155
123
  end
156
- Puppet[:pluginpath].split(":").each do |dir|
157
- file = ::File.join(dir, name.to_s + ".rb")
158
- if FileTest.exists?(file)
159
- begin
160
- load file
161
- Puppet.info "loaded %s" % file
162
- return true
163
- rescue LoadError => detail
164
- Puppet.info "Could not load %s: %s" %
165
- [file, detail]
166
- return false
167
- end
168
- end
124
+ self.eachproperty { |property|
125
+ yield property
126
+ }
127
+ unless self.class.depthfirst?
128
+ @children.each { |child|
129
+ yield child
130
+ }
169
131
  end
170
132
  end
171
133
 
172
- # Define a new type.
173
- def self.newtype(name, parent = nil, &block)
174
- parent ||= Puppet::Type
175
- name = Puppet::Util.symbolize(name)
176
-
177
- # Create the class, with the correct name.
178
- t = Class.new(parent) do
179
- @name = name
134
+ # Recurse deeply through the tree, but only yield types, not properties.
135
+ def delve(&block)
136
+ self.each do |obj|
137
+ if obj.is_a? Puppet::Type
138
+ obj.delve(&block)
139
+ end
180
140
  end
141
+ block.call(self)
142
+ end
143
+
144
+ # create a log at specified level
145
+ def log(msg)
146
+ Puppet::Util::Log.create(
147
+ :level => @parameters[:loglevel].value,
148
+ :message => msg,
149
+ :source => self
150
+ )
151
+ end
181
152
 
182
- # Used for method manipulation.
183
- selfobj = class << self; self; end
184
-
185
- const = name.to_s.capitalize
186
- newmethod = "new#{name.to_s}"
187
-
188
- @types ||= {}
189
153
 
190
- if @types.include?(name) and const_defined?(const)
191
- Puppet.info "Redefining %s" % name
192
- remove_const(const)
154
+ # instance methods related to instance intrinsics
155
+ # e.g., initialize() and name()
193
156
 
194
- if self.respond_to?(newmethod)
195
- # Remove the old newmethod, too
196
- selfobj.send(:remove_method,newmethod)
197
- end
198
- end
199
- const_set(name.to_s.capitalize,t)
157
+ public
200
158
 
201
- # Initialize any necessary variables.
202
- t.initvars
159
+ def initvars
160
+ @children = []
161
+ @evalcount = 0
162
+ @tags = []
203
163
 
204
- # Evaluate the passed block. This should usually define all of the work.
205
- t.class_eval(&block)
164
+ # callbacks are per object and event
165
+ @callbacks = Hash.new { |chash, key|
166
+ chash[key] = {}
167
+ }
206
168
 
207
- # If they've got all the necessary methods defined and they haven't
208
- # already added the state, then do so now.
209
- if t.ensurable? and ! t.validstate?(:ensure)
210
- t.ensurable
169
+ # properties and parameters are treated equivalently from the outside:
170
+ # as name-value pairs (using [] and []=)
171
+ # internally, however, parameters are merely a hash, while properties
172
+ # point to Property objects
173
+ # further, the lists of valid properties and parameters are defined
174
+ # at the class level
175
+ unless defined? @parameters
176
+ @parameters = {}
211
177
  end
212
178
 
213
- # And add it to our bucket.
214
- @types[name] = t
179
+ # set defalts
180
+ @noop = false
181
+ # keeping stats for the total number of changes, and how many were
182
+ # completely sync'ed
183
+ # this isn't really sufficient either, because it adds lots of special
184
+ # cases such as failed changes
185
+ # it also doesn't distinguish between changes from the current transaction
186
+ # vs. changes over the process lifetime
187
+ @totalchanges = 0
188
+ @syncedchanges = 0
189
+ @failedchanges = 0
190
+
191
+ @inited = true
192
+ end
215
193
 
216
- # Now define a "new<type>" method for convenience.
217
- if self.respond_to? newmethod
218
- # Refuse to overwrite existing methods like 'newparam' or 'newtype'.
219
- Puppet.warning "'new#{name.to_s}' method already exists; skipping"
220
- else
221
- selfobj.send(:define_method, newmethod) do |*args|
222
- t.create(*args)
223
- end
194
+ # initialize the type instance
195
+ def initialize(hash)
196
+ unless defined? @inited
197
+ self.initvars
224
198
  end
199
+ namevar = self.class.namevar
225
200
 
226
- t
227
- end
201
+ orighash = hash
228
202
 
229
- # Return a Type instance by name.
230
- def self.type(name)
231
- @types ||= {}
203
+ # If we got passed a transportable object, we just pull a bunch of info
204
+ # directly from it. This is the main object instantiation mechanism.
205
+ if hash.is_a?(Puppet::TransObject)
206
+ #self[:name] = hash[:name]
207
+ [:file, :line, :tags].each { |getter|
208
+ if hash.respond_to?(getter)
209
+ setter = getter.to_s + "="
210
+ if val = hash.send(getter)
211
+ self.send(setter, val)
212
+ end
213
+ end
214
+ }
232
215
 
233
- if name.is_a?(String)
234
- name = name.intern
216
+ # XXX This will need to change when transobjects change to titles.
217
+ @title = hash.name
218
+ hash = hash.to_hash
219
+ elsif hash[:title]
220
+ # XXX This should never happen
221
+ @title = hash[:title]
222
+ hash.delete(:title)
235
223
  end
236
224
 
237
- unless @types.include? name
238
- begin
239
- require "puppet/type/#{name}"
240
- unless @types.include? name
241
- Puppet.warning "Loaded puppet/type/#{name} but no class was created"
242
- end
243
- rescue LoadError => detail
244
- # If we can't load it from there, try loading it as a plugin.
245
- loadplugin(name)
246
- end
225
+ # Before anything else, set our parent if it was included
226
+ if hash.include?(:parent)
227
+ @parent = hash[:parent]
228
+ hash.delete(:parent)
247
229
  end
248
230
 
249
- @types[name]
250
- end
231
+ # Munge up the namevar stuff so we only have one value.
232
+ hash = self.argclean(hash)
251
233
 
252
- # class methods dealing with type instance management
234
+ # Let's do the name first, because some things need to happen once
235
+ # we have the name but before anything else
253
236
 
254
- public
237
+ attrs = self.class.allattrs
255
238
 
256
- # Create an alias. We keep these in a separate hash so that we don't encounter
257
- # the objects multiple times when iterating over them.
258
- def self.alias(name, obj)
259
- if @objects.include?(name)
260
- unless @objects[name] == obj
261
- raise Puppet::Error.new(
262
- "Cannot create alias %s: object already exists" %
263
- [name]
264
- )
239
+ if hash.include?(namevar)
240
+ #self.send(namevar.to_s + "=", hash[namevar])
241
+ self[namevar] = hash[namevar]
242
+ hash.delete(namevar)
243
+ if attrs.include?(namevar)
244
+ attrs.delete(namevar)
245
+ else
246
+ self.devfail "My namevar isn\'t a valid attribute...?"
265
247
  end
248
+ else
249
+ self.devfail "I was not passed a namevar"
266
250
  end
267
251
 
268
- if @aliases.include?(name)
269
- unless @aliases[name] == obj
270
- raise Puppet::Error.new(
271
- "Object %s already has alias %s" %
272
- [@aliases[name].name, name]
273
- )
252
+ # If the name and title differ, set up an alias
253
+ if self.name != self.title
254
+ if obj = self.class[self.name]
255
+ if self.class.isomorphic?
256
+ raise Puppet::Error, "%s already exists with name %s" %
257
+ [obj.title, self.name]
258
+ end
259
+ else
260
+ self.class.alias(self.name, self)
274
261
  end
275
262
  end
276
263
 
277
- @aliases[name] = obj
278
- end
279
-
280
- # retrieve a named instance of the current type
281
- def self.[](name)
282
- if @objects.has_key?(name)
283
- return @objects[name]
284
- elsif @aliases.has_key?(name)
285
- return @aliases[name]
286
- else
287
- return nil
288
- end
289
- end
290
-
291
- # add an instance by name to the class list of instances
292
- def self.[]=(name,object)
293
- newobj = nil
294
- if object.is_a?(Puppet::Type)
295
- newobj = object
264
+ if hash.include?(:provider)
265
+ self[:provider] = hash[:provider]
266
+ hash.delete(:provider)
296
267
  else
297
- raise Puppet::DevError, "must pass a Puppet::Type object"
268
+ setdefaults(:provider)
298
269
  end
299
270
 
300
- if exobj = @objects.has_key?(name) and self.isomorphic?
301
- msg = "Object '%s[%s]' already exists" %
302
- [name, newobj.class.name]
303
-
304
- if exobj.file and exobj.line
305
- msg += ("in file %s at line %s" %
306
- [object.file, object.line])
307
- end
308
- if object.file and object.line
309
- msg += ("and cannot be redefined in file %s at line %s" %
310
- [object.file, object.line])
271
+ # This is all of our attributes except the namevar.
272
+ attrs.each { |attr|
273
+ if hash.include?(attr)
274
+ begin
275
+ self[attr] = hash[attr]
276
+ rescue ArgumentError, Puppet::Error, TypeError
277
+ raise
278
+ rescue => detail
279
+ self.devfail(
280
+ "Could not set %s on %s: %s" %
281
+ [attr, self.class.name, detail]
282
+ )
283
+ end
284
+ hash.delete attr
311
285
  end
312
- error = Puppet::Error.new(msg)
313
- else
314
- #Puppet.info("adding %s of type %s to class list" %
315
- # [name,object.class])
316
- @objects[name] = newobj
317
- end
318
- end
319
-
320
- # remove all type instances; this is mostly only useful for testing
321
- def self.allclear
322
- Puppet::Event::Subscription.clear
323
- @types.each { |name, type|
324
- type.clear
325
286
  }
326
- end
287
+
288
+ # Set all default values.
289
+ self.setdefaults
327
290
 
328
- # remove all of the instances of a single type
329
- def self.clear
330
- if defined? @objects
331
- @objects.each do |name, obj|
332
- obj.remove(true)
333
- end
334
- @objects.clear
335
- end
336
- if defined? @aliases
337
- @aliases.clear
291
+ if hash.length > 0
292
+ self.debug hash.inspect
293
+ self.fail("Class %s does not accept argument(s) %s" %
294
+ [self.class.name, hash.keys.join(" ")])
338
295
  end
339
- end
340
296
 
341
- # remove a specified object
342
- def self.delete(object)
343
- return unless defined? @objects
344
- if @objects.include?(object.name)
345
- @objects.delete(object.name)
297
+ if self.respond_to?(:validate)
298
+ self.validate
346
299
  end
347
300
  end
348
301
 
349
- # iterate across each of the type's instances
350
- def self.each
351
- return unless defined? @objects
352
- @objects.each { |name,instance|
353
- yield instance
354
- }
302
+ # Set up all of our autorequires.
303
+ def finish
304
+ # Scheduling has to be done when the whole config is instantiated, so
305
+ # that file order doesn't matter in finding them.
306
+ self.schedule
355
307
  end
356
308
 
357
- # does the type have an object with the given name?
358
- def self.has_key?(name)
359
- return @objects.has_key?(name)
309
+ # Return a cached value
310
+ def cached(name)
311
+ Puppet::Util::Storage.cache(self)[name]
312
+ #@cache[name] ||= nil
360
313
  end
361
314
 
362
- # Allow an outside party to specify the 'is' value for a state. The
363
- # arguments are an array because you can't use parens with 'is=' calls.
364
- # Most classes won't use this.
365
- def is=(ary)
366
- param, value = ary
367
- if param.is_a?(String)
368
- param = param.intern
369
- end
370
- if self.class.validstate?(param)
371
- unless @states.include?(param)
372
- self.newstate(param)
373
- end
374
- @states[param].is = value
375
- else
376
- self[param] = value
377
- end
315
+ # Cache a value
316
+ def cache(name, value)
317
+ Puppet::Util::Storage.cache(self)[name] = value
318
+ #@cache[name] = value
378
319
  end
379
320
 
380
- # class and instance methods dealing with parameters and states
381
-
382
- public
321
+ # def set(name, value)
322
+ # send(name.to_s + "=", value)
323
+ # end
324
+ #
325
+ # def get(name)
326
+ # send(name)
327
+ # end
383
328
 
384
- # build a per-Type hash, mapping the states to their names
385
- def self.buildstatehash
386
- unless defined? @validstates
387
- @validstates = Hash.new(false)
388
- end
389
- return unless defined? @states
390
- @states.each { |stateklass|
391
- name = stateklass.name
392
- if @validstates.include?(name)
393
- if @validstates[name] != stateklass
394
- raise Puppet::Error.new("Redefining state %s(%s) in %s" %
395
- [name,stateklass,self])
396
- else
397
- # it's already there, so don't bother
398
- end
399
- else
400
- @validstates[name] = stateklass
401
- end
402
- }
329
+ # For now, leave the 'name' method functioning like it used to. Once 'title'
330
+ # works everywhere, I'll switch it.
331
+ def name
332
+ return self[:name]
403
333
  end
404
334
 
405
- # Find the namevar
406
- def self.namevar
407
- unless defined? @namevar
408
- return nil unless defined? @parameters and ! @parameters.empty?
409
- @namevar = @parameters.find { |name, param|
410
- param.isnamevar?
411
- unless param
412
- raise Puppet::DevError, "huh? %s" % name
413
- end
414
- }[0].value
415
- end
416
- @namevar
335
+ # Return the "type[name]" style reference.
336
+ def ref
337
+ "%s[%s]" % [self.class.name.to_s.capitalize, self.title]
338
+ end
339
+
340
+ def self_refresh?
341
+ self.class.self_refresh
417
342
  end
418
343
 
419
- # Copy an existing class parameter. This allows other types to avoid
420
- # duplicating a parameter definition, and is mostly used by subclasses
421
- # of the File class.
422
- def self.copyparam(klass, name)
423
- param = klass.attrclass(name)
424
-
425
- unless param
426
- raise Puppet::DevError, "Class %s has no param %s" % [klass, name]
427
- end
428
- @parameters ||= []
429
- @parameters << param
430
-
431
- @paramhash ||= {}
432
- @parameters.each { |p| @paramhash[name] = p }
344
+ # Mark that we're purging.
345
+ def purging
346
+ @purging = true
347
+ end
433
348
 
434
- if param.isnamevar?
435
- @namevar = param.name
349
+ # Is this resource being purged? Used by transactions to forbid
350
+ # deletion when there are dependencies.
351
+ def purging?
352
+ if defined? @purging
353
+ @purging
354
+ else
355
+ false
436
356
  end
437
357
  end
438
358
 
439
- # Create a new metaparam. Requires a block and a name, stores it in the
440
- # @parameters array, and does some basic checking on it.
441
- def self.newmetaparam(name, &block)
442
- name = Puppet::Util.symbolize(name)
443
- param = Class.new(Puppet::Parameter) do
444
- @name = name
359
+ # Retrieve the title of an object. If no title was set separately,
360
+ # then use the object's name.
361
+ def title
362
+ unless defined? @title and @title
363
+ namevar = self.class.namevar
364
+ if self.class.validparameter?(namevar)
365
+ @title = self[:name]
366
+ elsif self.class.validproperty?(namevar)
367
+ @title = self.should(namevar)
368
+ else
369
+ self.devfail "Could not find namevar %s for %s" %
370
+ [namevar, self.class.name]
371
+ end
445
372
  end
446
373
 
447
- param.initvars
448
-
449
- param.ismetaparameter
450
- param.class_eval(&block)
451
- const_set("MetaParam" + name.to_s.capitalize,param)
452
- @@metaparams ||= []
453
- @@metaparams << param
454
-
455
- @@metaparamhash ||= {}
456
- @@metaparams.each { |p| @@metaparamhash[name] = p }
457
-
458
- return param
374
+ return @title
459
375
  end
460
376
 
461
- def self.eachmetaparam
462
- @@metaparams.each { |p| yield p.name }
377
+ # convert to a string
378
+ def to_s
379
+ self.ref
463
380
  end
464
381
 
465
- # Create a new parameter. Requires a block and a name, stores it in the
466
- # @parameters array, and does some basic checking on it.
467
- def self.newparam(name, &block)
468
- name = Puppet::Util.symbolize(name)
469
- param = Class.new(Puppet::Parameter) do
470
- @name = name
382
+ # Convert to a transportable object
383
+ def to_trans(ret = true)
384
+ # Retrieve the object, if they tell use to.
385
+ if ret
386
+ retrieve()
471
387
  end
472
388
 
473
- param.initvars
474
-
475
- param.element = self
476
- param.class_eval(&block)
477
- const_set("Parameter" + name.to_s.capitalize,param)
478
- @parameters ||= []
479
- @parameters << param
389
+ trans = TransObject.new(self.title, self.class.name)
480
390
 
481
- @paramhash ||= {}
482
- @parameters.each { |p| @paramhash[name] = p }
483
-
484
- # These might be enabled later.
485
- # define_method(name) do
486
- # @parameters[name].value
487
- # end
488
- #
489
- # define_method(name.to_s + "=") do |value|
490
- # newparam(param, value)
491
- # end
492
-
493
- if param.isnamevar?
494
- @namevar = param.name
391
+ properties().each do |property|
392
+ trans[property.name] = property.is
495
393
  end
496
394
 
497
- return param
498
- end
499
-
500
- # Create a new state.
501
- def self.newstate(name, parent = nil, &block)
502
- parent ||= Puppet::State
503
- if @validstates.include?(name)
504
- raise Puppet::DevError, "Class %s already has a state named %s" %
505
- [self.name, name]
506
- end
507
- s = Class.new(parent) do
508
- @name = name
395
+ @parameters.each do |name, param|
396
+ # Avoid adding each instance name as both the name and the namevar
397
+ next if param.class.isnamevar? and param.value == self.title
398
+ trans[name] = param.value
509
399
  end
510
400
 
511
- s.initvars
401
+ trans.tags = self.tags
512
402
 
513
- const_set("State" + name.to_s.capitalize,s)
514
- s.class_eval(&block)
515
- @states ||= []
403
+ # FIXME I'm currently ignoring 'parent' and 'path'
516
404
 
517
- # If it's the 'ensure' state, always put it first.
518
- if name == :ensure
519
- @states.unshift s
520
- else
521
- @states << s
522
- end
523
- @validstates[name] = s
405
+ return trans
406
+ end
524
407
 
525
- # define_method(name) do
526
- # @states[name].should
527
- # end
528
- #
529
- # define_method(name.to_s + "=") do |value|
530
- # newstate(name, :should => value)
531
- # end
532
-
533
- return s
534
- end
535
-
536
- # Specify a block for generating a list of objects to autorequire. This
537
- # makes it so that you don't have to manually specify things that you clearly
538
- # require.
539
- def self.autorequire(name, &block)
540
- @autorequires ||= {}
541
- @autorequires[name] = block
542
- end
543
-
544
- # Yield each of those autorequires in turn, yo.
545
- def self.eachautorequire
546
- @autorequires ||= {}
547
- @autorequires.each { |type, block|
548
- yield(type, block)
549
- }
550
- end
551
-
552
- # Return the parameter names
553
- def self.parameters
554
- return [] unless defined? @parameters
555
- @parameters.collect { |klass| klass.name }
556
- end
557
-
558
- # Find the metaparameter class associated with a given metaparameter name.
559
- def self.metaparamclass(name)
560
- @@metaparamhash[name]
561
- end
562
-
563
- # Find the parameter class associated with a given parameter name.
564
- def self.paramclass(name)
565
- @paramhash[name]
566
- end
567
-
568
- # Find the class associated with any given attribute.
569
- def self.attrclass(name)
570
- @attrclasses ||= {}
571
-
572
- # We cache the value, since this method gets called such a huge number
573
- # of times (as in, hundreds of thousands in a given run).
574
- unless @attrclasses.include?(name)
575
- @attrclasses[name] = case self.attrtype(name)
576
- when :state: @validstates[name]
577
- when :meta: @@metaparamhash[name]
578
- when :param: @paramhash[name]
579
- end
580
- end
581
- @attrclasses[name]
582
- end
583
-
584
- def self.to_s
585
- if defined? @name
586
- "Puppet::Type::" + @name.to_s.capitalize
587
- else
588
- super
589
- end
590
- end
591
-
592
- # Create a block to validate that our object is set up entirely. This will
593
- # be run before the object is operated on.
594
- def self.validate(&block)
595
- define_method(:validate, &block)
596
- #@validate = block
597
- end
598
-
599
- # does the name reflect a valid state?
600
- def self.validstate?(name)
601
- unless @validstates.length == @states.length
602
- self.buildstatehash
603
- end
604
- if @validstates.include?(name)
605
- return @validstates[name]
606
- else
607
- return false
608
- end
609
- end
610
-
611
- # Return the list of validstates
612
- def self.validstates
613
- return {} unless defined? @states
614
- unless @validstates.length == @states.length
615
- self.buildstatehash
616
- end
617
-
618
- return @validstates.keys
619
- end
620
-
621
- # Return the state class associated with a name
622
- def self.statebyname(name)
623
- unless @validstates.length == @states.length
624
- self.buildstatehash
625
- end
626
- @validstates[name]
627
- end
628
-
629
- # does the name reflect a valid parameter?
630
- def self.validparameter?(name)
631
- unless defined? @parameters
632
- raise Puppet::DevError, "Class %s has not defined parameters" % self
633
- end
634
- if @paramhash.include?(name) or @@metaparamhash.include?(name)
635
- return true
636
- else
637
- return false
638
- end
639
- end
640
-
641
- # What type of parameter are we dealing with? Cache the results, because
642
- # this method gets called so many times.
643
- def self.attrtype(name)
644
- @attrtypes ||= {}
645
- unless @attrtypes.include?(name)
646
- @attrtypes[name] = case
647
- when @validstates.include?(name): :state
648
- when @@metaparamhash.include?(name): :meta
649
- when @paramhash.include?(name): :param
650
- else
651
- raise Puppet::DevError, "Invalid attribute '%s' for class '%s'" %
652
- [name, self.name]
653
- end
654
- end
655
-
656
- @attrtypes[name]
657
- end
658
-
659
- # All parameters, in the appropriate order. The namevar comes first,
660
- # then the states, then the params and metaparams in the order they
661
- # were specified in the files.
662
- def self.allattrs
663
- # now get all of the arguments, in a specific order
664
- # Cache this, since it gets called so many times
665
- namevar = self.namevar
666
-
667
- order = [namevar]
668
- order << [self.states.collect { |state| state.name },
669
- self.parameters,
670
- self.metaparams].flatten.reject { |param|
671
- # we don't want our namevar in there multiple times
672
- param == namevar
673
- }
674
-
675
- order.flatten!
676
-
677
- return order
678
- end
679
-
680
- # A similar function but one that yields the name, type, and class.
681
- # This is mainly so that setdefaults doesn't call quite so many functions.
682
- def self.eachattr(*ary)
683
- # now get all of the arguments, in a specific order
684
- # Cache this, since it gets called so many times
685
-
686
- if ary.empty?
687
- ary = nil
688
- end
689
- self.states.each { |state|
690
- yield(state, :state) if ary.nil? or ary.include?(state.name)
691
- }
692
-
693
- @parameters.each { |param|
694
- yield(param, :param) if ary.nil? or ary.include?(param.name)
695
- }
696
-
697
- @@metaparams.each { |param|
698
- yield(param, :meta) if ary.nil? or ary.include?(param.name)
699
- }
700
- end
701
-
702
- def self.validattr?(name)
703
- if name.is_a?(String)
704
- name = name.intern
705
- end
706
- if self.validstate?(name) or self.validparameter?(name) or self.metaparam?(name)
707
- return true
708
- else
709
- return false
710
- end
711
- end
712
-
713
- # abstract accessing parameters and states, and normalize
714
- # access to always be symbols, not strings
715
- # This returns a value, not an object. It returns the 'is'
716
- # value, but you can also specifically return 'is' and 'should'
717
- # values using 'object.is(:state)' or 'object.should(:state)'.
718
- def [](name)
719
- if name.is_a?(String)
720
- name = name.intern
721
- end
722
-
723
- if name == :name
724
- name = self.class.namevar
725
- end
726
- case self.class.attrtype(name)
727
- when :state
728
- if @states.include?(name)
729
- return @states[name].is
730
- else
731
- return nil
732
- end
733
- when :meta
734
- if @metaparams.include?(name)
735
- return @metaparams[name].value
736
- else
737
- if default = self.class.metaparamclass(name).default
738
- return default
739
- else
740
- return nil
741
- end
742
- end
743
- when :param
744
- if @parameters.include?(name)
745
- return @parameters[name].value
746
- else
747
- if default = self.class.paramclass(name).default
748
- return default
749
- else
750
- return nil
751
- end
752
- end
753
- else
754
- raise TypeError.new("Invalid parameter %s(%s)" % [name, name.inspect])
755
- end
756
- end
757
-
758
- # Abstract setting parameters and states, and normalize
759
- # access to always be symbols, not strings. This sets the 'should'
760
- # value on states, and otherwise just sets the appropriate parameter.
761
- def []=(name,value)
762
- if name.is_a?(String)
763
- name = name.intern
764
- end
765
-
766
- if name == :name
767
- name = self.class.namevar
768
- end
769
- if value.nil?
770
- raise Puppet::Error.new("Got nil value for %s" % name)
771
- end
772
-
773
- case self.class.attrtype(name)
774
- when :state
775
- if value.is_a?(Puppet::State)
776
- self.debug "'%s' got handed a state for '%s'" % [self,name]
777
- @states[name] = value
778
- else
779
- if @states.include?(name)
780
- @states[name].should = value
781
- else
782
- # newstate returns true if it successfully created the state,
783
- # false otherwise; I just don't know what to do with that
784
- # fact.
785
- unless newstate(name, :should => value)
786
- #self.info "%s failed" % name
787
- end
788
- end
789
- end
790
- when :meta
791
- self.newmetaparam(self.class.metaparamclass(name), value)
792
- when :param
793
- klass = self.class.attrclass(name)
794
- # if they've got a method to handle the parameter, then do it that way
795
- self.newparam(klass, value)
796
- else
797
- raise Puppet::Error, "Invalid parameter %s" % [name]
798
- end
799
- end
800
-
801
- # remove a state from the object; useful in testing or in cleanup
802
- # when an error has been encountered
803
- def delete(attr)
804
- case attr
805
- when Puppet::Type
806
- if @children.include?(attr)
807
- @children.delete(attr)
808
- end
809
- else
810
- if @states.has_key?(attr)
811
- @states.delete(attr)
812
- elsif @parameters.has_key?(attr)
813
- @parameters.delete(attr)
814
- elsif @metaparams.has_key?(attr)
815
- @metaparams.delete(attr)
816
- else
817
- raise Puppet::DevError.new("Undefined attribute '#{attr}' in #{self}")
818
- end
819
- end
820
- end
821
-
822
- # iterate across all children, and then iterate across states
823
- # we do children first so we're sure that all dependent objects
824
- # are checked first
825
- # we ignore parameters here, because they only modify how work gets
826
- # done, they don't ever actually result in work specifically
827
- def each
828
- # we want to return the states in the order that each type
829
- # specifies it, because it may (as in the case of File#create)
830
- # be important
831
- if self.class.depthfirst?
832
- @children.each { |child|
833
- yield child
834
- }
835
- end
836
- self.eachstate { |state|
837
- yield state
838
- }
839
- unless self.class.depthfirst?
840
- @children.each { |child|
841
- yield child
842
- }
843
- end
844
- end
845
-
846
- # Recurse deeply through the tree, but only yield types, not states.
847
- def delve(&block)
848
- self.each do |obj|
849
- if obj.is_a? Puppet::Type
850
- obj.delve(&block)
851
- end
852
- end
853
- block.call(self)
854
- end
855
-
856
- # iterate across the existing states
857
- def eachstate
858
- # states() is a private method
859
- states().each { |state|
860
- yield state
861
- }
862
- end
863
-
864
- def devfail(msg)
865
- self.fail(Puppet::DevError, msg)
866
- end
867
-
868
- # Throw an error, defaulting to a Puppet::Error
869
- def fail(*args)
870
- type = nil
871
- if args[0].is_a?(Class)
872
- type = args.shift
873
- else
874
- type = Puppet::Error
875
- end
876
-
877
- error = type.new(args.join(" "))
878
-
879
- if defined? @line and @line
880
- error.line = @line
881
- end
882
-
883
- if defined? @file and @file
884
- error.file = @file
885
- end
886
-
887
- raise error
888
- end
889
-
890
- # retrieve the 'is' value for a specified state
891
- def is(state)
892
- if @states.include?(state)
893
- return @states[state].is
894
- else
895
- return nil
896
- end
897
- end
898
-
899
- # retrieve the 'should' value for a specified state
900
- def should(state)
901
- if @states.include?(state)
902
- return @states[state].should
903
- else
904
- return nil
905
- end
906
- end
907
-
908
- # create a log at specified level
909
- def log(msg)
910
- Puppet::Log.create(
911
- :level => @metaparams[:loglevel].value,
912
- :message => msg,
913
- :source => self
914
- )
915
- end
916
-
917
- # is the instance a managed instance? A 'yes' here means that
918
- # the instance was created from the language, vs. being created
919
- # in order resolve other questions, such as finding a package
920
- # in a list
921
- def managed?
922
- # Once an object is managed, it always stays managed; but an object
923
- # that is listed as unmanaged might become managed later in the process,
924
- # so we have to check that every time
925
- if defined? @managed and @managed
926
- return @managed
927
- else
928
- @managed = false
929
- states.each { |state|
930
- if state.should and ! state.class.unmanaged
931
- @managed = true
932
- break
933
- end
934
- }
935
- return @managed
936
- end
937
- end
938
-
939
- # Create a new parameter.
940
- def newparam(klass, value = nil)
941
- newattr(:param, klass, value)
942
- end
943
-
944
- # Create a new parameter or metaparameter. We'll leave the calling
945
- # method to store it appropriately.
946
- def newmetaparam(klass, value = nil)
947
- newattr(:meta, klass, value)
948
- end
949
-
950
- # The base function that the others wrap.
951
- def newattr(type, klass, value = nil)
952
- # This should probably be a bit, um, different, but...
953
- if type == :state
954
- return newstate(klass)
955
- end
956
- param = klass.new
957
- param.parent = self
958
-
959
- unless value.nil?
960
- param.value = value
961
- end
962
-
963
- case type
964
- when :meta
965
- @metaparams[klass.name] = param
966
- when :param
967
- @parameters[klass.name] = param
968
- else
969
- self.devfail("Invalid param type %s" % type)
970
- end
971
-
972
- return param
973
- end
974
-
975
- # create a new state
976
- def newstate(name, hash = {})
977
- stateklass = nil
978
- if name.is_a?(Class)
979
- stateklass = name
980
- name = stateklass.name
981
- else
982
- stateklass = self.class.validstate?(name)
983
- unless stateklass
984
- self.fail("Invalid state %s" % name)
985
- end
986
- end
987
- if @states.include?(name)
988
- hash.each { |var,value|
989
- @states[name].send(var.to_s + "=", value)
990
- }
991
- else
992
- #Puppet.warning "Creating state %s for %s" %
993
- # [stateklass.name,self.name]
994
- begin
995
- hash[:parent] = self
996
- # make sure the state doesn't have any errors
997
- newstate = stateklass.new(hash)
998
- @states[name] = newstate
999
- return newstate
1000
- rescue Puppet::Error => detail
1001
- # the state failed, so just ignore it
1002
- self.warning "State %s failed: %s" %
1003
- [name, detail]
1004
- return false
1005
- rescue Puppet::DevError => detail
1006
- # the state failed, so just ignore it
1007
- self.err "State %s failed: %s" %
1008
- [name, detail]
1009
- return false
1010
- rescue => detail
1011
- # the state failed, so just ignore it
1012
- self.err "State %s failed: %s (%s)" %
1013
- [name, detail, detail.class]
1014
- return false
1015
- end
1016
- end
1017
- end
1018
-
1019
- # return the value of a parameter
1020
- def parameter(name)
1021
- unless name.is_a? Symbol
1022
- name = name.intern
1023
- end
1024
- return @parameters[name].value
1025
- end
1026
-
1027
- def parent=(parent)
1028
- if self.parentof?(parent)
1029
- devfail "%s[%s] is already the parent of %s[%s]" %
1030
- [self.class.name, self.name, parent.class.name, parent.name]
1031
- end
1032
- @parent = parent
1033
- end
1034
-
1035
- # Add a hook for testing for recursion.
1036
- def parentof?(child)
1037
- if (self == child)
1038
- debug "parent is equal to child"
1039
- return true
1040
- elsif defined? @parent and @parent.parentof?(child)
1041
- debug "My parent is parent of child"
1042
- return true
1043
- elsif @children.include?(child)
1044
- debug "child is already in children array"
1045
- return true
1046
- else
1047
- return false
1048
- end
1049
- end
1050
-
1051
- def push(*childs)
1052
- unless defined? @children
1053
- @children = []
1054
- end
1055
- childs.each { |child|
1056
- # Make sure we don't have any loops here.
1057
- if parentof?(child)
1058
- devfail "Already the parent of %s[%s]" % [child.class.name, child.name]
1059
- end
1060
- unless child.is_a?(Puppet::Element)
1061
- self.debug "Got object of type %s" % child.class
1062
- self.devfail(
1063
- "Containers can only contain Puppet::Elements, not %s" %
1064
- child.class
1065
- )
1066
- end
1067
- @children.push(child)
1068
- child.parent = self
1069
- }
1070
- end
1071
-
1072
- # Remove an object. The argument determines whether the object's
1073
- # subscriptions get eliminated, too.
1074
- def remove(rmdeps = true)
1075
- # Our children remove themselves from our @children array (else the object
1076
- # we called this on at the top would not be removed), so we duplicate the
1077
- # array and iterate over that. If we don't do this, only half of the
1078
- # objects get removed.
1079
- @children.dup.each { |child|
1080
- child.remove(rmdeps)
1081
- }
1082
-
1083
- @children.clear
1084
-
1085
- # This is hackish (mmm, cut and paste), but it works for now, and it's
1086
- # better than warnings.
1087
- [@states, @parameters, @metaparams].each do |hash|
1088
- hash.each do |name, obj|
1089
- obj.remove
1090
- end
1091
-
1092
- hash.clear
1093
- end
1094
-
1095
- if rmdeps
1096
- Puppet::Event::Subscription.dependencies(self).each { |dep|
1097
- #info "Deleting dependency %s" % dep
1098
- #begin
1099
- # self.unsubscribe(dep)
1100
- #rescue
1101
- # # ignore failed unsubscribes
1102
- #end
1103
- dep.delete
1104
- }
1105
- Puppet::Event::Subscription.subscribers(self).each { |dep|
1106
- #info "Unsubscribing from %s" % dep
1107
- begin
1108
- dep.unsubscribe(self)
1109
- rescue
1110
- # ignore failed unsubscribes
1111
- end
1112
- }
1113
- end
1114
- self.class.delete(self)
1115
-
1116
- if defined? @parent and @parent
1117
- @parent.delete(self)
1118
- @parent = nil
1119
- end
1120
- end
1121
-
1122
- # Is the named state defined?
1123
- def statedefined?(name)
1124
- unless name.is_a? Symbol
1125
- name = name.intern
1126
- end
1127
- return @states.include?(name)
1128
- end
1129
-
1130
- # return an actual type by name; to return the value, use 'inst[name]'
1131
- # FIXME this method should go away
1132
- def state(name)
1133
- unless name.is_a? Symbol
1134
- name = name.intern
1135
- end
1136
- return @states[name]
1137
- end
1138
-
1139
- private
1140
-
1141
- def states
1142
- #debug "%s has %s states" % [self,@states.length]
1143
- tmpstates = []
1144
- self.class.states.each { |state|
1145
- if @states.include?(state.name)
1146
- tmpstates.push(@states[state.name])
1147
- end
1148
- }
1149
- unless tmpstates.length == @states.length
1150
- self.devfail(
1151
- "Something went very wrong with tmpstates creation"
1152
- )
1153
- end
1154
- return tmpstates
1155
- end
1156
-
1157
-
1158
- # instance methods related to instance intrinsics
1159
- # e.g., initialize() and name()
1160
-
1161
- public
1162
-
1163
- # Force users to call this, so that we can merge objects if
1164
- # necessary. FIXME This method should be responsible for most of the
1165
- # error handling.
1166
- def self.create(hash)
1167
- # Handle this new object being implicit
1168
- implicit = hash[:implicit] || false
1169
- if hash.include?(:implicit)
1170
- hash.delete(:implicit)
1171
- end
1172
-
1173
- name = nil
1174
- unless hash.is_a? TransObject
1175
- # if it's not a transobject, then make it one, just to make people's
1176
- # lives easier
1177
- hash = self.hash2trans(hash)
1178
- end
1179
- name = hash.name
1180
-
1181
- #Puppet.debug "Creating %s[%s]" % [self.name, name]
1182
-
1183
- # if the object already exists
1184
- if self.isomorphic? and retobj = self[name]
1185
- # if only one of our objects is implicit, then it's easy to see
1186
- # who wins -- the non-implicit one.
1187
- if retobj.implicit? and ! implicit
1188
- Puppet.notice "Removing implicit %s" % retobj.name
1189
- # Remove all of the objects, but do not remove their subscriptions.
1190
- retobj.remove(false)
1191
-
1192
- # now pass through and create the new object
1193
- elsif implicit
1194
- Puppet.notice "Ignoring implicit %s" % name
1195
-
1196
- return retobj
1197
- else
1198
- # If only one of the objects is being managed, then merge them
1199
- if retobj.managed?
1200
- raise Puppet::Error, "%s '%s' is already being managed" %
1201
- [self.name, name]
1202
- else
1203
- retobj.merge(hash)
1204
- return retobj
1205
- end
1206
- # We will probably want to support merging of some kind in
1207
- # the future, but for now, just throw an error.
1208
- #retobj.merge(hash)
1209
-
1210
- #return retobj
1211
- end
1212
- end
1213
-
1214
- # create it anew
1215
- # if there's a failure, destroy the object if it got that far
1216
- begin
1217
- obj = new(hash)
1218
- rescue => detail
1219
- if Puppet[:debug]
1220
- puts detail.backtrace
1221
- end
1222
- Puppet.err "Could not create %s: %s" % [name, detail.to_s]
1223
- if obj
1224
- obj.remove(true)
1225
- elsif obj = self[name]
1226
- obj.remove(true)
1227
- end
1228
- return nil
1229
- end
1230
-
1231
- if implicit
1232
- obj.implicit = true
1233
- end
1234
-
1235
- # Store the object by name
1236
- self[obj.name] = obj
1237
-
1238
- if name != obj[self.namevar] and obj.class.isomorphic?
1239
- self.alias(obj[self.namevar], obj)
1240
- end
1241
-
1242
- return obj
1243
- end
1244
-
1245
- # Convert a hash to a TransObject.
1246
- def self.hash2trans(hash)
1247
- name = nil
1248
- ["name", :name, self.namevar, self.namevar.to_s].each { |param|
1249
- if hash.include? param
1250
- name = hash[param]
1251
- hash.delete(param)
1252
- break
1253
- end
1254
- }
1255
- unless name
1256
- raise Puppet::Error,
1257
- "You must specify a name for objects of type %s" % self.to_s
1258
- end
1259
-
1260
- [:type, "type"].each do |type|
1261
- if hash.include? type
1262
- unless self.validattr? :type
1263
- hash.delete type
1264
- end
1265
- end
1266
- end
1267
- # okay, now make a transobject out of hash
1268
- begin
1269
- trans = TransObject.new(name, self.name.to_s)
1270
- hash.each { |param, value|
1271
- trans[param] = value
1272
- }
1273
- rescue => detail
1274
- raise Puppet::Error, "Could not create %s: %s" %
1275
- [name, detail]
1276
- end
1277
-
1278
- return trans
1279
- end
1280
-
1281
- def self.implicitcreate(hash)
1282
- unless hash.include?(:implicit)
1283
- hash[:implicit] = true
1284
- end
1285
- if obj = self.create(hash)
1286
- obj.implicit = true
1287
-
1288
- return obj
1289
- else
1290
- return nil
1291
- end
1292
- end
1293
-
1294
- # Is this type's name isomorphic with the object? That is, if the
1295
- # name conflicts, does it necessarily mean that the objects conflict?
1296
- # Defaults to true.
1297
- def self.isomorphic?
1298
- if defined? @isomorphic
1299
- return @isomorphic
1300
- else
1301
- return true
1302
- end
1303
- end
1304
-
1305
- # and then make 'new' private
1306
- class << self
1307
- private :new
1308
- end
1309
-
1310
- def initvars
1311
- @children = []
1312
- @evalcount = 0
1313
- @tags = []
1314
-
1315
- # callbacks are per object and event
1316
- @callbacks = Hash.new { |chash, key|
1317
- chash[key] = {}
1318
- }
1319
-
1320
- # states and parameters are treated equivalently from the outside:
1321
- # as name-value pairs (using [] and []=)
1322
- # internally, however, parameters are merely a hash, while states
1323
- # point to State objects
1324
- # further, the lists of valid states and parameters are defined
1325
- # at the class level
1326
- unless defined? @states
1327
- @states = Hash.new(false)
1328
- end
1329
- unless defined? @parameters
1330
- @parameters = Hash.new(false)
1331
- end
1332
- unless defined? @metaparams
1333
- @metaparams = Hash.new(false)
1334
- end
1335
-
1336
- # set defalts
1337
- @noop = false
1338
- # keeping stats for the total number of changes, and how many were
1339
- # completely sync'ed
1340
- # this isn't really sufficient either, because it adds lots of special
1341
- # cases such as failed changes
1342
- # it also doesn't distinguish between changes from the current transaction
1343
- # vs. changes over the process lifetime
1344
- @totalchanges = 0
1345
- @syncedchanges = 0
1346
- @failedchanges = 0
1347
-
1348
- @inited = true
1349
- end
1350
-
1351
- # initialize the type instance
1352
- def initialize(hash)
1353
- unless defined? @inited
1354
- self.initvars
1355
- end
1356
- namevar = self.class.namevar
1357
-
1358
- # If we got passed a transportable object, we just pull a bunch of info
1359
- # directly from it. This is the main object instantiation mechanism.
1360
- if hash.is_a?(Puppet::TransObject)
1361
- #self[:name] = hash[:name]
1362
- [:file, :line, :tags].each { |getter|
1363
- if hash.respond_to?(getter)
1364
- setter = getter.to_s + "="
1365
- if val = hash.send(getter)
1366
- self.send(setter, val)
1367
- end
1368
- end
1369
- }
1370
-
1371
- @name = hash.name
1372
-
1373
- # If they did not provide a namevar,
1374
- if hash.include? namevar
1375
- self[:alias] = hash.name
1376
- else
1377
- hash[namevar] = hash.name
1378
- end
1379
- hash = hash.to_hash
1380
- end
1381
-
1382
- # Before anything else, set our parent if it was included
1383
- if hash.include?(:parent)
1384
- @parent = hash[:parent]
1385
- hash.delete(:parent)
1386
- end
1387
-
1388
- # Convert all args to symbols
1389
- hash = self.argclean(hash)
1390
-
1391
- # Let's do the name first, because some things need to happen once
1392
- # we have the name but before anything else
1393
-
1394
- attrs = self.class.allattrs
1395
-
1396
- if hash.include?(namevar)
1397
- #self.send(namevar.to_s + "=", hash[namevar])
1398
- self[namevar] = hash[namevar]
1399
- hash.delete(namevar)
1400
- if attrs.include?(namevar)
1401
- attrs.delete(namevar)
1402
- else
1403
- self.devfail "My namevar isn\'t a valid attribute...?"
1404
- end
1405
- else
1406
- self.devfail "I was not passed a namevar"
1407
- end
1408
-
1409
- # The information to cache to disk. We have to do this after
1410
- # the name is set because it uses the name and/or path, but before
1411
- # everything else is set because the states need to be able to
1412
- # retrieve their stored info.
1413
- #@cache = Puppet::Storage.cache(self)
1414
-
1415
- # This is all of our attributes except the namevar.
1416
- attrs.each { |name|
1417
- if hash.include?(name)
1418
- begin
1419
- self[name] = hash[name]
1420
- rescue ArgumentError, Puppet::Error, TypeError
1421
- raise
1422
- rescue => detail
1423
- self.devfail(
1424
- "Could not set %s on %s: %s" %
1425
- [name, self.class.name, detail]
1426
- )
1427
- end
1428
- hash.delete name
1429
- end
1430
- }
1431
-
1432
- # While this could theoretically be set after all of the objects are
1433
- # created, it seems to make more sense to set them immediately.
1434
- self.setdefaults
1435
-
1436
- if hash.length > 0
1437
- self.debug hash.inspect
1438
- self.fail("Class %s does not accept argument(s) %s" %
1439
- [self.class.name, hash.keys.join(" ")])
1440
- end
1441
-
1442
- if self.respond_to?(:validate)
1443
- self.validate
1444
- end
1445
- end
1446
-
1447
- # Figure out of there are any objects we can automatically add as
1448
- # dependencies.
1449
- def autorequire
1450
- self.class.eachautorequire { |type, block|
1451
- # Ignore any types we can't find, although that would be a bit odd.
1452
- next unless typeobj = Puppet.type(type)
1453
-
1454
- # Retrieve the list of names from the block.
1455
- next unless list = self.instance_eval(&block)
1456
- unless list.is_a?(Array)
1457
- list = [list]
1458
- end
1459
-
1460
- # Collect the current prereqs
1461
- list.each { |dep|
1462
- obj = nil
1463
- # Support them passing objects directly, to save some effort.
1464
- if dep.is_a? Puppet::Type
1465
- type = dep.class.name
1466
- obj = dep
1467
-
1468
- # Now change our dependency to just the string, instead of
1469
- # the object itself.
1470
- dep = dep.name
1471
- else
1472
- # Skip autorequires that we aren't managing
1473
- unless obj = typeobj[dep]
1474
- next
1475
- end
1476
- end
1477
-
1478
- # Skip autorequires that we already require
1479
- next if self.requires?(obj)
1480
-
1481
- debug "Autorequiring %s %s" % [obj.class.name, obj.name]
1482
- self[:require] = [type, dep]
1483
- }
1484
-
1485
- #self.info reqs.inspect
1486
- #self[:require] = reqs
1487
- }
1488
- end
1489
-
1490
- # Set up all of our autorequires.
1491
- def finish
1492
- self.autorequire
1493
-
1494
- # Scheduling has to be done when the whole config is instantiated, so
1495
- # that file order doesn't matter in finding them.
1496
- self.schedule
1497
- end
1498
-
1499
- # Return a cached value
1500
- def cached(name)
1501
- Puppet::Storage.cache(self)[name]
1502
- #@cache[name] ||= nil
1503
- end
1504
-
1505
- # Cache a value
1506
- def cache(name, value)
1507
- Puppet::Storage.cache(self)[name] = value
1508
- #@cache[name] = value
1509
- end
1510
-
1511
- # Look up the schedule and set it appropriately. This is done after
1512
- # the instantiation phase, so that the schedule can be anywhere in the
1513
- # file.
1514
- def schedule
1515
-
1516
- # If we've already set the schedule, then just move on
1517
- return if self[:schedule].is_a?(Puppet.type(:schedule))
1518
-
1519
- return unless self[:schedule]
1520
-
1521
- # Schedules don't need to be scheduled
1522
- #return if self.is_a?(Puppet.type(:schedule))
1523
-
1524
- # Nor do components
1525
- #return if self.is_a?(Puppet.type(:component))
1526
-
1527
- if sched = Puppet.type(:schedule)[self[:schedule]]
1528
- self[:schedule] = sched
1529
- else
1530
- self.fail "Could not find schedule %s" % self[:schedule]
1531
- end
1532
- end
1533
-
1534
- # Check whether we are scheduled to run right now or not.
1535
- def scheduled?
1536
- return true if Puppet[:ignoreschedules]
1537
- return true unless schedule = self[:schedule]
1538
-
1539
- # We use 'checked' here instead of 'synced' because otherwise we'll
1540
- # end up checking most elements most times, because they will generally
1541
- # have been synced a long time ago (e.g., a file only gets updated
1542
- # once a month on the server and its schedule is daily; the last sync time
1543
- # will have been a month ago, so we'd end up checking every run).
1544
- return schedule.match?(self.cached(:checked).to_i)
1545
- end
1546
-
1547
- # Add a new tag.
1548
- def tag(tag)
1549
- tag = tag.intern if tag.is_a? String
1550
- unless @tags.include? tag
1551
- @tags << tag
1552
- end
1553
- end
1554
-
1555
- # Define the initial list of tags.
1556
- def tags=(list)
1557
- list = [list] unless list.is_a? Array
1558
-
1559
- @tags = list.collect do |t|
1560
- case t
1561
- when String: t.intern
1562
- when Symbol: t
1563
- else
1564
- self.warning "Ignoring tag %s of type %s" % [tag.inspect, tag.class]
1565
- end
1566
- end
1567
- end
1568
-
1569
- # Figure out of any of the specified tags apply to this object. This is an
1570
- # OR operation.
1571
- def tagged?(tags)
1572
- tags = [tags] unless tags.is_a? Array
1573
-
1574
- tags = tags.collect { |t| t.intern }
1575
-
1576
- return tags.find { |tag| @tags.include? tag }
1577
- end
1578
-
1579
- # Is the specified parameter set?
1580
- def attrset?(type, attr)
1581
- case type
1582
- when :state: return @states.include?(attr)
1583
- when :param: return @parameters.include?(attr)
1584
- when :meta: return @metaparams.include?(attr)
1585
- else
1586
- self.devfail "Invalid set type %s" % [type]
1587
- end
1588
- end
1589
-
1590
- # def set(name, value)
1591
- # send(name.to_s + "=", value)
1592
- # end
1593
- #
1594
- # def get(name)
1595
- # send(name)
1596
- # end
1597
-
1598
- # For any parameters or states that have defaults and have not yet been
1599
- # set, set them now.
1600
- def setdefaults(*ary)
1601
- self.class.eachattr(*ary) { |klass, type|
1602
- # not many attributes will have defaults defined, so we short-circuit
1603
- # those away
1604
- next unless klass.method_defined?(:default)
1605
- next if self.attrset?(type, klass.name)
1606
-
1607
- obj = self.newattr(type, klass)
1608
- value = obj.default
1609
- unless value.nil?
1610
- #self.debug "defaulting %s to %s" % [obj.name, obj.default]
1611
- obj.value = value
1612
- else
1613
- #self.debug "No default for %s" % obj.name
1614
- self.delete(obj.name)
1615
- end
1616
- }
1617
-
1618
- end
1619
-
1620
- # Merge new information with an existing object, checking for conflicts
1621
- # and such. This allows for two specifications of the same object and
1622
- # the same values, but it's pretty limited right now. The result of merging
1623
- # states is very different from the result of merging parameters or metaparams.
1624
- # This is currently unused.
1625
- def merge(hash)
1626
- hash.each { |param, value|
1627
- if param.is_a?(String)
1628
- param = param.intern
1629
- end
1630
-
1631
- # Of course names are the same, duh.
1632
- next if param == :name or param == self.class.namevar
1633
-
1634
- unless value.is_a?(Array)
1635
- value = [value]
1636
- end
1637
-
1638
- if @states.include?(param) and oldvals = @states[param].shouldorig
1639
- unless oldvals.is_a?(Array)
1640
- oldvals = [oldvals]
1641
- end
1642
- # If the values are exactly the same, order and everything,
1643
- # then it's okay.
1644
- if oldvals == value
1645
- return true
1646
- end
1647
- # take the intersection
1648
- newvals = oldvals & value
1649
- if newvals.empty?
1650
- self.fail "No common values for %s on %s(%s)" %
1651
- [param, self.class.name, self.name]
1652
- elsif newvals.length > 1
1653
- self.fail "Too many values for %s on %s(%s)" %
1654
- [param, self.class.name, self.name]
1655
- else
1656
- self.debug "Reduced old values %s and new values %s to %s" %
1657
- [oldvals.inspect, value.inspect, newvals.inspect]
1658
- @states[param].should = newvals
1659
- #self.should = newvals
1660
- return true
1661
- end
1662
- else
1663
- self[param] = value
1664
- end
1665
- }
1666
-
1667
- # Set the defaults again, just in case.
1668
- self.setdefaults
1669
- end
1670
-
1671
- # derive the instance name based on class.namevar
1672
- def name
1673
- unless defined? @name and @name
1674
- namevar = self.class.namevar
1675
- if self.class.validparameter?(namevar)
1676
- @name = self[:name]
1677
- elsif self.class.validstate?(namevar)
1678
- @name = self.should(namevar)
1679
- else
1680
- self.devfail "Could not find namevar %s for %s" %
1681
- [namevar, self.class.name]
1682
- end
1683
- end
1684
-
1685
- unless @name
1686
- self.devfail "Could not find namevar '%s' for %s" %
1687
- [self.class.namevar, self.class.name]
1688
- end
1689
-
1690
- return @name
1691
- end
1692
-
1693
- # fix any namevar => param translations
1694
- def argclean(hash)
1695
- # We have to set the name of our object before anything else,
1696
- # because it might be used in creating the other states. We dup and
1697
- # then convert to a hash here because TransObjects behave strangely
1698
- # here.
1699
- hash = hash.dup.to_hash
1700
-
1701
- if hash.include?(:parent)
1702
- hash.delete(:parent)
1703
- end
1704
- namevar = self.class.namevar
1705
-
1706
- hash.each { |var,value|
1707
- unless var.is_a? Symbol
1708
- hash[var.intern] = value
1709
- hash.delete(var)
1710
- end
1711
- }
1712
-
1713
- # if they're not using :name for the namevar but we got :name (probably
1714
- # from the parser)
1715
- # if namevar != :name and hash.include?(:name) and ! hash[:name].nil?
1716
- # #self[namevar] = hash[:name]
1717
- # hash[namevar] = hash[:name]
1718
- # hash.delete(:name)
1719
- # # else if we got the namevar
1720
- # elsif hash.has_key?(namevar) and ! hash[namevar].nil?
1721
- # #self[namevar] = hash[namevar]
1722
- # #hash.delete(namevar)
1723
- # # else something's screwy
1724
- # else
1725
- # # they didn't specify anything related to names
1726
- # end
1727
-
1728
- return hash
1729
- end
1730
-
1731
- # retrieve the current value of all contained states
1732
- def retrieve
1733
- # it's important to use the method here, as it follows the order
1734
- # in which they're defined in the object
1735
- states().each { |state|
1736
- state.retrieve
1737
- }
1738
- end
1739
-
1740
- # convert to a string
1741
- def to_s
1742
- self.name
1743
- end
1744
-
1745
- # Convert to a transportable object
1746
- def to_trans
1747
- # Collect all of the "is" values
1748
- retrieve()
1749
-
1750
- trans = TransObject.new(self.name, self.class.name)
1751
-
1752
- states().each do |state|
1753
- trans[state.name] = state.is
1754
- end
1755
-
1756
- @parameters.each do |name, param|
1757
- # Avoid adding each instance name as both the name and the namevar
1758
- next if param.class.isnamevar? and param.value == self.name
1759
- trans[name] = param.value
1760
- end
1761
-
1762
- @metaparams.each do |name, param|
1763
- trans[name] = param.value
1764
- end
1765
-
1766
- trans.tags = self.tags
1767
-
1768
- # FIXME I'm currently ignoring 'parent' and 'path'
1769
-
1770
- return trans
1771
- end
1772
-
1773
- # instance methods dealing with actually doing work
1774
-
1775
- public
1776
-
1777
- # this is a retarded hack method to get around the difference between
1778
- # component children and file children
1779
- def self.depthfirst?
1780
- if defined? @depthfirst
1781
- return @depthfirst
1782
- else
1783
- return false
1784
- end
1785
- end
1786
-
1787
- # Retrieve the changes associated with all of the states.
1788
- def statechanges
1789
- # If we are changing the existence of the object, then none of
1790
- # the other states matter.
1791
- changes = []
1792
- if @states.include?(:ensure) and ! @states[:ensure].insync?
1793
- #self.info "ensuring %s from %s" %
1794
- # [@states[:ensure].should, @states[:ensure].is]
1795
- changes = [Puppet::StateChange.new(@states[:ensure])]
1796
- # Else, if the 'ensure' state is correctly absent, then do
1797
- # nothing
1798
- elsif @states.include?(:ensure) and @states[:ensure].is == :absent
1799
- #self.info "Object is correctly absent"
1800
- return []
1801
- else
1802
- #if @states.include?(:ensure)
1803
- # self.info "ensure: Is: %s, Should: %s" %
1804
- # [@states[:ensure].is, @states[:ensure].should]
1805
- #else
1806
- # self.info "no ensure state"
1807
- #end
1808
- changes = states().find_all { |state|
1809
- ! state.insync?
1810
- }.collect { |state|
1811
- Puppet::StateChange.new(state)
1812
- }
1813
- end
1814
-
1815
- if Puppet[:debug] and changes.length > 0
1816
- self.debug("Changing " + changes.collect { |ch|
1817
- ch.state.name
1818
- }.join(",")
1819
- )
1820
- end
1821
-
1822
- changes
1823
- end
1824
-
1825
- # this method is responsible for collecting state changes
1826
- # we always descend into the children before we evaluate our current
1827
- # states
1828
- # this returns any changes resulting from testing, thus 'collect'
1829
- # rather than 'each'
1830
- def evaluate
1831
- now = Time.now
1832
-
1833
- #Puppet.err "Evaluating %s" % self.path.join(":")
1834
- unless defined? @evalcount
1835
- self.err "No evalcount defined on '%s' of type '%s'" %
1836
- [self.name,self.class]
1837
- @evalcount = 0
1838
- end
1839
- @evalcount += 1
1840
-
1841
- changes = []
1842
-
1843
- # this only operates on states, not states + children
1844
- # it's important that we call retrieve() on the type instance,
1845
- # not directly on the state, because it allows the type to override
1846
- # the method, like pfile does
1847
- self.retrieve
1848
-
1849
- # states() is a private method, returning an ordered list
1850
- unless self.class.depthfirst?
1851
- changes += statechanges()
1852
- end
1853
-
1854
- changes << @children.collect { |child|
1855
- ch = child.evaluate
1856
- child.cache(:checked, now)
1857
- ch
1858
- }
1859
-
1860
- if self.class.depthfirst?
1861
- changes += statechanges()
1862
- end
1863
-
1864
- changes.flatten!
1865
-
1866
- # now record how many changes we've resulted in
1867
- if changes.length > 0
1868
- self.debug "%s change(s)" %
1869
- [changes.length]
1870
- end
1871
- self.cache(:checked, now)
1872
- return changes.flatten
1873
- end
1874
-
1875
- # if all contained objects are in sync, then we're in sync
1876
- # FIXME I don't think this is used on the type instances any more,
1877
- # it's really only used for testing
1878
- def insync?
1879
- insync = true
1880
-
1881
- if state = @states[:ensure]
1882
- if state.insync? and state.should == :absent
1883
- return true
1884
- end
1885
- end
1886
-
1887
- states.each { |state|
1888
- unless state.insync?
1889
- state.debug("Not in sync: %s vs %s" %
1890
- [state.is.inspect, state.should.inspect])
1891
- insync = false
1892
- #else
1893
- # state.debug("In sync")
1894
- end
1895
- }
1896
-
1897
- #self.debug("%s sync status is %s" % [self,insync])
1898
- return insync
1899
- end
1900
-
1901
- # Meta-parameter methods: These methods deal with the results
1902
- # of specifying metaparameters
1903
-
1904
- def self.metaparams
1905
- @@metaparams.collect { |param| param.name }
1906
- end
1907
-
1908
- # Is the parameter in question a meta-parameter?
1909
- def self.metaparam?(param)
1910
- @@metaparamhash.include?(param)
1911
- end
1912
-
1913
- # Subscription and relationship methods
1914
-
1915
- #def addcallback(object, event, method)
1916
- # @callbacks[object][event] = method
1917
- #end
1918
-
1919
- # Build the dependencies associated with an individual object.
1920
- def builddepends
1921
- # Handle the requires
1922
- if self[:require]
1923
- self.handledepends(self[:require], :NONE, nil, true)
1924
- end
1925
-
1926
- # And the subscriptions
1927
- if self[:subscribe]
1928
- self.handledepends(self[:subscribe], :ALL_EVENTS, :refresh, true)
1929
- end
1930
-
1931
- if self[:notify]
1932
- self.handledepends(self[:notify], :ALL_EVENTS, :refresh, false)
1933
- end
1934
-
1935
- if self[:before]
1936
- self.handledepends(self[:before], :NONE, nil, false)
1937
- end
1938
- end
1939
-
1940
- # return all objects that we depend on
1941
- def eachdependency
1942
- Puppet::Event::Subscription.dependencies(self).each { |dep|
1943
- yield dep.source
1944
- }
1945
- end
1946
-
1947
- # return all objects subscribed to the current object
1948
- def eachsubscriber
1949
- Puppet::Event::Subscription.subscribers(self).each { |sub|
1950
- yield sub.target
1951
- }
1952
- end
1953
-
1954
- def handledepends(requires, event, method, up)
1955
- # Requires are specified in the form of [type, name], so they're always
1956
- # an array. But we want them to be an array of arrays.
1957
- unless requires[0].is_a?(Array)
1958
- requires = [requires]
1959
- end
1960
- requires.each { |rname|
1961
- # we just have a name and a type, and we need to convert it
1962
- # to an object...
1963
- type = nil
1964
- object = nil
1965
- tname = rname[0]
1966
- unless type = Puppet::Type.type(tname)
1967
- self.fail "Could not find type %s" % tname.inspect
1968
- end
1969
- name = rname[1]
1970
- unless object = type[name]
1971
- self.fail "Could not retrieve object '%s' of type '%s'" %
1972
- [name,type]
1973
- end
1974
- self.debug("subscribes to %s" % [object])
1975
-
1976
- # Are we requiring them, or vice versa?
1977
- source = target = nil
1978
- if up
1979
- source = object
1980
- target = self
1981
- else
1982
- source = self
1983
- target = object
1984
- end
1985
-
1986
- # ok, both sides of the connection store some information
1987
- # we store the method to call when a given subscription is
1988
- # triggered, but the source object decides whether
1989
- subargs = {
1990
- :event => event,
1991
- :source => source,
1992
- :target => target
1993
- }
1994
-
1995
- if method and target.respond_to?(method)
1996
- subargs[:callback] = method
1997
- end
1998
- Puppet::Event::Subscription.new(subargs)
1999
- }
2000
- end
2001
-
2002
- def requires?(object)
2003
- req = false
2004
- self.eachdependency { |dep|
2005
- if dep == object
2006
- req = true
2007
- break
2008
- end
2009
- }
2010
-
2011
- return req
2012
- end
2013
-
2014
- def subscribe(hash)
2015
- hash[:source] = self
2016
- Puppet::Event::Subscription.new(hash)
2017
-
2018
- # add to the correct area
2019
- #@subscriptions.push sub
2020
- end
2021
-
2022
- def subscribesto?(object)
2023
- sub = false
2024
- self.eachsubscriber { |o|
2025
- if o == object
2026
- sub = true
2027
- break
2028
- end
2029
- }
2030
-
2031
- return sub
2032
- end
2033
-
2034
- # Unsubscribe from a given object, possibly with a specific event.
2035
- def unsubscribe(object, event = nil)
2036
- Puppet::Event::Subscription.dependencies(self).find_all { |sub|
2037
- if event
2038
- sub.match?(event)
2039
- else
2040
- sub.source == object
2041
- end
2042
- }.each { |sub|
2043
- sub.delete
2044
- }
2045
- end
2046
-
2047
- # we've received an event
2048
- # we only support local events right now, so we can pass actual
2049
- # objects around, including the transaction object
2050
- # the assumption here is that container objects will pass received
2051
- # methods on to contained objects
2052
- # i.e., we don't trigger our children, our refresh() method calls
2053
- # refresh() on our children
2054
- def trigger(event, source)
2055
- trans = event.transaction
2056
- if @callbacks.include?(source)
2057
- [:ALL_EVENTS, event.event].each { |eventname|
2058
- if method = @callbacks[source][eventname]
2059
- if trans.triggered?(self, method) > 0
2060
- next
2061
- end
2062
- if self.respond_to?(method)
2063
- self.send(method)
2064
- end
2065
-
2066
- trans.triggered(self, method)
2067
- end
2068
- }
2069
- end
2070
- end
2071
-
2072
- # Documentation methods
2073
- def self.paramdoc(param)
2074
- @paramhash[param].doc
2075
- end
2076
- def self.metaparamdoc(metaparam)
2077
- @@metaparamhash[metaparam].doc
2078
- end
2079
-
2080
- # Add all of the meta parameters.
2081
- #newmetaparam(:onerror) do
2082
- # desc "How to handle errors -- roll back innermost
2083
- # transaction, roll back entire transaction, ignore, etc. Currently
2084
- # non-functional."
2085
- #end
2086
-
2087
- newmetaparam(:noop) do
2088
- desc "Boolean flag indicating whether work should actually
2089
- be done. *true*/**false**"
2090
- munge do |noop|
2091
- if noop == "true" or noop == true
2092
- return true
2093
- elsif noop == "false" or noop == false
2094
- return false
2095
- else
2096
- self.fail("Invalid noop value '%s'" % noop)
2097
- end
2098
- end
2099
- end
2100
-
2101
- newmetaparam(:schedule) do
2102
- desc "On what schedule the object should be managed. You must create a
2103
- schedule object, and then reference the name of that object to use
2104
- that for your schedule:
2105
-
2106
- schedule { daily:
2107
- period => daily,
2108
- range => \"2-4\"
2109
- }
2110
-
2111
- exec { \"/usr/bin/apt-get update\":
2112
- schedule => daily
2113
- }
2114
-
2115
- The creation of the schedule object does not need to appear in the
2116
- configuration before objects that use it."
2117
-
2118
- munge do |name|
2119
- if schedule = Puppet.type(:schedule)[name]
2120
- return schedule
2121
- else
2122
- return name
2123
- end
2124
- end
2125
- end
2126
-
2127
- newmetaparam(:check) do
2128
- desc "States which should have their values retrieved
2129
- but which should not actually be modified. This is currently used
2130
- internally, but will eventually be used for querying, so that you
2131
- could specify that you wanted to check the install state of all
2132
- packages, and then query the Puppet client daemon to get reports
2133
- on all packages."
2134
-
2135
- munge do |args|
2136
- # If they've specified all, collect all known states
2137
- if args == :all
2138
- args = @parent.class.states.collect do |state|
2139
- state.name
2140
- end
2141
- end
2142
-
2143
- unless args.is_a?(Array)
2144
- args = [args]
2145
- end
2146
-
2147
- unless defined? @parent
2148
- self.devfail "No parent for %s, %s?" %
2149
- [self.class, self.name]
2150
- end
2151
-
2152
- args.each { |state|
2153
- unless state.is_a?(Symbol)
2154
- state = state.intern
2155
- end
2156
- next if @parent.statedefined?(state)
2157
-
2158
- stateklass = @parent.class.validstate?(state)
2159
-
2160
- unless stateklass
2161
- raise Puppet::Error, "%s is not a valid attribute for %s" %
2162
- [state, self.class.name]
2163
- end
2164
- next unless stateklass.checkable?
2165
-
2166
- @parent.newstate(state)
2167
- }
2168
- end
2169
- end
2170
- # For each object we require, subscribe to all events that it generates. We
2171
- # might reduce the level of subscription eventually, but for now...
2172
- newmetaparam(:require) do
2173
- desc "One or more objects that this object depends on.
2174
- This is used purely for guaranteeing that changes to required objects
2175
- happen before the dependent object. For instance:
2176
-
2177
- # Create the destination directory before you copy things down
2178
- file { \"/usr/local/scripts\":
2179
- ensure => directory
2180
- }
2181
-
2182
- file { \"/usr/local/scripts/myscript\":
2183
- source => \"puppet://server/module/myscript\",
2184
- mode => 755,
2185
- require => file[\"/usr/local/scripts\"]
2186
- }
2187
-
2188
- Note that Puppet will autorequire everything that it can, and
2189
- there are hooks in place so that it's easy for elements to add new
2190
- ways to autorequire objects, so if you think Puppet could be
2191
- smarter here, let us know.
2192
-
2193
- In fact, the above code was redundant -- Puppet will autorequire
2194
- any parent directories that are being managed; it will
2195
- automatically realize that the parent directory should be created
2196
- before the script is pulled down.
2197
-
2198
- Currently, exec elements will autorequire their CWD (if it is
2199
- specified) plus any fully qualified paths that appear in the
2200
- command. For instance, if you had an ``exec`` command that ran
2201
- the ``myscript`` mentioned above, the above code that pulls the
2202
- file down would be automatically listed as a requirement to the
2203
- ``exec`` code, so that you would always be running againts the
2204
- most recent version.
2205
- "
2206
-
2207
- # Take whatever dependencies currently exist and add these.
2208
- # Note that this probably doesn't behave correctly with unsubscribe.
2209
- munge do |requires|
2210
- # We need to be two arrays deep...
2211
- unless requires.is_a?(Array)
2212
- requires = [requires]
2213
- end
2214
- unless requires[0].is_a?(Array)
2215
- requires = [requires]
2216
- end
2217
- if values = @parent[:require]
2218
- requires = values + requires
2219
- end
2220
- requires
2221
- end
2222
- end
2223
-
2224
- # For each object we require, subscribe to all events that it generates.
2225
- # We might reduce the level of subscription eventually, but for now...
2226
- newmetaparam(:subscribe) do
2227
- desc "One or more objects that this object depends on. Changes in the
2228
- subscribed to objects result in the dependent objects being
2229
- refreshed (e.g., a service will get restarted). For instance:
2230
-
2231
- class nagios {
2232
- file { \"/etc/nagios/nagios.conf\":
2233
- source => \"puppet://server/module/nagios.conf\",
2234
- alias => nagconf # just to make things easier for me
2235
- }
2236
- service { nagios:
2237
- running => true,
2238
- subscribe => file[nagconf]
2239
- }
2240
- }
2241
- "
2242
-
2243
- munge do |requires|
2244
- if values = @parent[:subscribe]
2245
- requires = values + requires
2246
- end
2247
- requires
2248
- # @parent.handledepends(requires, :ALL_EVENTS, :refresh)
2249
- end
2250
- end
2251
-
2252
- newmetaparam(:loglevel) do
2253
- desc "Sets the level that information will be logged.
2254
- The log levels have the biggest impact when logs are sent to
2255
- syslog (which is currently the default)."
2256
- defaultto :notice
2257
-
2258
- newvalues(*Puppet::Log.levels)
2259
- newvalues(:verbose)
2260
-
2261
- munge do |loglevel|
2262
- val = super(loglevel)
2263
- if val == :verbose
2264
- val = :info
2265
- end
2266
- val
2267
- end
2268
- end
2269
-
2270
- newmetaparam(:alias) do
2271
- desc "Creates an alias for the object. Puppet uses this internally when you
2272
- provide a symbolic name:
2273
-
2274
- file { sshdconfig:
2275
- path => $operatingsystem ? {
2276
- solaris => \"/usr/local/etc/ssh/sshd_config\",
2277
- default => \"/etc/ssh/sshd_config\"
2278
- },
2279
- source => \"...\"
2280
- }
2281
-
2282
- service { sshd:
2283
- subscribe => file[sshdconfig]
2284
- }
2285
-
2286
- When you use this feature, the parser sets ``sshdconfig`` as the name,
2287
- and the library sets that as an alias for the file so the dependency
2288
- lookup for ``sshd`` works. You can use this parameter yourself,
2289
- but note that only the library can use these aliases; for instance,
2290
- the following code will not work:
2291
-
2292
- file { \"/etc/ssh/sshd_config\":
2293
- owner => root,
2294
- group => root,
2295
- alias => sshdconfig
2296
- }
2297
-
2298
- file { sshdconfig:
2299
- mode => 644
2300
- }
2301
-
2302
- There's no way here for the Puppet parser to know that these two stanzas
2303
- should be affecting the same file.
2304
-
2305
- See the [language tutorial][] for more information.
2306
-
2307
- [language tutorial]: languagetutorial.html
2308
-
2309
- "
2310
-
2311
- munge do |aliases|
2312
- unless aliases.is_a?(Array)
2313
- aliases = [aliases]
2314
- end
2315
- @parent.info "Adding aliases %s" % aliases.join(", ")
2316
- aliases.each do |other|
2317
- if obj = @parent.class[other]
2318
- unless obj == @parent
2319
- self.fail(
2320
- "%s can not create alias %s: object already exists" %
2321
- [@parent.name, other]
2322
- )
2323
- end
2324
- next
2325
- end
2326
- @parent.class.alias(other, @parent)
2327
- end
2328
- end
2329
- end
2330
-
2331
- newmetaparam(:tag) do
2332
- desc "Add the specified tags to the associated element. While all elements
2333
- are automatically tagged with as much information as possible
2334
- (e.g., each class and component containing the element), it can
2335
- be useful to add your own tags to a given element.
2336
-
2337
- Tags are currently useful for things like applying a subset of a
2338
- host's configuration:
2339
-
2340
- puppetd --test --tag mytag
2341
-
2342
- This way, when you're testing a configuration you can run just the
2343
- portion you're testing."
2344
-
2345
- munge do |tags|
2346
- tags = [tags] unless tags.is_a? Array
2347
-
2348
- tags.each do |tag|
2349
- @parent.tag(tag)
2350
- end
2351
- end
2352
- end
2353
-
2354
- newmetaparam(:notify) do
2355
- desc %{This parameter is the opposite of **subscribe** -- it sends events
2356
- to the specified object:
2357
-
2358
- file { "/etc/sshd_config":
2359
- source => "....",
2360
- notify => service[sshd]
2361
- }
2362
-
2363
- service { sshd:
2364
- ensure => running
2365
- }
2366
-
2367
- This will restart the sshd service if the sshd config file changes.}
2368
-
2369
-
2370
- # Take whatever dependencies currently exist and add these.
2371
- munge do |notifies|
2372
- # We need to be two arrays deep...
2373
- unless notifies.is_a?(Array)
2374
- notifies = [notifies]
2375
- end
2376
- unless notifies[0].is_a?(Array)
2377
- notifies = [notifies]
2378
- end
2379
- if values = @parent[:notify]
2380
- notifies = values + notifies
2381
- end
2382
- notifies
2383
- end
2384
-
2385
- end
2386
-
2387
- newmetaparam(:before) do
2388
- desc %{This parameter is the opposite of **require** -- it guarantees
2389
- that the specified object is applied later than the specifying
2390
- object:
2391
-
2392
- file { "/var/nagios/configuration":
2393
- source => "...",
2394
- recurse => true,
2395
- before => exec["nagios-rebuid"]
2396
- }
2397
-
2398
- exec { "nagios-rebuild":
2399
- command => "/usr/bin/make",
2400
- cwd => "/var/nagios/configuration"
2401
- }
2402
-
2403
- This will make sure all of the files are up to date before the
2404
- make command is run.}
2405
-
2406
- # Take whatever dependencies currently exist and add these.
2407
- munge do |notifies|
2408
- # We need to be two arrays deep...
2409
- unless notifies.is_a?(Array)
2410
- notifies = [notifies]
2411
- end
2412
- unless notifies[0].is_a?(Array)
2413
- notifies = [notifies]
2414
- end
2415
- if values = @parent[:notify]
2416
- notifies = values + notifies
2417
- end
2418
- notifies
2419
- end
2420
-
2421
- end
2422
408
  end # Puppet::Type
2423
409
  end
2424
410
 
2425
- require 'puppet/statechange'
411
+ require 'puppet/propertychange'
412
+ require 'puppet/provider'
2426
413
  require 'puppet/type/component'
2427
- require 'puppet/type/cron'
2428
- require 'puppet/type/exec'
2429
- require 'puppet/type/group'
2430
- require 'puppet/type/package'
2431
414
  require 'puppet/type/pfile'
2432
415
  require 'puppet/type/pfilebucket'
2433
- require 'puppet/type/schedule'
2434
- require 'puppet/type/service'
2435
- require 'puppet/type/symlink'
2436
- require 'puppet/type/user'
2437
416
  require 'puppet/type/tidy'
2438
- require 'puppet/type/parsedtype'
2439
417
 
2440
- # $Id: type.rb 1373 2006-07-06 04:39:59Z luke $
418
+
419
+
420
+ # $Id: type.rb 2329 2007-03-19 21:37:52Z luke $