puppet 0.24.5 → 0.24.6

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 (354) hide show
  1. data/CHANGELOG +206 -0
  2. data/Rakefile +53 -0
  3. data/bin/filebucket +0 -0
  4. data/bin/puppet +32 -11
  5. data/bin/puppetca +1 -0
  6. data/bin/puppetd +0 -0
  7. data/bin/puppetdoc +0 -0
  8. data/bin/puppetmasterd +0 -0
  9. data/bin/puppetrun +16 -8
  10. data/bin/ralsh +0 -0
  11. data/conf/debian/rules +0 -0
  12. data/conf/gentoo/init.d/puppetmaster +0 -0
  13. data/conf/osx/PackageInfo.plist +36 -0
  14. data/conf/osx/createpackage.sh +167 -0
  15. data/conf/osx/preflight +12 -0
  16. data/conf/redhat/client.init +1 -1
  17. data/conf/redhat/puppet.spec +34 -6
  18. data/conf/redhat/server.init +42 -7
  19. data/conf/redhat/server.sysconfig +22 -0
  20. data/conf/solaris/smf/svc-puppetd +0 -0
  21. data/conf/solaris/smf/svc-puppetmasterd +0 -0
  22. data/examples/etc/init.d/sleeper +0 -0
  23. data/examples/mac_dscl.pp +0 -0
  24. data/examples/mac_dscl_revert.pp +0 -0
  25. data/examples/mac_netinfo.pp +0 -0
  26. data/examples/mac_pkgdmg.pp +0 -0
  27. data/ext/bin/sleeper +0 -0
  28. data/ext/module_puppet +0 -0
  29. data/ext/nagios/check_puppet.rb +0 -0
  30. data/ext/passenger/README +63 -0
  31. data/ext/passenger/apache2.conf +29 -0
  32. data/ext/passenger/config.ru +40 -0
  33. data/ext/puppet-test +0 -0
  34. data/ext/puppetlast +6 -31
  35. data/ext/puppetstoredconfigclean.rb +87 -0
  36. data/install.rb +75 -20
  37. data/lib/puppet.rb +1 -1
  38. data/lib/puppet/daemon.rb +0 -0
  39. data/lib/puppet/defaults.rb +3 -7
  40. data/lib/puppet/external/base64.rb +0 -0
  41. data/lib/puppet/external/nagios.rb +0 -0
  42. data/lib/puppet/external/nagios/base.rb +0 -0
  43. data/lib/puppet/file_serving/fileset.rb +2 -2
  44. data/lib/puppet/file_serving/metadata.rb +3 -3
  45. data/lib/puppet/indirector/facts/facter.rb +3 -2
  46. data/lib/puppet/indirector/yaml.rb +10 -1
  47. data/lib/puppet/module.rb +36 -12
  48. data/lib/puppet/network/authstore.rb +0 -0
  49. data/lib/puppet/network/client/master.rb +12 -11
  50. data/lib/puppet/network/handler/filebucket.rb +0 -0
  51. data/lib/puppet/network/handler/fileserver.rb +38 -46
  52. data/lib/puppet/network/handler/master.rb +1 -1
  53. data/lib/puppet/network/handler/report.rb +0 -0
  54. data/lib/puppet/network/handler/resource.rb +0 -0
  55. data/lib/puppet/network/handler/runner.rb +0 -0
  56. data/lib/puppet/network/http_server/rack.rb +148 -0
  57. data/lib/puppet/network/rights.rb +0 -0
  58. data/lib/puppet/network/xmlrpc/client.rb +5 -5
  59. data/lib/puppet/node.rb +5 -9
  60. data/lib/puppet/node/environment.rb +1 -17
  61. data/lib/puppet/node/facts.rb +0 -0
  62. data/lib/puppet/parameter.rb +1 -28
  63. data/lib/puppet/parser/ast.rb +6 -0
  64. data/lib/puppet/parser/ast/arithmetic_operator.rb +41 -0
  65. data/lib/puppet/parser/ast/boolean_operator.rb +48 -0
  66. data/lib/puppet/parser/ast/collexpr.rb +6 -1
  67. data/lib/puppet/parser/ast/comparison_operator.rb +37 -0
  68. data/lib/puppet/parser/ast/minus.rb +23 -0
  69. data/lib/puppet/parser/ast/nop.rb +11 -0
  70. data/lib/puppet/parser/ast/not.rb +19 -0
  71. data/lib/puppet/parser/ast/resource_override.rb +23 -16
  72. data/lib/puppet/parser/ast/resource_reference.rb +10 -6
  73. data/lib/puppet/parser/ast/vardef.rb +2 -2
  74. data/lib/puppet/parser/collector.rb +2 -1
  75. data/lib/puppet/parser/functions.rb +7 -217
  76. data/lib/puppet/parser/functions/defined.rb +27 -0
  77. data/lib/puppet/parser/functions/fail.rb +4 -0
  78. data/lib/puppet/parser/functions/file.rb +21 -0
  79. data/lib/puppet/parser/functions/fqdn_rand.rb +15 -0
  80. data/lib/puppet/parser/functions/generate.rb +35 -0
  81. data/lib/puppet/parser/functions/include.rb +26 -0
  82. data/lib/puppet/parser/functions/realize.rb +14 -0
  83. data/lib/puppet/parser/functions/search.rb +7 -0
  84. data/lib/puppet/parser/functions/sha1.rb +6 -0
  85. data/lib/puppet/parser/functions/tag.rb +6 -0
  86. data/lib/puppet/parser/functions/tagged.rb +18 -0
  87. data/lib/puppet/parser/functions/template.rb +22 -0
  88. data/lib/puppet/parser/lexer.rb +15 -5
  89. data/lib/puppet/parser/parser.rb +1073 -715
  90. data/lib/puppet/parser/parser_support.rb +18 -13
  91. data/lib/puppet/parser/resource.rb +1 -1
  92. data/lib/puppet/parser/resource/param.rb +10 -2
  93. data/lib/puppet/parser/scope.rb +63 -5
  94. data/lib/puppet/parser/templatewrapper.rb +61 -15
  95. data/lib/puppet/property.rb +7 -1
  96. data/lib/puppet/property/keyvalue.rb +96 -0
  97. data/lib/puppet/property/list.rb +78 -0
  98. data/lib/puppet/provider/confine.rb +1 -1
  99. data/lib/puppet/provider/confine/variable.rb +10 -1
  100. data/lib/puppet/provider/cron/crontab.rb +0 -0
  101. data/lib/puppet/provider/mailalias/aliases.rb +0 -0
  102. data/lib/puppet/provider/maillist/mailman.rb +0 -0
  103. data/lib/puppet/provider/mount/parsed.rb +0 -0
  104. data/lib/puppet/provider/nameservice.rb +24 -39
  105. data/lib/puppet/provider/nameservice/directoryservice.rb +12 -3
  106. data/lib/puppet/provider/nameservice/netinfo.rb +12 -2
  107. data/lib/puppet/provider/nameservice/objectadd.rb +1 -10
  108. data/lib/puppet/provider/package/appdmg.rb +1 -1
  109. data/lib/puppet/provider/package/apple.rb +0 -0
  110. data/lib/puppet/provider/package/apt.rb +14 -21
  111. data/lib/puppet/provider/package/aptitude.rb +0 -0
  112. data/lib/puppet/provider/package/blastwave.rb +2 -0
  113. data/lib/puppet/provider/package/darwinport.rb +0 -0
  114. data/lib/puppet/provider/package/dpkg.rb +33 -51
  115. data/lib/puppet/provider/package/fink.rb +1 -1
  116. data/lib/puppet/provider/package/freebsd.rb +0 -0
  117. data/lib/puppet/provider/package/gem.rb +0 -0
  118. data/lib/puppet/provider/package/hpux.rb +46 -0
  119. data/lib/puppet/provider/package/openbsd.rb +0 -0
  120. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  121. data/lib/puppet/provider/package/portage.rb +3 -1
  122. data/lib/puppet/provider/package/ports.rb +3 -3
  123. data/lib/puppet/provider/package/rpm.rb +8 -1
  124. data/lib/puppet/provider/package/rug.rb +2 -2
  125. data/lib/puppet/provider/package/sun.rb +2 -0
  126. data/lib/puppet/provider/package/sunfreeware.rb +3 -0
  127. data/lib/puppet/provider/package/yum.rb +24 -17
  128. data/lib/puppet/provider/package/yumhelper.py +92 -11
  129. data/lib/puppet/provider/parsedfile.rb +0 -0
  130. data/lib/puppet/provider/port/parsed.rb +0 -0
  131. data/lib/puppet/provider/selboolean/getsetsebool.rb +47 -0
  132. data/lib/puppet/provider/selmodule/semodule.rb +143 -0
  133. data/lib/puppet/provider/service/base.rb +0 -0
  134. data/lib/puppet/provider/service/daemontools.rb +154 -0
  135. data/lib/puppet/provider/service/debian.rb +1 -1
  136. data/lib/puppet/provider/service/freebsd.rb +2 -0
  137. data/lib/puppet/provider/service/gentoo.rb +2 -0
  138. data/lib/puppet/provider/service/init.rb +0 -0
  139. data/lib/puppet/provider/service/redhat.rb +1 -1
  140. data/lib/puppet/provider/service/runit.rb +93 -0
  141. data/lib/puppet/provider/service/smf.rb +2 -0
  142. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -1
  143. data/lib/puppet/provider/sshkey/parsed.rb +0 -0
  144. data/lib/puppet/provider/user/hpux.rb +30 -0
  145. data/lib/puppet/provider/user/user_role_add.rb +156 -0
  146. data/lib/puppet/provider/user/useradd.rb +23 -14
  147. data/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb +17 -0
  148. data/lib/puppet/rails/database/schema.rb +0 -8
  149. data/lib/puppet/rails/resource.rb +6 -6
  150. data/lib/puppet/reference/configuration.rb +0 -7
  151. data/lib/puppet/reports.rb +0 -0
  152. data/lib/puppet/reports/rrdgraph.rb +3 -2
  153. data/lib/puppet/sslcertificates.rb +0 -0
  154. data/lib/puppet/sslcertificates/inventory.rb +3 -2
  155. data/lib/puppet/sslcertificates/support.rb +3 -0
  156. data/lib/puppet/transaction/report.rb +1 -7
  157. data/lib/puppet/transportable.rb +10 -7
  158. data/lib/puppet/type.rb +2110 -14
  159. data/lib/puppet/type/cron.rb +0 -0
  160. data/lib/puppet/type/exec.rb +0 -0
  161. data/lib/puppet/type/file.rb +12 -2
  162. data/lib/puppet/type/file/checksum.rb +4 -0
  163. data/lib/puppet/type/file/content.rb +0 -0
  164. data/lib/puppet/type/file/ensure.rb +0 -0
  165. data/lib/puppet/type/file/group.rb +30 -43
  166. data/lib/puppet/type/file/mode.rb +0 -0
  167. data/lib/puppet/type/file/owner.rb +0 -0
  168. data/lib/puppet/type/file/selcontext.rb +104 -0
  169. data/lib/puppet/type/file/source.rb +0 -0
  170. data/lib/puppet/type/file/type.rb +0 -0
  171. data/lib/puppet/type/filebucket.rb +0 -0
  172. data/lib/puppet/type/group.rb +0 -8
  173. data/lib/puppet/type/host.rb +0 -0
  174. data/lib/puppet/type/mailalias.rb +0 -0
  175. data/lib/puppet/type/maillist.rb +0 -0
  176. data/lib/puppet/type/mount.rb +0 -0
  177. data/lib/puppet/type/package.rb +2 -2
  178. data/lib/puppet/type/port.rb +0 -0
  179. data/lib/puppet/type/schedule.rb +0 -0
  180. data/lib/puppet/type/selboolean.rb +31 -0
  181. data/lib/puppet/type/selmodule.rb +54 -0
  182. data/lib/puppet/type/ssh_authorized_key.rb +3 -3
  183. data/lib/puppet/type/sshkey.rb +0 -0
  184. data/lib/puppet/type/tidy.rb +0 -0
  185. data/lib/puppet/type/user.rb +153 -137
  186. data/lib/puppet/type/yumrepo.rb +18 -2
  187. data/lib/puppet/type/zone.rb +5 -1
  188. data/lib/puppet/util.rb +7 -7
  189. data/lib/puppet/util/filetype.rb +7 -0
  190. data/lib/puppet/util/instance_loader.rb +0 -0
  191. data/lib/puppet/util/ldap/connection.rb +11 -1
  192. data/lib/puppet/util/ldap/manager.rb +1 -1
  193. data/lib/puppet/util/loadedfile.rb +0 -0
  194. data/lib/puppet/util/log.rb +42 -43
  195. data/lib/puppet/util/metric.rb +23 -9
  196. data/lib/puppet/util/posix.rb +69 -18
  197. data/lib/puppet/util/selinux.rb +139 -0
  198. data/lib/puppet/util/settings.rb +5 -7
  199. data/lib/puppet/util/user_attr.rb +21 -0
  200. data/test/certmgr/ca.rb +0 -0
  201. data/test/certmgr/certmgr.rb +0 -0
  202. data/test/certmgr/inventory.rb +0 -0
  203. data/test/certmgr/support.rb +0 -0
  204. data/test/data/providers/ssh_authorized_key/parsed/authorized_keys1 +3 -0
  205. data/test/data/snippets/append.pp +11 -0
  206. data/test/data/snippets/arithmetic_expression.pp +8 -0
  207. data/test/data/snippets/arraytrailingcomma.pp +3 -0
  208. data/test/data/snippets/emptyifelse.pp +9 -0
  209. data/test/data/snippets/funccomma.pp +5 -0
  210. data/test/data/snippets/ifexpression.rb +6 -0
  211. data/test/data/snippets/subclass_name_duplication.pp +0 -0
  212. data/test/executables/filebucket.rb +0 -0
  213. data/test/executables/puppetbin.rb +0 -0
  214. data/test/executables/puppetca.rb +0 -0
  215. data/test/executables/puppetd.rb +0 -0
  216. data/test/executables/puppetmasterd.rb +0 -0
  217. data/test/executables/puppetmodule.rb +0 -0
  218. data/test/language/ast.rb +0 -0
  219. data/test/language/ast/casestatement.rb +0 -0
  220. data/test/language/ast/resource.rb +0 -0
  221. data/test/language/ast/resource_reference.rb +0 -28
  222. data/test/language/ast/selector.rb +0 -0
  223. data/test/language/ast/variable.rb +0 -0
  224. data/test/language/functions.rb +91 -12
  225. data/test/language/parser.rb +21 -0
  226. data/test/language/resource.rb +0 -0
  227. data/test/language/scope.rb +28 -0
  228. data/test/language/snippets.rb +14 -0
  229. data/test/language/transportable.rb +0 -0
  230. data/test/lib/puppettest.rb +0 -0
  231. data/test/lib/puppettest/reporttesting.rb +0 -2
  232. data/test/lib/puppettest/runnable_test.rb +2 -0
  233. data/test/lib/puppettest/support/resources.rb +0 -0
  234. data/test/network/authconfig.rb +0 -0
  235. data/test/network/authorization.rb +0 -0
  236. data/test/network/authstore.rb +0 -0
  237. data/test/network/client/ca.rb +0 -0
  238. data/test/network/client/client.rb +0 -0
  239. data/test/network/client/dipper.rb +0 -0
  240. data/test/network/client/master.rb +2 -6
  241. data/test/network/client/resource.rb +0 -0
  242. data/test/network/client_request.rb +0 -0
  243. data/test/network/daemon.rb +0 -0
  244. data/test/network/handler/bucket.rb +0 -0
  245. data/test/network/handler/ca.rb +0 -0
  246. data/test/network/handler/fileserver.rb +8 -0
  247. data/test/network/handler/handler.rb +0 -0
  248. data/test/network/handler/master.rb +3 -1
  249. data/test/network/handler/report.rb +0 -0
  250. data/test/network/handler/resource.rb +0 -0
  251. data/test/network/handler/runner.rb +0 -0
  252. data/test/network/rights.rb +0 -0
  253. data/test/network/server/mongrel_test.rb +0 -0
  254. data/test/network/server/webrick.rb +0 -0
  255. data/test/network/xmlrpc/client.rb +0 -0
  256. data/test/network/xmlrpc/processor.rb +0 -0
  257. data/test/network/xmlrpc/server.rb +0 -0
  258. data/test/network/xmlrpc/webrick_servlet.rb +0 -0
  259. data/test/other/dsl.rb +0 -0
  260. data/test/other/events.rb +0 -0
  261. data/test/other/overrides.rb +0 -0
  262. data/test/other/provider.rb +0 -0
  263. data/test/other/puppet.rb +0 -0
  264. data/test/other/relationships.rb +0 -0
  265. data/test/other/report.rb +2 -4
  266. data/test/other/transactions.rb +1 -1
  267. data/test/puppet/conffiles.rb +0 -0
  268. data/test/puppet/defaults.rb +0 -0
  269. data/test/puppet/errortest.rb +0 -0
  270. data/test/puppet/tc_suidmanager.rb +0 -0
  271. data/test/rails/ast.rb +0 -0
  272. data/test/rails/configuration.rb +0 -0
  273. data/test/rails/host.rb +0 -0
  274. data/test/rails/rails.rb +0 -0
  275. data/test/rails/railsparameter.rb +0 -0
  276. data/test/rails/railsresource.rb +0 -0
  277. data/test/ral/manager/attributes.rb +0 -0
  278. data/test/ral/manager/instances.rb +0 -0
  279. data/test/ral/manager/manager.rb +0 -0
  280. data/test/ral/manager/provider.rb +0 -0
  281. data/test/ral/manager/type.rb +0 -0
  282. data/test/ral/providers/cron/crontab.rb +0 -0
  283. data/test/ral/providers/group.rb +14 -13
  284. data/test/ral/providers/host/netinfo.rb +0 -0
  285. data/test/ral/providers/host/parsed.rb +0 -0
  286. data/test/ral/providers/mailalias/aliases.rb +0 -0
  287. data/test/ral/providers/mount/netinfo.rb +0 -0
  288. data/test/ral/providers/nameservice.rb +0 -0
  289. data/test/ral/providers/package.rb +0 -31
  290. data/test/ral/providers/package/aptitude.rb +1 -2
  291. data/test/ral/providers/package/aptrpm.rb +2 -2
  292. data/test/ral/providers/parsedfile.rb +0 -0
  293. data/test/ral/providers/port/parsed.rb +0 -0
  294. data/test/ral/providers/provider.rb +0 -0
  295. data/test/ral/providers/service/base.rb +0 -0
  296. data/test/ral/providers/service/debian.rb +0 -0
  297. data/test/ral/providers/sshkey/parsed.rb +0 -0
  298. data/test/ral/providers/user.rb +8 -8
  299. data/test/ral/providers/user/useradd.rb +0 -0
  300. data/test/ral/type/basic.rb +0 -0
  301. data/test/ral/type/cron.rb +0 -0
  302. data/test/ral/type/exec.rb +0 -0
  303. data/test/ral/type/file.rb +0 -0
  304. data/test/ral/type/file/target.rb +0 -0
  305. data/test/ral/type/filebucket.rb +0 -0
  306. data/test/ral/type/fileignoresource.rb +0 -0
  307. data/test/ral/type/filesources.rb +1 -3
  308. data/test/ral/type/group.rb +0 -0
  309. data/test/ral/type/host.rb +0 -0
  310. data/test/ral/type/mailalias.rb +1 -2
  311. data/test/ral/type/parameter.rb +0 -0
  312. data/test/ral/type/port.rb +0 -0
  313. data/test/ral/type/property.rb +0 -0
  314. data/test/ral/type/resources.rb +0 -0
  315. data/test/ral/type/service.rb +0 -0
  316. data/test/ral/type/sshkey.rb +0 -0
  317. data/test/ral/type/tidy.rb +0 -0
  318. data/test/ral/type/user.rb +0 -50
  319. data/test/ral/type/yumrepo.rb +7 -1
  320. data/test/ral/type/zone.rb +0 -0
  321. data/test/test +0 -0
  322. data/test/util/autoload.rb +0 -0
  323. data/test/util/classgen.rb +0 -0
  324. data/test/util/execution.rb +0 -0
  325. data/test/util/features.rb +0 -0
  326. data/test/util/fileparsing.rb +0 -0
  327. data/test/util/filetype.rb +0 -0
  328. data/test/util/inifile.rb +0 -0
  329. data/test/util/instance_loader.rb +0 -0
  330. data/test/util/log.rb +0 -59
  331. data/test/util/metrics.rb +0 -0
  332. data/test/util/package.rb +0 -0
  333. data/test/util/pidlock.rb +0 -0
  334. data/test/util/settings.rb +0 -0
  335. data/test/util/storage.rb +0 -0
  336. data/test/util/subclass_loader.rb +0 -0
  337. data/test/util/utiltest.rb +0 -0
  338. metadata +54 -19
  339. data/lib/puppet/metatype/attributes.rb +0 -685
  340. data/lib/puppet/metatype/closure.rb +0 -49
  341. data/lib/puppet/metatype/container.rb +0 -50
  342. data/lib/puppet/metatype/evaluation.rb +0 -163
  343. data/lib/puppet/metatype/instances.rb +0 -305
  344. data/lib/puppet/metatype/metaparams.rb +0 -423
  345. data/lib/puppet/metatype/providers.rb +0 -247
  346. data/lib/puppet/metatype/relationships.rb +0 -115
  347. data/lib/puppet/metatype/schedules.rb +0 -33
  348. data/lib/puppet/metatype/tags.rb +0 -38
  349. data/lib/puppet/util/plist.rb +0 -23
  350. data/lib/puppet/util/plist/generator.rb +0 -225
  351. data/lib/puppet/util/plist/parser.rb +0 -226
  352. data/test/ral/providers/package/apt.rb +0 -169
  353. data/test/ral/providers/package/dpkg.rb +0 -64
  354. data/test/util/posixtest.rb +0 -169
