puppet 0.9.2 → 0.13.0

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 (213) hide show
  1. data/CHANGELOG +58 -0
  2. data/README +21 -18
  3. data/Rakefile +176 -36
  4. data/bin/puppet +34 -48
  5. data/bin/puppetca +41 -28
  6. data/bin/puppetd +87 -65
  7. data/bin/puppetdoc +99 -23
  8. data/bin/puppetmasterd +72 -91
  9. data/conf/redhat/client.init +80 -0
  10. data/conf/redhat/client.sysconfig +11 -0
  11. data/conf/redhat/fileserver.conf +12 -0
  12. data/conf/redhat/puppet.spec +130 -0
  13. data/conf/redhat/server.init +89 -0
  14. data/conf/redhat/server.sysconfig +9 -0
  15. data/examples/code/allatonce +2 -2
  16. data/examples/code/assignments +1 -1
  17. data/examples/code/classing +2 -2
  18. data/examples/code/components +2 -2
  19. data/examples/code/file.bl +5 -5
  20. data/examples/code/filedefaults +2 -2
  21. data/examples/code/fileparsing +1 -1
  22. data/examples/code/filerecursion +1 -1
  23. data/examples/code/functions +1 -1
  24. data/examples/code/groups +1 -1
  25. data/examples/code/importing +1 -1
  26. data/examples/code/nodes +1 -1
  27. data/examples/code/one +1 -1
  28. data/examples/code/relationships +2 -2
  29. data/examples/code/simpletests +5 -5
  30. data/examples/code/snippets/argumentdefaults +2 -2
  31. data/examples/code/snippets/casestatement +16 -8
  32. data/examples/code/snippets/classheirarchy.pp +4 -4
  33. data/examples/code/snippets/classincludes.pp +4 -4
  34. data/examples/code/snippets/classpathtest +2 -2
  35. data/examples/code/snippets/componentmetaparams.pp +11 -0
  36. data/examples/code/snippets/dirchmod +5 -5
  37. data/examples/code/snippets/emptyclass.pp +9 -0
  38. data/examples/code/snippets/failmissingexecpath.pp +1 -1
  39. data/examples/code/snippets/falsevalues.pp +1 -1
  40. data/examples/code/snippets/filecreate +5 -5
  41. data/examples/code/snippets/implicititeration +5 -5
  42. data/examples/code/snippets/multipleinstances +4 -4
  43. data/examples/code/snippets/namevartest +3 -3
  44. data/examples/code/snippets/scopetest +1 -1
  45. data/examples/code/snippets/selectorvalues.pp +3 -3
  46. data/examples/code/snippets/simpledefaults +2 -2
  47. data/examples/code/snippets/simpleselector +5 -5
  48. data/examples/code/snippets/singleary.pp +19 -0
  49. data/examples/root/etc/init.d/sleeper +3 -2
  50. data/ext/emacs/puppet-mode-init.el +6 -0
  51. data/ext/emacs/puppet-mode.el +189 -0
  52. data/ext/ldap/puppet.schema +17 -0
  53. data/ext/{module:puppet → module_puppet} +30 -31
  54. data/ext/vim/filetype.vim +9 -0
  55. data/ext/vim/puppet.vim +87 -0
  56. data/install.rb +63 -30
  57. data/lib/puppet.rb +216 -122
  58. data/lib/puppet/client.rb +51 -416
  59. data/lib/puppet/client/ca.rb +17 -0
  60. data/lib/puppet/client/dipper.rb +78 -0
  61. data/lib/puppet/client/file.rb +20 -0
  62. data/lib/puppet/client/log.rb +17 -0
  63. data/lib/puppet/client/master.rb +246 -0
  64. data/lib/puppet/client/proxy.rb +27 -0
  65. data/lib/puppet/client/status.rb +7 -0
  66. data/lib/puppet/config.rb +563 -13
  67. data/lib/puppet/daemon.rb +50 -22
  68. data/lib/puppet/element.rb +4 -4
  69. data/lib/puppet/event-loop.rb +1 -0
  70. data/lib/puppet/event-loop/better-definers.rb +367 -0
  71. data/lib/puppet/event-loop/event-loop.rb +355 -0
  72. data/lib/puppet/event-loop/signal-system.rb +220 -0
  73. data/lib/puppet/event.rb +9 -11
  74. data/lib/puppet/filetype.rb +195 -0
  75. data/lib/puppet/log.rb +35 -12
  76. data/lib/puppet/metric.rb +2 -2
  77. data/lib/puppet/networkclient.rb +145 -0
  78. data/lib/puppet/parameter.rb +335 -0
  79. data/lib/puppet/parser/ast.rb +42 -1453
  80. data/lib/puppet/parser/ast/astarray.rb +88 -0
  81. data/lib/puppet/parser/ast/branch.rb +47 -0
  82. data/lib/puppet/parser/ast/caseopt.rb +66 -0
  83. data/lib/puppet/parser/ast/casestatement.rb +78 -0
  84. data/lib/puppet/parser/ast/classdef.rb +78 -0
  85. data/lib/puppet/parser/ast/compdef.rb +111 -0
  86. data/lib/puppet/parser/ast/component.rb +105 -0
  87. data/lib/puppet/parser/ast/hostclass.rb +82 -0
  88. data/lib/puppet/parser/ast/leaf.rb +86 -0
  89. data/lib/puppet/parser/ast/node.rb +103 -0
  90. data/lib/puppet/parser/ast/nodedef.rb +68 -0
  91. data/lib/puppet/parser/ast/objectdef.rb +336 -0
  92. data/lib/puppet/parser/ast/objectparam.rb +30 -0
  93. data/lib/puppet/parser/ast/objectref.rb +76 -0
  94. data/lib/puppet/parser/ast/selector.rb +60 -0
  95. data/lib/puppet/parser/ast/typedefaults.rb +45 -0
  96. data/lib/puppet/parser/ast/vardef.rb +44 -0
  97. data/lib/puppet/parser/interpreter.rb +31 -14
  98. data/lib/puppet/parser/lexer.rb +2 -4
  99. data/lib/puppet/parser/parser.rb +332 -242
  100. data/lib/puppet/parser/scope.rb +55 -38
  101. data/lib/puppet/server.rb +43 -44
  102. data/lib/puppet/server/authstore.rb +3 -6
  103. data/lib/puppet/server/ca.rb +5 -2
  104. data/lib/puppet/server/filebucket.rb +2 -4
  105. data/lib/puppet/server/fileserver.rb +28 -12
  106. data/lib/puppet/server/logger.rb +15 -4
  107. data/lib/puppet/server/master.rb +62 -7
  108. data/lib/puppet/sslcertificates.rb +41 -607
  109. data/lib/puppet/sslcertificates/ca.rb +291 -0
  110. data/lib/puppet/sslcertificates/certificate.rb +283 -0
  111. data/lib/puppet/statechange.rb +6 -1
  112. data/lib/puppet/storage.rb +67 -56
  113. data/lib/puppet/transaction.rb +25 -9
  114. data/lib/puppet/transportable.rb +102 -22
  115. data/lib/puppet/type.rb +1096 -315
  116. data/lib/puppet/type/component.rb +30 -21
  117. data/lib/puppet/type/cron.rb +409 -448
  118. data/lib/puppet/type/exec.rb +234 -174
  119. data/lib/puppet/type/group.rb +65 -82
  120. data/lib/puppet/type/nameservice.rb +247 -3
  121. data/lib/puppet/type/nameservice/netinfo.rb +29 -40
  122. data/lib/puppet/type/nameservice/objectadd.rb +52 -66
  123. data/lib/puppet/type/nameservice/posix.rb +6 -194
  124. data/lib/puppet/type/package.rb +447 -295
  125. data/lib/puppet/type/package/apt.rb +51 -50
  126. data/lib/puppet/type/package/bsd.rb +82 -0
  127. data/lib/puppet/type/package/dpkg.rb +85 -88
  128. data/lib/puppet/type/package/rpm.rb +67 -63
  129. data/lib/puppet/type/package/sun.rb +119 -98
  130. data/lib/puppet/type/package/yum.rb +41 -37
  131. data/lib/puppet/type/parsedtype.rb +295 -0
  132. data/lib/puppet/type/parsedtype/host.rb +143 -0
  133. data/lib/puppet/type/parsedtype/port.rb +232 -0
  134. data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
  135. data/lib/puppet/type/pfile.rb +484 -460
  136. data/lib/puppet/type/pfile/checksum.rb +237 -181
  137. data/lib/puppet/type/pfile/content.rb +67 -0
  138. data/lib/puppet/type/pfile/ensure.rb +212 -0
  139. data/lib/puppet/type/pfile/group.rb +106 -105
  140. data/lib/puppet/type/pfile/mode.rb +98 -101
  141. data/lib/puppet/type/pfile/source.rb +228 -209
  142. data/lib/puppet/type/pfile/type.rb +18 -21
  143. data/lib/puppet/type/pfile/uid.rb +127 -130
  144. data/lib/puppet/type/pfilebucket.rb +68 -63
  145. data/lib/puppet/type/schedule.rb +341 -0
  146. data/lib/puppet/type/service.rb +351 -255
  147. data/lib/puppet/type/service/base.rb +9 -14
  148. data/lib/puppet/type/service/debian.rb +32 -38
  149. data/lib/puppet/type/service/init.rb +130 -130
  150. data/lib/puppet/type/service/smf.rb +48 -20
  151. data/lib/puppet/type/state.rb +229 -16
  152. data/lib/puppet/type/symlink.rb +51 -63
  153. data/lib/puppet/type/tidy.rb +105 -102
  154. data/lib/puppet/type/user.rb +118 -180
  155. data/lib/puppet/util.rb +100 -6
  156. data/test/certmgr/certmgr.rb +0 -1
  157. data/test/client/client.rb +4 -4
  158. data/test/executables/puppetbin.rb +7 -14
  159. data/test/executables/puppetca.rb +18 -24
  160. data/test/executables/puppetd.rb +7 -16
  161. data/test/executables/puppetmasterd.rb +7 -9
  162. data/test/executables/puppetmodule.rb +11 -16
  163. data/test/language/ast.rb +11 -7
  164. data/test/language/interpreter.rb +1 -1
  165. data/test/language/scope.rb +2 -0
  166. data/test/language/snippets.rb +30 -5
  167. data/test/language/transportable.rb +77 -0
  168. data/test/other/config.rb +316 -0
  169. data/test/other/events.rb +22 -21
  170. data/test/other/log.rb +14 -14
  171. data/test/other/metrics.rb +4 -8
  172. data/test/other/overrides.rb +5 -5
  173. data/test/other/relationships.rb +4 -2
  174. data/test/other/storage.rb +64 -3
  175. data/test/other/transactions.rb +20 -20
  176. data/test/parser/parser.rb +7 -4
  177. data/test/puppet/conffiles.rb +12 -12
  178. data/test/puppet/defaults.rb +13 -11
  179. data/test/puppet/utiltest.rb +14 -11
  180. data/test/puppettest.rb +156 -48
  181. data/test/server/bucket.rb +2 -2
  182. data/test/server/fileserver.rb +6 -6
  183. data/test/server/logger.rb +19 -11
  184. data/test/server/master.rb +33 -4
  185. data/test/server/server.rb +2 -7
  186. data/test/types/basic.rb +5 -7
  187. data/test/types/component.rb +22 -18
  188. data/test/types/cron.rb +111 -44
  189. data/test/types/exec.rb +116 -59
  190. data/test/types/file.rb +262 -137
  191. data/test/types/filebucket.rb +13 -15
  192. data/test/types/fileignoresource.rb +12 -16
  193. data/test/types/filesources.rb +73 -48
  194. data/test/types/filetype.rb +13 -15
  195. data/test/types/group.rb +15 -13
  196. data/test/types/host.rb +146 -0
  197. data/test/types/package.rb +74 -63
  198. data/test/types/port.rb +139 -0
  199. data/test/types/query.rb +8 -8
  200. data/test/types/schedule.rb +335 -0
  201. data/test/types/service.rb +137 -21
  202. data/test/types/sshkey.rb +140 -0
  203. data/test/types/symlink.rb +3 -5
  204. data/test/types/tidy.rb +5 -14
  205. data/test/types/type.rb +67 -11
  206. data/test/types/user.rb +25 -23
  207. metadata +186 -122
  208. data/lib/puppet/type/pfile/create.rb +0 -108
  209. data/lib/puppet/type/pprocess.rb +0 -97
  210. data/lib/puppet/type/typegen.rb +0 -149
  211. data/lib/puppet/type/typegen/filerecord.rb +0 -243
  212. data/lib/puppet/type/typegen/filetype.rb +0 -316
  213. data/test/other/state.rb +0 -106
