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.
- data/CHANGELOG +58 -0
- data/README +21 -18
- data/Rakefile +176 -36
- data/bin/puppet +34 -48
- data/bin/puppetca +41 -28
- data/bin/puppetd +87 -65
- data/bin/puppetdoc +99 -23
- data/bin/puppetmasterd +72 -91
- data/conf/redhat/client.init +80 -0
- data/conf/redhat/client.sysconfig +11 -0
- data/conf/redhat/fileserver.conf +12 -0
- data/conf/redhat/puppet.spec +130 -0
- data/conf/redhat/server.init +89 -0
- data/conf/redhat/server.sysconfig +9 -0
- data/examples/code/allatonce +2 -2
- data/examples/code/assignments +1 -1
- data/examples/code/classing +2 -2
- data/examples/code/components +2 -2
- data/examples/code/file.bl +5 -5
- data/examples/code/filedefaults +2 -2
- data/examples/code/fileparsing +1 -1
- data/examples/code/filerecursion +1 -1
- data/examples/code/functions +1 -1
- data/examples/code/groups +1 -1
- data/examples/code/importing +1 -1
- data/examples/code/nodes +1 -1
- data/examples/code/one +1 -1
- data/examples/code/relationships +2 -2
- data/examples/code/simpletests +5 -5
- data/examples/code/snippets/argumentdefaults +2 -2
- data/examples/code/snippets/casestatement +16 -8
- data/examples/code/snippets/classheirarchy.pp +4 -4
- data/examples/code/snippets/classincludes.pp +4 -4
- data/examples/code/snippets/classpathtest +2 -2
- data/examples/code/snippets/componentmetaparams.pp +11 -0
- data/examples/code/snippets/dirchmod +5 -5
- data/examples/code/snippets/emptyclass.pp +9 -0
- data/examples/code/snippets/failmissingexecpath.pp +1 -1
- data/examples/code/snippets/falsevalues.pp +1 -1
- data/examples/code/snippets/filecreate +5 -5
- data/examples/code/snippets/implicititeration +5 -5
- data/examples/code/snippets/multipleinstances +4 -4
- data/examples/code/snippets/namevartest +3 -3
- data/examples/code/snippets/scopetest +1 -1
- data/examples/code/snippets/selectorvalues.pp +3 -3
- data/examples/code/snippets/simpledefaults +2 -2
- data/examples/code/snippets/simpleselector +5 -5
- data/examples/code/snippets/singleary.pp +19 -0
- data/examples/root/etc/init.d/sleeper +3 -2
- data/ext/emacs/puppet-mode-init.el +6 -0
- data/ext/emacs/puppet-mode.el +189 -0
- data/ext/ldap/puppet.schema +17 -0
- data/ext/{module:puppet → module_puppet} +30 -31
- data/ext/vim/filetype.vim +9 -0
- data/ext/vim/puppet.vim +87 -0
- data/install.rb +63 -30
- data/lib/puppet.rb +216 -122
- data/lib/puppet/client.rb +51 -416
- data/lib/puppet/client/ca.rb +17 -0
- data/lib/puppet/client/dipper.rb +78 -0
- data/lib/puppet/client/file.rb +20 -0
- data/lib/puppet/client/log.rb +17 -0
- data/lib/puppet/client/master.rb +246 -0
- data/lib/puppet/client/proxy.rb +27 -0
- data/lib/puppet/client/status.rb +7 -0
- data/lib/puppet/config.rb +563 -13
- data/lib/puppet/daemon.rb +50 -22
- data/lib/puppet/element.rb +4 -4
- data/lib/puppet/event-loop.rb +1 -0
- data/lib/puppet/event-loop/better-definers.rb +367 -0
- data/lib/puppet/event-loop/event-loop.rb +355 -0
- data/lib/puppet/event-loop/signal-system.rb +220 -0
- data/lib/puppet/event.rb +9 -11
- data/lib/puppet/filetype.rb +195 -0
- data/lib/puppet/log.rb +35 -12
- data/lib/puppet/metric.rb +2 -2
- data/lib/puppet/networkclient.rb +145 -0
- data/lib/puppet/parameter.rb +335 -0
- data/lib/puppet/parser/ast.rb +42 -1453
- data/lib/puppet/parser/ast/astarray.rb +88 -0
- data/lib/puppet/parser/ast/branch.rb +47 -0
- data/lib/puppet/parser/ast/caseopt.rb +66 -0
- data/lib/puppet/parser/ast/casestatement.rb +78 -0
- data/lib/puppet/parser/ast/classdef.rb +78 -0
- data/lib/puppet/parser/ast/compdef.rb +111 -0
- data/lib/puppet/parser/ast/component.rb +105 -0
- data/lib/puppet/parser/ast/hostclass.rb +82 -0
- data/lib/puppet/parser/ast/leaf.rb +86 -0
- data/lib/puppet/parser/ast/node.rb +103 -0
- data/lib/puppet/parser/ast/nodedef.rb +68 -0
- data/lib/puppet/parser/ast/objectdef.rb +336 -0
- data/lib/puppet/parser/ast/objectparam.rb +30 -0
- data/lib/puppet/parser/ast/objectref.rb +76 -0
- data/lib/puppet/parser/ast/selector.rb +60 -0
- data/lib/puppet/parser/ast/typedefaults.rb +45 -0
- data/lib/puppet/parser/ast/vardef.rb +44 -0
- data/lib/puppet/parser/interpreter.rb +31 -14
- data/lib/puppet/parser/lexer.rb +2 -4
- data/lib/puppet/parser/parser.rb +332 -242
- data/lib/puppet/parser/scope.rb +55 -38
- data/lib/puppet/server.rb +43 -44
- data/lib/puppet/server/authstore.rb +3 -6
- data/lib/puppet/server/ca.rb +5 -2
- data/lib/puppet/server/filebucket.rb +2 -4
- data/lib/puppet/server/fileserver.rb +28 -12
- data/lib/puppet/server/logger.rb +15 -4
- data/lib/puppet/server/master.rb +62 -7
- data/lib/puppet/sslcertificates.rb +41 -607
- data/lib/puppet/sslcertificates/ca.rb +291 -0
- data/lib/puppet/sslcertificates/certificate.rb +283 -0
- data/lib/puppet/statechange.rb +6 -1
- data/lib/puppet/storage.rb +67 -56
- data/lib/puppet/transaction.rb +25 -9
- data/lib/puppet/transportable.rb +102 -22
- data/lib/puppet/type.rb +1096 -315
- data/lib/puppet/type/component.rb +30 -21
- data/lib/puppet/type/cron.rb +409 -448
- data/lib/puppet/type/exec.rb +234 -174
- data/lib/puppet/type/group.rb +65 -82
- data/lib/puppet/type/nameservice.rb +247 -3
- data/lib/puppet/type/nameservice/netinfo.rb +29 -40
- data/lib/puppet/type/nameservice/objectadd.rb +52 -66
- data/lib/puppet/type/nameservice/posix.rb +6 -194
- data/lib/puppet/type/package.rb +447 -295
- data/lib/puppet/type/package/apt.rb +51 -50
- data/lib/puppet/type/package/bsd.rb +82 -0
- data/lib/puppet/type/package/dpkg.rb +85 -88
- data/lib/puppet/type/package/rpm.rb +67 -63
- data/lib/puppet/type/package/sun.rb +119 -98
- data/lib/puppet/type/package/yum.rb +41 -37
- data/lib/puppet/type/parsedtype.rb +295 -0
- data/lib/puppet/type/parsedtype/host.rb +143 -0
- data/lib/puppet/type/parsedtype/port.rb +232 -0
- data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
- data/lib/puppet/type/pfile.rb +484 -460
- data/lib/puppet/type/pfile/checksum.rb +237 -181
- data/lib/puppet/type/pfile/content.rb +67 -0
- data/lib/puppet/type/pfile/ensure.rb +212 -0
- data/lib/puppet/type/pfile/group.rb +106 -105
- data/lib/puppet/type/pfile/mode.rb +98 -101
- data/lib/puppet/type/pfile/source.rb +228 -209
- data/lib/puppet/type/pfile/type.rb +18 -21
- data/lib/puppet/type/pfile/uid.rb +127 -130
- data/lib/puppet/type/pfilebucket.rb +68 -63
- data/lib/puppet/type/schedule.rb +341 -0
- data/lib/puppet/type/service.rb +351 -255
- data/lib/puppet/type/service/base.rb +9 -14
- data/lib/puppet/type/service/debian.rb +32 -38
- data/lib/puppet/type/service/init.rb +130 -130
- data/lib/puppet/type/service/smf.rb +48 -20
- data/lib/puppet/type/state.rb +229 -16
- data/lib/puppet/type/symlink.rb +51 -63
- data/lib/puppet/type/tidy.rb +105 -102
- data/lib/puppet/type/user.rb +118 -180
- data/lib/puppet/util.rb +100 -6
- data/test/certmgr/certmgr.rb +0 -1
- data/test/client/client.rb +4 -4
- data/test/executables/puppetbin.rb +7 -14
- data/test/executables/puppetca.rb +18 -24
- data/test/executables/puppetd.rb +7 -16
- data/test/executables/puppetmasterd.rb +7 -9
- data/test/executables/puppetmodule.rb +11 -16
- data/test/language/ast.rb +11 -7
- data/test/language/interpreter.rb +1 -1
- data/test/language/scope.rb +2 -0
- data/test/language/snippets.rb +30 -5
- data/test/language/transportable.rb +77 -0
- data/test/other/config.rb +316 -0
- data/test/other/events.rb +22 -21
- data/test/other/log.rb +14 -14
- data/test/other/metrics.rb +4 -8
- data/test/other/overrides.rb +5 -5
- data/test/other/relationships.rb +4 -2
- data/test/other/storage.rb +64 -3
- data/test/other/transactions.rb +20 -20
- data/test/parser/parser.rb +7 -4
- data/test/puppet/conffiles.rb +12 -12
- data/test/puppet/defaults.rb +13 -11
- data/test/puppet/utiltest.rb +14 -11
- data/test/puppettest.rb +156 -48
- data/test/server/bucket.rb +2 -2
- data/test/server/fileserver.rb +6 -6
- data/test/server/logger.rb +19 -11
- data/test/server/master.rb +33 -4
- data/test/server/server.rb +2 -7
- data/test/types/basic.rb +5 -7
- data/test/types/component.rb +22 -18
- data/test/types/cron.rb +111 -44
- data/test/types/exec.rb +116 -59
- data/test/types/file.rb +262 -137
- data/test/types/filebucket.rb +13 -15
- data/test/types/fileignoresource.rb +12 -16
- data/test/types/filesources.rb +73 -48
- data/test/types/filetype.rb +13 -15
- data/test/types/group.rb +15 -13
- data/test/types/host.rb +146 -0
- data/test/types/package.rb +74 -63
- data/test/types/port.rb +139 -0
- data/test/types/query.rb +8 -8
- data/test/types/schedule.rb +335 -0
- data/test/types/service.rb +137 -21
- data/test/types/sshkey.rb +140 -0
- data/test/types/symlink.rb +3 -5
- data/test/types/tidy.rb +5 -14
- data/test/types/type.rb +67 -11
- data/test/types/user.rb +25 -23
- metadata +186 -122
- data/lib/puppet/type/pfile/create.rb +0 -108
- data/lib/puppet/type/pprocess.rb +0 -97
- data/lib/puppet/type/typegen.rb +0 -149
- data/lib/puppet/type/typegen/filerecord.rb +0 -243
- data/lib/puppet/type/typegen/filetype.rb +0 -316
- data/test/other/state.rb +0 -106
data/lib/puppet/statechange.rb
CHANGED
@@ -37,6 +37,8 @@ module Puppet
|
|
37
37
|
return nil
|
38
38
|
end
|
39
39
|
|
40
|
+
#@state.info "Is: %s, Should: %s" % [@state.is.inspect, @state.should.inspect]
|
41
|
+
|
40
42
|
begin
|
41
43
|
events = @state.sync
|
42
44
|
if events.nil?
|
@@ -75,6 +77,9 @@ module Puppet
|
|
75
77
|
}
|
76
78
|
rescue => detail
|
77
79
|
#@state.err "%s failed: %s" % [self.to_s,detail]
|
80
|
+
if Puppet[:debug]
|
81
|
+
puts detail.backtrace
|
82
|
+
end
|
78
83
|
raise
|
79
84
|
# there should be a way to ask the state what type of event
|
80
85
|
# it would have generated, but...
|
@@ -147,4 +152,4 @@ module Puppet
|
|
147
152
|
end
|
148
153
|
end
|
149
154
|
|
150
|
-
# $Id: statechange.rb
|
155
|
+
# $Id: statechange.rb 831 2006-01-16 20:01:20Z luke $
|
data/lib/puppet/storage.rb
CHANGED
@@ -1,95 +1,106 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Puppet
|
2
4
|
# a class for storing state
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
class Storage
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.class.load
|
10
|
+
end
|
11
|
+
|
12
|
+
# Return a hash that will be stored to disk. It's worth noting
|
13
|
+
# here that we use the object's full path, not just the name/type
|
14
|
+
# combination. At the least, this is useful for those non-isomorphic
|
15
|
+
# types like exec, but it also means that if an object changes locations
|
16
|
+
# in the configuration it will lose its cache.
|
17
|
+
def self.cache(object)
|
18
|
+
unless object.is_a? Puppet::Type
|
19
|
+
raise Puppet::DevFail, "Must pass a Type instance to Storage.cache"
|
20
|
+
end
|
21
|
+
return @@state[object.path] ||= {}
|
22
|
+
end
|
9
23
|
|
10
24
|
def self.clear
|
11
|
-
@@state
|
25
|
+
@@state.clear
|
12
26
|
Storage.init
|
13
27
|
end
|
14
28
|
|
15
29
|
def self.init
|
16
30
|
Puppet.debug "Initializing Storage"
|
17
|
-
@@state =
|
18
|
-
hash[key] = Hash.new(nil)
|
19
|
-
}
|
31
|
+
@@state = {}
|
20
32
|
@@splitchar = "\t"
|
21
33
|
end
|
22
34
|
|
23
35
|
self.init
|
24
36
|
|
25
|
-
|
26
|
-
if Puppet[:
|
37
|
+
def self.load
|
38
|
+
if Puppet[:statefile].nil?
|
27
39
|
raise Puppet::DevError, "Somehow the statefile is nil"
|
28
40
|
end
|
29
41
|
|
30
|
-
|
31
|
-
Puppet.info "Statefile %s does not exist" % Puppet[:
|
42
|
+
unless File.exists?(Puppet[:statefile])
|
43
|
+
Puppet.info "Statefile %s does not exist" % Puppet[:statefile]
|
44
|
+
unless defined? @@state and ! @@state.nil?
|
45
|
+
self.init
|
46
|
+
end
|
32
47
|
return
|
33
48
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
49
|
+
#Puppet.debug "Loading statefile %s" % Puppet[:statefile]
|
50
|
+
Puppet::Util.lock(Puppet[:statefile]) { |file|
|
51
|
+
#@@state = Marshal.load(file)
|
52
|
+
begin
|
53
|
+
@@state = YAML.load(file)
|
54
|
+
rescue => detail
|
55
|
+
Puppet.err "Checksumfile %s is corrupt (%s); replacing" %
|
56
|
+
[Puppet[:statefile], detail]
|
40
57
|
begin
|
41
|
-
|
42
|
-
|
58
|
+
File.rename(Puppet[:statefile],
|
59
|
+
Puppet[:statefile] + ".bad")
|
60
|
+
rescue
|
43
61
|
raise Puppet::Error,
|
44
|
-
"
|
45
|
-
|
46
|
-
], caller
|
62
|
+
"Could not rename corrupt %s; remove manually" %
|
63
|
+
Puppet[:statefile]
|
47
64
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
65
|
+
end
|
66
|
+
}
|
67
|
+
|
68
|
+
unless @@state.is_a?(Hash)
|
69
|
+
Puppet.err "State got corrupted"
|
70
|
+
self.init
|
52
71
|
end
|
53
72
|
|
54
73
|
#Puppet.debug "Loaded state is %s" % @@state.inspect
|
55
|
-
|
74
|
+
end
|
56
75
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
result = @@state[myclass]
|
62
|
-
return result
|
63
|
-
end
|
76
|
+
def self.stateinspect
|
77
|
+
@@state.inspect
|
78
|
+
end
|
64
79
|
|
65
|
-
|
66
|
-
|
80
|
+
def self.store
|
81
|
+
Puppet.debug "Storing state"
|
82
|
+
unless FileTest.directory?(File.dirname(Puppet[:statefile]))
|
67
83
|
begin
|
68
|
-
Puppet.recmkdir(File.dirname(Puppet[:
|
84
|
+
Puppet.recmkdir(File.dirname(Puppet[:statefile]))
|
69
85
|
Puppet.info "Creating state directory %s" %
|
70
|
-
File.dirname(Puppet[:
|
86
|
+
File.dirname(Puppet[:statefile])
|
71
87
|
rescue => detail
|
72
88
|
Puppet.err "Could not create state file: %s" % detail
|
73
89
|
return
|
74
90
|
end
|
75
91
|
end
|
76
92
|
|
77
|
-
unless FileTest.exist?(Puppet[:
|
78
|
-
Puppet.info "Creating state file %s" % Puppet[:
|
93
|
+
unless FileTest.exist?(Puppet[:statefile])
|
94
|
+
Puppet.info "Creating state file %s" % Puppet[:statefile]
|
79
95
|
end
|
80
96
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
#Puppet.debug "Stored state is %s" % @@state.inspect
|
91
|
-
end
|
92
|
-
end
|
97
|
+
Puppet::Util.lock(
|
98
|
+
Puppet[:statefile], "w", 0600
|
99
|
+
) { |file|
|
100
|
+
file.print YAML.dump(@@state)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
93
104
|
end
|
94
105
|
|
95
|
-
# $Id: storage.rb
|
106
|
+
# $Id: storage.rb 848 2006-01-24 06:01:58Z luke $
|
data/lib/puppet/transaction.rb
CHANGED
@@ -41,8 +41,10 @@ class Transaction
|
|
41
41
|
# then, we need to pass the event to the object's containing component,
|
42
42
|
# to see if it or any of its parents have subscriptions on the event
|
43
43
|
def evaluate
|
44
|
-
Puppet.debug "
|
44
|
+
Puppet.debug "Beginning transaction %s with %s changes" %
|
45
|
+
[self.object_id, @changes.length]
|
45
46
|
|
47
|
+
now = Time.now
|
46
48
|
events = @changes.collect { |change|
|
47
49
|
if change.is_a?(Puppet::StateChange)
|
48
50
|
change.transaction = self
|
@@ -53,9 +55,11 @@ class Transaction
|
|
53
55
|
events = [change.forward].flatten.reject { |e| e.nil? }
|
54
56
|
#@@changed.push change.state.parent
|
55
57
|
rescue => detail
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
change.state.err "change from %s to %s failed: %s" %
|
59
|
+
[change.state.is_to_s, change.state.should_to_s, detail]
|
60
|
+
#Puppet.err("%s failed: %s" % [change.to_s,detail])
|
61
|
+
if Puppet[:debug]
|
62
|
+
puts detail.backtrace
|
59
63
|
end
|
60
64
|
next
|
61
65
|
# FIXME this should support using onerror to determine
|
@@ -63,13 +67,19 @@ class Transaction
|
|
63
67
|
# should do so
|
64
68
|
end
|
65
69
|
|
70
|
+
# This is kinda lame, because it can result in the same
|
71
|
+
# object being modified multiple times, but that's difficult
|
72
|
+
# to avoid as long as we're syncing each state individually.
|
73
|
+
change.state.parent.cache(:synced, now)
|
74
|
+
|
66
75
|
unless events.nil? or (events.is_a?(Array) and events.empty?)
|
67
76
|
change.changed = true
|
68
77
|
end
|
69
78
|
events
|
70
79
|
else
|
80
|
+
puts caller
|
71
81
|
raise Puppet::DevError,
|
72
|
-
"Transactions cannot handle objects of type %s" %
|
82
|
+
"Transactions cannot handle objects of type %s" % change.class
|
73
83
|
end
|
74
84
|
}.flatten.reject { |event|
|
75
85
|
event.nil?
|
@@ -104,10 +114,15 @@ class Transaction
|
|
104
114
|
end
|
105
115
|
# change collection is in-band, and message generation is out-of-band
|
106
116
|
# of course, exception raising is also out-of-band
|
107
|
-
|
117
|
+
now = Time.now.to_i
|
118
|
+
@changes = @objects.find_all { |child|
|
119
|
+
child.scheduled?
|
120
|
+
}.collect { |child|
|
108
121
|
# these children are all Puppet::Type instances
|
109
122
|
# not all of the children will return a change, and Containers
|
110
123
|
# return transactions
|
124
|
+
#ary = child.evaluate
|
125
|
+
#ary
|
111
126
|
child.evaluate
|
112
127
|
}.flatten.reject { |child|
|
113
128
|
child.nil? # remove empties
|
@@ -130,6 +145,9 @@ class Transaction
|
|
130
145
|
#@@changed.push change.state.parent
|
131
146
|
rescue => detail
|
132
147
|
Puppet.err("%s rollback failed: %s" % [change,detail])
|
148
|
+
if Puppet[:debug]
|
149
|
+
puts detail.backtrace
|
150
|
+
end
|
133
151
|
next
|
134
152
|
# at this point, we would normally do error handling
|
135
153
|
# but i haven't decided what to do for that yet
|
@@ -160,7 +178,6 @@ class Transaction
|
|
160
178
|
|
161
179
|
#---------------------------------------------------------------
|
162
180
|
def triggered(object, method)
|
163
|
-
Puppet.notice "Triggered %s" % method
|
164
181
|
@triggered[object][method] += 1
|
165
182
|
#@triggerevents << ("%s_%sed" % [object.class.name.to_s, method.to_s]).intern
|
166
183
|
end
|
@@ -168,7 +185,6 @@ class Transaction
|
|
168
185
|
|
169
186
|
#---------------------------------------------------------------
|
170
187
|
def triggered?(object, method)
|
171
|
-
Puppet.notice "Looking for triggered %s" % method
|
172
188
|
@triggered[object][method]
|
173
189
|
end
|
174
190
|
#---------------------------------------------------------------
|
@@ -176,4 +192,4 @@ end
|
|
176
192
|
end
|
177
193
|
#---------------------------------------------------------------
|
178
194
|
|
179
|
-
# $Id: transaction.rb
|
195
|
+
# $Id: transaction.rb 858 2006-01-30 19:22:25Z luke $
|
data/lib/puppet/transportable.rb
CHANGED
@@ -1,18 +1,33 @@
|
|
1
1
|
require 'puppet'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
module Puppet
|
4
5
|
# The transportable objects themselves. Basically just a hash with some
|
5
|
-
# metadata and a few extra methods.
|
6
|
-
|
6
|
+
# metadata and a few extra methods. I used to have the object actually
|
7
|
+
# be a subclass of Hash, but I could never correctly dump them using
|
8
|
+
# YAML.
|
9
|
+
class TransObject
|
10
|
+
include Enumerable
|
7
11
|
attr_accessor :type, :name, :file, :line
|
8
12
|
|
9
13
|
attr_writer :tags
|
10
14
|
|
15
|
+
%w{has_key? include? length delete empty? << [] []=}.each { |method|
|
16
|
+
define_method(method) do |*args|
|
17
|
+
@params.send(method, *args)
|
18
|
+
end
|
19
|
+
}
|
20
|
+
|
21
|
+
def each
|
22
|
+
@params.each { |p,v| yield p, v }
|
23
|
+
end
|
24
|
+
|
11
25
|
def initialize(name,type)
|
12
|
-
self[:name] = name
|
13
26
|
@type = type
|
14
27
|
@name = name
|
28
|
+
@params = {"name" => name}
|
15
29
|
#self.class.add(self)
|
30
|
+
@tags = []
|
16
31
|
end
|
17
32
|
|
18
33
|
def longname
|
@@ -23,45 +38,79 @@ module Puppet
|
|
23
38
|
return @tags
|
24
39
|
end
|
25
40
|
|
41
|
+
def to_hash
|
42
|
+
@params.dup
|
43
|
+
end
|
44
|
+
|
26
45
|
def to_s
|
27
46
|
return "%s(%s) => %s" % [@type,self[:name],super]
|
28
47
|
end
|
29
48
|
|
49
|
+
def to_manifest
|
50
|
+
"#{self.type.to_s} { \"#{self.name}\":\n%s\n}" % @params.collect { |p, v|
|
51
|
+
" #{p} => \"#{v}\""
|
52
|
+
}.join(",\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_yaml_properties
|
56
|
+
instance_variables
|
57
|
+
#%w{ @type @name @file @line @tags }.find_all { |v|
|
58
|
+
#}
|
59
|
+
end
|
60
|
+
|
30
61
|
def to_type(parent = nil)
|
31
|
-
if parent
|
32
|
-
self[:parent] = parent
|
33
|
-
end
|
34
62
|
retobj = nil
|
35
63
|
if type = Puppet::Type.type(self.type)
|
36
64
|
unless retobj = type.create(self)
|
65
|
+
#Puppet.notice "Could not create %s[%s]" %
|
66
|
+
# [self.type, self.name]
|
37
67
|
return nil
|
38
68
|
end
|
39
|
-
retobj.file = @file
|
40
|
-
retobj.line = @line
|
69
|
+
#retobj.file = @file
|
70
|
+
#retobj.line = @line
|
41
71
|
else
|
42
72
|
raise Puppet::Error.new("Could not find object type %s" % self.type)
|
43
73
|
end
|
44
74
|
|
45
|
-
if defined? @tags and @tags
|
46
|
-
|
47
|
-
|
48
|
-
end
|
75
|
+
#if defined? @tags and @tags
|
76
|
+
# #Puppet.debug "%s(%s) tags: %s" % [@type, @name, @tags.join(" ")]
|
77
|
+
# retobj.tags = @tags
|
78
|
+
#end
|
49
79
|
|
50
80
|
if parent
|
81
|
+
self[:parent] = parent
|
51
82
|
parent.push retobj
|
52
83
|
end
|
53
84
|
|
54
85
|
return retobj
|
55
86
|
end
|
56
87
|
end
|
57
|
-
#------------------------------------------------------------
|
58
88
|
|
59
|
-
|
60
|
-
#
|
61
|
-
class TransBucket
|
62
|
-
|
89
|
+
# Just a linear container for objects. Behaves mostly like an array, except
|
90
|
+
# that YAML will correctly dump them even with their instance variables.
|
91
|
+
class TransBucket
|
92
|
+
include Enumerable
|
93
|
+
|
94
|
+
attr_accessor :name, :type, :file, :line, :classes, :autoname, :keyword, :top
|
95
|
+
|
96
|
+
%w{delete shift include? length empty? << []}.each { |method|
|
97
|
+
define_method(method) do |*args|
|
98
|
+
#Puppet.warning "Calling %s with %s" % [method, args.inspect]
|
99
|
+
@children.send(method, *args)
|
100
|
+
#Puppet.warning @params.inspect
|
101
|
+
end
|
102
|
+
}
|
103
|
+
|
104
|
+
def each
|
105
|
+
@children.each { |c| yield c }
|
106
|
+
end
|
107
|
+
|
108
|
+
def initialize
|
109
|
+
@children = []
|
110
|
+
end
|
63
111
|
|
64
112
|
def push(*args)
|
113
|
+
#Puppet.warning "calling push"
|
65
114
|
args.each { |arg|
|
66
115
|
case arg
|
67
116
|
when Puppet::TransBucket, Puppet::TransObject
|
@@ -72,7 +121,37 @@ module Puppet
|
|
72
121
|
arg.class
|
73
122
|
end
|
74
123
|
}
|
75
|
-
|
124
|
+
@children += args
|
125
|
+
#Puppet.warning @children.inspect
|
126
|
+
end
|
127
|
+
|
128
|
+
# Convert to a parseable manifest
|
129
|
+
def to_manifest
|
130
|
+
unless self.top
|
131
|
+
unless defined? @keyword and @keyword
|
132
|
+
raise Puppet::DevError, "No keyword; cannot convert to manifest"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
str = nil
|
137
|
+
if self.top
|
138
|
+
str = "%s"
|
139
|
+
else
|
140
|
+
str = "#{@keyword} #{@type} {\n%s\n}"
|
141
|
+
end
|
142
|
+
str % @children.collect { |child|
|
143
|
+
child.to_manifest
|
144
|
+
}.collect { |str|
|
145
|
+
if self.top
|
146
|
+
str
|
147
|
+
else
|
148
|
+
str.gsub(/^/, " ") # indent everything once
|
149
|
+
end
|
150
|
+
}.join("\n\n") # and throw in a blank line
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_yaml_properties
|
154
|
+
instance_variables
|
76
155
|
end
|
77
156
|
|
78
157
|
def to_type(parent = nil)
|
@@ -96,13 +175,14 @@ module Puppet
|
|
96
175
|
hash[param] = value
|
97
176
|
}
|
98
177
|
else
|
99
|
-
Puppet.debug "%s[%s] has no parameters" % [@type, @name]
|
178
|
+
#Puppet.debug "%s[%s] has no parameters" % [@type, @name]
|
100
179
|
end
|
101
180
|
|
102
181
|
if parent
|
103
182
|
hash[:parent] = parent
|
104
183
|
end
|
105
|
-
container = Puppet
|
184
|
+
container = Puppet.type(:component).create(hash)
|
185
|
+
#Puppet.info container.inspect
|
106
186
|
|
107
187
|
if parent
|
108
188
|
parent.push container
|
@@ -128,7 +208,7 @@ module Puppet
|
|
128
208
|
# Now just call to_type on them with the container as a parent
|
129
209
|
unless obj = child.to_type(container)
|
130
210
|
# nothing; we assume the method already warned
|
131
|
-
Puppet.warning "Could not create child %s" % child.name
|
211
|
+
#Puppet.warning "Could not create child %s" % child.name
|
132
212
|
end
|
133
213
|
}
|
134
214
|
|
@@ -148,4 +228,4 @@ module Puppet
|
|
148
228
|
#------------------------------------------------------------
|
149
229
|
end
|
150
230
|
|
151
|
-
# $Id: transportable.rb
|
231
|
+
# $Id: transportable.rb 873 2006-02-07 23:12:33Z luke $
|