@@ -1,685 +0,0 @@
1
- require 'puppet'
2
- require 'puppet/type'
3
-
4
- class Puppet::Type
5
- class << self
6
- include Puppet::Util::ClassGen
7
- include Puppet::Util::Warnings
8
- attr_reader :properties
9
- end
10
-
11
- def self.states
12
- warnonce "The states method is deprecated; use properties"
13
- properties()
14
- end
15
-
16
- # All parameters, in the appropriate order. The namevar comes first,
17
- # then the properties, then the params and metaparams in the order they
18
- # were specified in the files.
19
- def self.allattrs
20
- # now get all of the arguments, in a specific order
21
- # Cache this, since it gets called so many times
22
- namevar = self.namevar
23
-
24
- order = [namevar]
25
- if self.parameters.include?(:provider)
26
- order << :provider
27
- end
28
- order << [self.properties.collect { |property| property.name },
29
- self.parameters - [:provider],
30
- self.metaparams].flatten.reject { |param|
31
- # we don't want our namevar in there multiple times
32
- param == namevar
33
- }
34
-
35
- order.flatten!
36
-
37
- return order
38
- end
39
-
40
- # Retrieve an attribute alias, if there is one.
41
- def self.attr_alias(param)
42
- @attr_aliases[symbolize(param)]
43
- end
44
-
45
- # Create an alias to an existing attribute. This will cause the aliased
46
- # attribute to be valid when setting and retrieving values on the instance.
47
- def self.set_attr_alias(hash)
48
- hash.each do |new, old|
49
- @attr_aliases[symbolize(new)] = symbolize(old)
50
- end
51
- end
52
-
53
- # Find the class associated with any given attribute.
54
- def self.attrclass(name)
55
- @attrclasses ||= {}
56
-
57
- # We cache the value, since this method gets called such a huge number
58
- # of times (as in, hundreds of thousands in a given run).
59
- unless @attrclasses.include?(name)
60
- @attrclasses[name] = case self.attrtype(name)
61
- when :property: @validproperties[name]
62
- when :meta: @@metaparamhash[name]
63
- when :param: @paramhash[name]
64
- end
65
- end
66
- @attrclasses[name]
67
- end
68
-
69
- # What type of parameter are we dealing with? Cache the results, because
70
- # this method gets called so many times.
71
- def self.attrtype(attr)
72
- @attrtypes ||= {}
73
- unless @attrtypes.include?(attr)
74
- @attrtypes[attr] = case
75
- when @validproperties.include?(attr): :property
76
- when @paramhash.include?(attr): :param
77
- when @@metaparamhash.include?(attr): :meta
78
- else
79
- raise Puppet::DevError,
80
- "Invalid attribute '%s' for class '%s'" %
81
- [attr, self.name]
82
- end
83
- end
84
-
85
- @attrtypes[attr]
86
- end
87
-
88
- # Copy an existing class parameter. This allows other types to avoid
89
- # duplicating a parameter definition, and is mostly used by subclasses
90
- # of the File class.
91
- def self.copyparam(klass, name)
92
- param = klass.attrclass(name)
93
-
94
- unless param
95
- raise Puppet::DevError, "Class %s has no param %s" % [klass, name]
96
- end
97
- @parameters << param
98
- @parameters.each { |p| @paramhash[name] = p }
99
-
100
- if param.isnamevar?
101
- @namevar = param.name
102
- end
103
- end
104
-
105
- # A similar function but one that yields the class and type.
106
- # This is mainly so that setdefaults doesn't call quite so many functions.
107
- def self.eachattr(*ary)
108
- if ary.empty?
109
- ary = nil
110
- end
111
-
112
- # We have to do this in a specific order, so that defaults are
113
- # created in that order (e.g., providers should be set up before
114
- # anything else).
115
- allattrs.each do |name|
116
- next unless ary.nil? or ary.include?(name)
117
- if obj = @properties.find { |p| p.name == name }
118
- yield obj, :property
119
- elsif obj = @parameters.find { |p| p.name == name }
120
- yield obj, :param
121
- elsif obj = @@metaparams.find { |p| p.name == name }
122
- yield obj, :meta
123
- else
124
- raise Puppet::DevError, "Could not find parameter %s" % name
125
- end
126
- end
127
- end
128
-
129
- def self.eachmetaparam
130
- @@metaparams.each { |p| yield p.name }
131
- end
132
-
133
- # Create the 'ensure' class. This is a separate method so other types
134
- # can easily call it and create their own 'ensure' values.
135
- def self.ensurable(&block)
136
- if block_given?
137
- self.newproperty(:ensure, :parent => Puppet::Property::Ensure, &block)
138
- else
139
- self.newproperty(:ensure, :parent => Puppet::Property::Ensure) do
140
- self.defaultvalues
141
- end
142
- end
143
- end
144
-
145
- # Should we add the 'ensure' property to this class?
146
- def self.ensurable?
147
- # If the class has all three of these methods defined, then it's
148
- # ensurable.
149
- ens = [:exists?, :create, :destroy].inject { |set, method|
150
- set &&= self.public_method_defined?(method)
151
- }
152
-
153
- return ens
154
- end
155
-
156
- # Deal with any options passed into parameters.
157
- def self.handle_param_options(name, options)
158
- # If it's a boolean parameter, create a method to test the value easily
159
- if options[:boolean]
160
- define_method(name.to_s + "?") do
161
- val = self[name]
162
- if val == :true or val == true
163
- return true
164
- end
165
- end
166
- end
167
-
168
- # If this param handles relationships, store that information
169
- end
170
-
171
- # Is the parameter in question a meta-parameter?
172
- def self.metaparam?(param)
173
- @@metaparamhash.include?(symbolize(param))
174
- end
175
-
176
- # Find the metaparameter class associated with a given metaparameter name.
177
- def self.metaparamclass(name)
178
- @@metaparamhash[symbolize(name)]
179
- end
180
-
181
- def self.metaparams
182
- @@metaparams.collect { |param| param.name }
183
- end
184
-
185
- def self.metaparamdoc(metaparam)
186
- @@metaparamhash[metaparam].doc
187
- end
188
-
189
- # Create a new metaparam. Requires a block and a name, stores it in the
190
- # @parameters array, and does some basic checking on it.
191
- def self.newmetaparam(name, options = {}, &block)
192
- @@metaparams ||= []
193
- @@metaparamhash ||= {}
194
- name = symbolize(name)
195
-
196
- param = genclass(name,
197
- :parent => options[:parent] || Puppet::Parameter,
198
- :prefix => "MetaParam",
199
- :hash => @@metaparamhash,
200
- :array => @@metaparams,
201
- :attributes => options[:attributes],
202
- &block
203
- )
204
-
205
- # Grr.
206
- if options[:required_features]
207
- param.required_features = options[:required_features]
208
- end
209
-
210
- handle_param_options(name, options)
211
-
212
- param.metaparam = true
213
-
214
- return param
215
- end
216
-
217
- # Find the namevar
218
- def self.namevar
219
- unless defined? @namevar
220
- params = @parameters.find_all { |param|
221
- param.isnamevar? or param.name == :name
222
- }
223
-
224
- if params.length > 1
225
- raise Puppet::DevError, "Found multiple namevars for %s" % self.name
226
- elsif params.length == 1
227
- @namevar = params[0].name
228
- else
229
- raise Puppet::DevError, "No namevar for %s" % self.name
230
- end
231
- end
232
- @namevar
233
- end
234
-
235
- # Create a new parameter. Requires a block and a name, stores it in the
236
- # @parameters array, and does some basic checking on it.
237
- def self.newparam(name, options = {}, &block)
238
- options[:attributes] ||= {}
239
- param = genclass(name,
240
- :parent => options[:parent] || Puppet::Parameter,
241
- :attributes => options[:attributes],
242
- :block => block,
243
- :prefix => "Parameter",
244
- :array => @parameters,
245
- :hash => @paramhash
246
- )
247
-
248
- handle_param_options(name, options)
249
-
250
- # Grr.
251
- if options[:required_features]
252
- param.required_features = options[:required_features]
253
- end
254
-
255
- param.isnamevar if options[:namevar]
256
-
257
- # These might be enabled later.
258
- # define_method(name) do
259
- # @parameters[name].value
260
- # end
261
- #
262
- # define_method(name.to_s + "=") do |value|
263
- # newparam(param, value)
264
- # end
265
-
266
- if param.isnamevar?
267
- @namevar = param.name
268
- end
269
-
270
- return param
271
- end
272
-
273
- def self.newstate(name, options = {}, &block)
274
- Puppet.warning "newstate() has been deprecrated; use newproperty(%s)" %
275
- name
276
- newproperty(name, options, &block)
277
- end
278
-
279
- # Create a new property. The first parameter must be the name of the property;
280
- # this is how users will refer to the property when creating new instances.
281
- # The second parameter is a hash of options; the options are:
282
- # * <tt>:parent</tt>: The parent class for the property. Defaults to Puppet::Property.
283
- # * <tt>:retrieve</tt>: The method to call on the provider or @parent object (if
284
- # the provider is not set) to retrieve the current value.
285
- def self.newproperty(name, options = {}, &block)
286
- name = symbolize(name)
287
-
288
- # This is here for types that might still have the old method of defining
289
- # a parent class.
290
- unless options.is_a? Hash
291
- raise Puppet::DevError,
292
- "Options must be a hash, not %s" % options.inspect
293
- end
294
-
295
- if @validproperties.include?(name)
296
- raise Puppet::DevError, "Class %s already has a property named %s" %
297
- [self.name, name]
298
- end
299
-
300
- if parent = options[:parent]
301
- options.delete(:parent)
302
- else
303
- parent = Puppet::Property
304
- end
305
-
306
- # We have to create our own, new block here because we want to define
307
- # an initial :retrieve method, if told to, and then eval the passed
308
- # block if available.
309
- prop = genclass(name, :parent => parent, :hash => @validproperties, :attributes => options) do
310
- # If they've passed a retrieve method, then override the retrieve
311
- # method on the class.
312
- if options[:retrieve]
313
- define_method(:retrieve) do
314
- provider.send(options[:retrieve])
315
- end
316
- end
317
-
318
- if block
319
- class_eval(&block)
320
- end
321
- end
322
-
323
- # If it's the 'ensure' property, always put it first.
324
- if name == :ensure
325
- @properties.unshift prop
326
- else
327
- @properties << prop
328
- end
329
-
330
- # define_method(name) do
331
- # @parameters[name].should
332
- # end
333
- #
334
- # define_method(name.to_s + "=") do |value|
335
- # newproperty(name, :should => value)
336
- # end
337
-
338
- return prop
339
- end
340
-
341
- def self.paramdoc(param)
342
- @paramhash[param].doc
343
- end
344
-
345
- # Return the parameter names
346
- def self.parameters
347
- return [] unless defined? @parameters
348
- @parameters.collect { |klass| klass.name }
349
- end
350
-
351
- # Find the parameter class associated with a given parameter name.
352
- def self.paramclass(name)
353
- @paramhash[name]
354
- end
355
-
356
- # Return the property class associated with a name
357
- def self.propertybyname(name)
358
- @validproperties[name]
359
- end
360
-
361
- def self.validattr?(name)
362
- name = symbolize(name)
363
- return true if name == :name
364
- @validattrs ||= {}
365
-
366
- unless @validattrs.include?(name)
367
- if self.validproperty?(name) or self.validparameter?(name) or self.metaparam?(name)
368
- @validattrs[name] = true
369
- else
370
- @validattrs[name] = false
371
- end
372
- end
373
-
374
- @validattrs[name]
375
- end
376
-
377
- # does the name reflect a valid property?
378
- def self.validproperty?(name)
379
- name = symbolize(name)
380
- if @validproperties.include?(name)
381
- return @validproperties[name]
382
- else
383
- return false
384
- end
385
- end
386
-
387
- # Return the list of validproperties
388
- def self.validproperties
389
- return {} unless defined? @parameters
390
-
391
- return @validproperties.keys
392
- end
393
-
394
- # does the name reflect a valid parameter?
395
- def self.validparameter?(name)
396
- unless defined? @parameters
397
- raise Puppet::DevError, "Class %s has not defined parameters" % self
398
- end
399
- if @paramhash.include?(name) or @@metaparamhash.include?(name)
400
- return true
401
- else
402
- return false
403
- end
404
- end
405
-
406
- # fix any namevar => param translations
407
- def argclean(oldhash)
408
- # This duplication is here because it might be a transobject.
409
- hash = oldhash.dup.to_hash
410
-
411
- if hash.include?(:resource)
412
- hash.delete(:resource)
413
- end
414
- namevar = self.class.namevar
415
-
416
- # Do a simple translation for those cases where they've passed :name
417
- # but that's not our namevar
418
- if hash.include? :name and namevar != :name
419
- if hash.include? namevar
420
- raise ArgumentError, "Cannot provide both name and %s" % namevar
421
- end
422
- hash[namevar] = hash[:name]
423
- hash.delete(:name)
424
- end
425
-
426
- # Make sure we have a name, one way or another
427
- unless hash.include? namevar
428
- if defined? @title and @title
429
- hash[namevar] = @title
430
- else
431
- raise Puppet::Error, "Was not passed a namevar or title"
432
- end
433
- end
434
-
435
- return hash
436
- end
437
-
438
- # Return either the attribute alias or the attribute.
439
- def attr_alias(name)
440
- name = symbolize(name)
441
- if synonym = self.class.attr_alias(name)
442
- return synonym
443
- else
444
- return name
445
- end
446
- end
447
-
448
- # Are we deleting this resource?
449
- def deleting?
450
- obj = @parameters[:ensure] and obj.should == :absent
451
- end
452
-
453
- # Create a new property if it is valid but doesn't exist
454
- # Returns: true if a new parameter was added, false otherwise
455
- def add_property_parameter(prop_name)
456
- if self.class.validproperty?(prop_name) && !@parameters[prop_name]
457
- self.newattr(prop_name)
458
- return true
459
- end
460
- return false
461
- end
462
-
463
- # abstract accessing parameters and properties, and normalize
464
- # access to always be symbols, not strings
465
- # This returns a value, not an object. It returns the 'is'
466
- # value, but you can also specifically return 'is' and 'should'
467
- # values using 'object.is(:property)' or 'object.should(:property)'.
468
- def [](name)
469
- name = attr_alias(name)
470
-
471
- unless self.class.validattr?(name)
472
- raise TypeError.new("Invalid parameter %s(%s)" % [name, name.inspect])
473
- end
474
-
475
- if name == :name
476
- name = self.class.namevar
477
- end
478
-
479
- if obj = @parameters[name]
480
- # Note that if this is a property, then the value is the "should" value,
481
- # not the current value.
482
- obj.value
483
- else
484
- return nil
485
- end
486
- end
487
-
488
- # Abstract setting parameters and properties, and normalize
489
- # access to always be symbols, not strings. This sets the 'should'
490
- # value on properties, and otherwise just sets the appropriate parameter.
491
- def []=(name,value)
492
- name = attr_alias(name)
493
-
494
- unless self.class.validattr?(name)
495
- raise TypeError.new("Invalid parameter %s" % [name])
496
- end
497
-
498
- if name == :name
499
- name = self.class.namevar
500
- end
501
- if value.nil?
502
- raise Puppet::Error.new("Got nil value for %s" % name)
503
- end
504
-
505
- if obj = @parameters[name]
506
- obj.value = value
507
- return nil
508
- else
509
- self.newattr(name, :value => value)
510
- end
511
-
512
- nil
513
- end
514
-
515
- # remove a property from the object; useful in testing or in cleanup
516
- # when an error has been encountered
517
- def delete(attr)
518
- attr = symbolize(attr)
519
- if @parameters.has_key?(attr)
520
- @parameters.delete(attr)
521
- else
522
- raise Puppet::DevError.new("Undefined attribute '#{attr}' in #{self}")
523
- end
524
- end
525
-
526
- # iterate across the existing properties
527
- def eachproperty
528
- # properties() is a private method
529
- properties().each { |property|
530
- yield property
531
- }
532
- end
533
-
534
- # retrieve the 'should' value for a specified property
535
- def should(name)
536
- name = attr_alias(name)
537
- if prop = @parameters[name] and prop.is_a?(Puppet::Property)
538
- return prop.should
539
- else
540
- return nil
541
- end
542
- end
543
-
544
- # Create the actual attribute instance. Requires either the attribute
545
- # name or class as the first argument, then an optional hash of
546
- # attributes to set during initialization.
547
- def newattr(name, options = {})
548
- if name.is_a?(Class)
549
- klass = name
550
- name = klass.name
551
- end
552
-
553
- unless klass = self.class.attrclass(name)
554
- raise Puppet::Error, "Resource type %s does not support parameter %s" % [self.class.name, name]
555
- end
556
-
557
- if @parameters.include?(name)
558
- raise Puppet::Error, "Parameter '%s' is already defined in %s" %
559
- [name, self.ref]
560
- end
561
-
562
- if provider and ! provider.class.supports_parameter?(klass)
563
- missing = klass.required_features.find_all { |f| ! provider.class.feature?(f) }
564
- info "Provider %s does not support features %s; not managing attribute %s" % [provider.class.name, missing.join(", "), name]
565
- return nil
566
- end
567
-
568
- # Add resource information at creation time, so it's available
569
- # during validation.
570
- options[:resource] = self
571
- begin
572
- # make sure the parameter doesn't have any errors
573
- return @parameters[name] = klass.new(options)
574
- rescue => detail
575
- error = Puppet::Error.new("Parameter %s failed: %s" %
576
- [name, detail])
577
- error.set_backtrace(detail.backtrace)
578
- raise error
579
- end
580
- end
581
-
582
- # return the value of a parameter
583
- def parameter(name)
584
- unless name.is_a? Symbol
585
- name = name.intern
586
- end
587
- return @parameters[name].value
588
- end
589
-
590
- # Is the named property defined?
591
- def propertydefined?(name)
592
- unless name.is_a? Symbol
593
- name = name.intern
594
- end
595
- return @parameters.include?(name)
596
- end
597
-
598
- # return an actual type by name; to return the value, use 'inst[name]'
599
- # FIXME this method should go away
600
- def property(name)
601
- if obj = @parameters[symbolize(name)] and obj.is_a?(Puppet::Property)
602
- return obj
603
- else
604
- return nil
605
- end
606
- end
607
-
608
- # def set(name, value)
609
- # send(name.to_s + "=", value)
610
- # end
611
- #
612
- # def get(name)
613
- # send(name)
614
- # end
615
-
616
- # For any parameters or properties that have defaults and have not yet been
617
- # set, set them now. This method can be handed a list of attributes,
618
- # and if so it will only set defaults for those attributes.
619
- def setdefaults(*ary)
620
- #self.class.eachattr(*ary) { |klass, type|
621
- self.class.eachattr(*ary) { |klass, type|
622
- # not many attributes will have defaults defined, so we short-circuit
623
- # those away
624
- next unless klass.method_defined?(:default)
625
- next if @parameters[klass.name]
626
-
627
- next unless obj = self.newattr(klass)
628
-
629
- # We have to check for nil values, not "truth", so we allow defaults
630
- # to false.
631
- value = obj.default and ! value.nil?
632
- if ! value.nil?
633
- obj.value = value
634
- else
635
- @parameters.delete(obj.name)
636
- end
637
- }
638
- end
639
-
640
- # Convert our object to a hash. This just includes properties.
641
- def to_hash
642
- rethash = {}
643
-
644
- @parameters.each do |name, obj|
645
- rethash[name] = obj.value
646
- end
647
-
648
- rethash
649
- end
650
-
651
- # Return a specific value for an attribute.
652
- def value(name)
653
- name = attr_alias(name)
654
-
655
- if obj = @parameters[name] and obj.respond_to?(:value)
656
- return obj.value
657
- else
658
- return nil
659
- end
660
- end
661
-
662
- # Meta-parameter methods: These methods deal with the results
663
- # of specifying metaparameters
664
-
665
- private
666
-
667
- # Return all of the property objects, in the order specified in the
668
- # class.
669
- def properties
670
- #debug "%s has %s properties" % [self,@parameters.length]
671
- props = self.class.properties.collect { |prop|
672
- @parameters[prop.name]
673
- }.find_all { |p|
674
- ! p.nil?
675
- }.each do |prop|
676
- unless prop.is_a?(Puppet::Property)
677
- raise Puppet::DevError, "got a non-property %s(%s)" %
678
- [prop.class, prop.class.name]
679
- end
680
- end
681
-
682
- props
683
- end
684
- end
685
-