@@ -0,0 +1,88 @@
1
+ require 'puppet/parser/ast/branch'
2
+
3
+ class Puppet::Parser::AST
4
+ # The basic container class. This object behaves almost identically
5
+ # to a normal array except at initialization time. Note that its name
6
+ # is 'AST::ASTArray', rather than plain 'AST::Array'; I had too many
7
+ # bugs when it was just 'AST::Array', because things like
8
+ # 'object.is_a?(Array)' never behaved as I expected.
9
+ class ASTArray < Branch
10
+ include Enumerable
11
+
12
+ # Return a child by index. Probably never used.
13
+ def [](index)
14
+ @children[index]
15
+ end
16
+
17
+ # Evaluate our children.
18
+ def evaluate(scope)
19
+ rets = nil
20
+ # We basically always operate declaratively, and when we
21
+ # do we need to evaluate the settor-like statements first. This
22
+ # is basically variable and type-default declarations.
23
+ if scope.declarative?
24
+ test = [
25
+ AST::VarDef, AST::TypeDefaults
26
+ ]
27
+
28
+ settors = []
29
+ others = []
30
+ @children.each { |child|
31
+ if test.include?(child.class)
32
+ settors.push child
33
+ else
34
+ others.push child
35
+ end
36
+ }
37
+ rets = [settors,others].flatten.collect { |child|
38
+ child.safeevaluate(scope)
39
+ }
40
+ else
41
+ # If we're not declarative, just do everything in order.
42
+ rets = @children.collect { |item|
43
+ item.safeevaluate(scope)
44
+ }
45
+ end
46
+
47
+ rets = rets.reject { |obj| obj.nil? }
48
+
49
+ return rets
50
+ end
51
+
52
+ def push(*ary)
53
+ ary.each { |child|
54
+ #Puppet.debug "adding %s(%s) of type %s to %s" %
55
+ # [child, child.object_id, child.class.to_s.sub(/.+::/,''),
56
+ # self.object_id]
57
+ @children.push(child)
58
+ }
59
+
60
+ return self
61
+ end
62
+
63
+ # Convert to a string. Only used for printing the parse tree.
64
+ def to_s
65
+ return "[" + @children.collect { |child|
66
+ child.to_s
67
+ }.join(", ") + "]"
68
+ end
69
+
70
+ # Print the parse tree.
71
+ def tree(indent = 0)
72
+ #puts((AST.indent * indent) + self.pin)
73
+ self.collect { |child|
74
+ child.tree(indent)
75
+ }.join("\n" + (AST.midline * (indent+1)) + "\n")
76
+ end
77
+ end
78
+
79
+ # A simple container class, containing the parameters for an object.
80
+ # Used for abstracting the grammar declarations. Basically unnecessary
81
+ # except that I kept finding bugs because I had too many arrays that
82
+ # meant completely different things.
83
+ class ObjectInst < ASTArray; end
84
+
85
+ # Another simple container class to make sure we can correctly arrayfy
86
+ # things.
87
+ class CompArgument < ASTArray; end
88
+ end
@@ -0,0 +1,47 @@
1
+ class Puppet::Parser::AST
2
+ # The parent class of all AST objects that contain other AST objects.
3
+ # Everything but the really simple objects descend from this. It is
4
+ # important to note that Branch objects contain other AST objects only --
5
+ # if you want to contain values, use a descendent of the AST::Leaf class.
6
+ class Branch < AST
7
+ include Enumerable
8
+ attr_accessor :pin, :children
9
+
10
+ # Yield each contained AST node in turn. Used mostly by 'evaluate'.
11
+ # This definition means that I don't have to override 'evaluate'
12
+ # every time, but each child of Branch will likely need to override
13
+ # this method.
14
+ def each
15
+ @children.each { |child|
16
+ yield child
17
+ }
18
+ end
19
+
20
+ # Initialize our object. Largely relies on the method from the base
21
+ # class, but also does some verification.
22
+ def initialize(arghash)
23
+ super(arghash)
24
+
25
+ # Create the hash, if it was not set at initialization time.
26
+ unless defined? @children
27
+ @children = []
28
+ end
29
+
30
+ # Verify that we only got valid AST nodes.
31
+ @children.each { |child|
32
+ unless child.is_a?(AST)
33
+ raise Puppet::DevError,
34
+ "child %s is a %s instead of ast" % [child, child.class]
35
+ end
36
+ }
37
+ end
38
+
39
+ # Pretty-print the parse tree.
40
+ def tree(indent = 0)
41
+ return ((@@indline * indent) +
42
+ self.typewrap(self.pin)) + "\n" + self.collect { |child|
43
+ child.tree(indent + 1)
44
+ }.join("\n")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,66 @@
1
+ class Puppet::Parser::AST
2
+ # Each individual option in a case statement.
3
+ class CaseOpt < AST::Branch
4
+ attr_accessor :value, :statements
5
+
6
+ # CaseOpt is a bit special -- we just want the value first,
7
+ # so that CaseStatement can compare, and then it will selectively
8
+ # decide whether to fully evaluate this option
9
+
10
+ def each
11
+ [@value,@statements].each { |child| yield child }
12
+ end
13
+
14
+ # Are we the default option?
15
+ def default?
16
+ if defined? @default
17
+ return @default
18
+ end
19
+
20
+ if @value.is_a?(AST::ASTArray)
21
+ @value.each { |subval|
22
+ if subval.is_a?(AST::Default)
23
+ @default = true
24
+ break
25
+ end
26
+ }
27
+ else
28
+ if @value.is_a?(AST::Default)
29
+ @default = true
30
+ end
31
+ end
32
+
33
+ unless defined? @default
34
+ @default = false
35
+ end
36
+
37
+ return @default
38
+ end
39
+
40
+ # You can specify a list of values; return each in turn.
41
+ def eachvalue
42
+ if @value.is_a?(AST::ASTArray)
43
+ @value.each { |subval|
44
+ yield subval.value
45
+ }
46
+ else
47
+ yield @value.value
48
+ end
49
+ end
50
+
51
+ # Evaluate the actual statements; this only gets called if
52
+ # our option matched.
53
+ def evaluate(scope)
54
+ return @statements.safeevaluate(scope.newscope)
55
+ end
56
+
57
+ def tree(indent = 0)
58
+ rettree = [
59
+ @value.tree(indent + 1),
60
+ ((@@indline * indent) + self.typewrap(self.pin)),
61
+ @statements.tree(indent + 1)
62
+ ]
63
+ return rettree.flatten.join("\n")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,78 @@
1
+ class Puppet::Parser::AST
2
+ # The basic logical structure in Puppet. Supports a list of
3
+ # tests and statement arrays.
4
+ class CaseStatement < AST::Branch
5
+ attr_accessor :test, :options, :default
6
+
7
+ # Short-curcuit evaluation. Return the value of the statements for
8
+ # the first option that matches.
9
+ def evaluate(scope)
10
+ value = @test.safeevaluate(scope)
11
+
12
+ retvalue = nil
13
+ found = false
14
+
15
+ # Iterate across the options looking for a match.
16
+ @options.each { |option|
17
+ if option.eachvalue { |opval| break true if opval == value }
18
+ # we found a matching option
19
+ retvalue = option.safeevaluate(scope)
20
+ found = true
21
+ break
22
+ end
23
+ }
24
+
25
+ # Unless we found something, look for the default.
26
+ unless found
27
+ if defined? @default
28
+ retvalue = @default.safeevaluate(scope)
29
+ else
30
+ Puppet.debug "No true answers and no default"
31
+ end
32
+ end
33
+ return retvalue
34
+ end
35
+
36
+ # Do some input validation on our options.
37
+ def initialize(hash)
38
+ values = {}
39
+
40
+ super
41
+
42
+ # This won't work if we move away from only allowing
43
+ # constants here, but for now, it's fine and useful.
44
+ @options.each { |option|
45
+ unless option.is_a?(CaseOpt)
46
+ raise Puppet::DevError, "Option is not a CaseOpt"
47
+ end
48
+ if option.default?
49
+ @default = option
50
+ end
51
+ option.eachvalue { |val|
52
+ if values.include?(val)
53
+ raise Puppet::ParseError,
54
+ "Value %s appears twice in case statement" %
55
+ val
56
+ else
57
+ values[val] = true
58
+ end
59
+ }
60
+ }
61
+ end
62
+
63
+ def tree(indent = 0)
64
+ rettree = [
65
+ @test.tree(indent + 1),
66
+ ((@@indline * indent) + self.typewrap(self.pin)),
67
+ @options.tree(indent + 1)
68
+ ]
69
+
70
+ return rettree.flatten.join("\n")
71
+ end
72
+
73
+ def each
74
+ [@test,@options].each { |child| yield child }
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,78 @@
1
+ require 'puppet/parser/ast/compdef'
2
+
3
+ class Puppet::Parser::AST
4
+ # Define a new class. Syntactically similar to component definitions,
5
+ # but classes are always singletons -- only one can exist on a given
6
+ # host.
7
+ class ClassDef < AST::CompDef
8
+ attr_accessor :parentclass
9
+
10
+ def each
11
+ if @parentclass
12
+ #[@name,@args,@parentclass,@code].each { |child| yield child }
13
+ [@name,@parentclass,@code].each { |child| yield child }
14
+ else
15
+ #[@name,@args,@code].each { |child| yield child }
16
+ [@name,@code].each { |child| yield child }
17
+ end
18
+ end
19
+
20
+ # Store our parse tree according to name.
21
+ def evaluate(scope)
22
+ name = @name.safeevaluate(scope)
23
+ #args = @args.safeevaluate(scope)
24
+
25
+ #:args => args,
26
+ arghash = {
27
+ :name => name,
28
+ :code => @code
29
+ }
30
+
31
+ if @parentclass
32
+ arghash[:parentclass] = @parentclass.safeevaluate(scope)
33
+ end
34
+
35
+ #Puppet.debug("defining hostclass '%s' with arguments [%s]" %
36
+ # [name,args])
37
+
38
+ begin
39
+ hclass = HostClass.new(arghash)
40
+ hclass.keyword = self.keyword
41
+ scope.settype(name, hclass)
42
+ rescue Puppet::ParseError => except
43
+ except.line = self.line
44
+ except.file = self.file
45
+ raise except
46
+ rescue => detail
47
+ error = Puppet::ParseError.new(detail)
48
+ error.line = self.line
49
+ error.file = self.file
50
+ error.backtrace = detail.backtrace
51
+ raise error
52
+ end
53
+ end
54
+
55
+ def initialize(hash)
56
+ @parentclass = nil
57
+ @keyword = "class"
58
+ super
59
+ end
60
+
61
+ def tree(indent = 0)
62
+ #@args.tree(indent + 1),
63
+ return [
64
+ @name.tree(indent + 1),
65
+ ((@@indline * 4 * indent) + self.typewrap("class")),
66
+ @parentclass ? @parentclass.tree(indent + 1) : "",
67
+ @code.tree(indent + 1),
68
+ ].join("\n")
69
+ end
70
+
71
+ def to_s
72
+ return "class %s(%s) inherits %s {\n%s }" %
73
+ [@name, @parentclass, @code]
74
+ #[@name, @args, @parentclass, @code]
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,111 @@
1
+ class Puppet::Parser::AST
2
+ # Define a new component. This basically just stores the
3
+ # associated parse tree by name in our current scope. Note that
4
+ # there is currently a mismatch in how we look up components -- it
5
+ # usually uses scopes, but sometimes uses '@@settypes'.
6
+ # FIXME This class should verify that each of its direct children
7
+ # has an abstractable name -- i.e., if a file does not include a
8
+ # variable in its name, then the user is essentially guaranteed to
9
+ # encounter an error if the component is instantiated more than
10
+ # once.
11
+ class CompDef < AST::Branch
12
+ attr_accessor :name, :args, :code, :keyword
13
+
14
+ def each
15
+ [@name,@args,@code].each { |child| yield child }
16
+ end
17
+
18
+ # Store the parse tree.
19
+ def evaluate(scope)
20
+ name = @name.safeevaluate(scope)
21
+ args = @args.safeevaluate(scope)
22
+
23
+ begin
24
+ comp = AST::Component.new(
25
+ :name => name,
26
+ :args => args,
27
+ :code => @code
28
+ )
29
+ comp.keyword = self.keyword
30
+ scope.settype(name, comp)
31
+ rescue Puppet::ParseError => except
32
+ except.line = self.line
33
+ except.file = self.file
34
+ raise except
35
+ rescue => detail
36
+ error = Puppet::ParseError.new(detail)
37
+ error.line = self.line
38
+ error.file = self.file
39
+ error.backtrace = detail.backtrace
40
+ raise error
41
+ end
42
+ end
43
+
44
+ def initialize(hash)
45
+ @parentclass = nil
46
+
47
+ # Set a default keyword
48
+ @keyword = "define"
49
+ super
50
+
51
+ #Puppet.debug "Defining type %s" % @name.value
52
+
53
+ # we need to both mark that a given argument is valid,
54
+ # and we need to also store any provided default arguments
55
+ # FIXME This creates a global list of types and their
56
+ # acceptable arguments. This should really be scoped
57
+ # instead.
58
+ @@settypes[@name.value] = self
59
+ end
60
+
61
+ def tree(indent = 0)
62
+ return [
63
+ @name.tree(indent + 1),
64
+ ((@@indline * 4 * indent) + self.typewrap("define")),
65
+ @args.tree(indent + 1),
66
+ @code.tree(indent + 1),
67
+ ].join("\n")
68
+ end
69
+
70
+ def to_s
71
+ return "define %s(%s) {\n%s }" % [@name, @args, @code]
72
+ end
73
+
74
+ # Check whether a given argument is valid. Searches up through
75
+ # any parent classes that might exist.
76
+ def validarg?(param)
77
+ found = false
78
+ if @args.is_a?(AST::ASTArray)
79
+ found = @args.detect { |arg|
80
+ if arg.is_a?(AST::ASTArray)
81
+ arg[0].value == param
82
+ else
83
+ arg.value == param
84
+ end
85
+ }
86
+ else
87
+ found = @args.value == param
88
+ #Puppet.warning "got arg %s" % @args.inspect
89
+ #hash[@args.value] += 1
90
+ end
91
+
92
+ if found
93
+ return true
94
+ # a nil parentclass is an empty astarray
95
+ # stupid but true
96
+ elsif @parentclass
97
+ parent = @@settypes[@parentclass.value]
98
+ if parent and parent != []
99
+ return parent.validarg?(param)
100
+ else
101
+ raise Puppet::Error, "Could not find parent class %s" %
102
+ @parentclass.value
103
+ end
104
+ else
105
+ return false
106
+ end
107
+
108
+ end
109
+ end
110
+
111
+ end