puppet 0.9.2
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 +0 -0
- data/COPYING +340 -0
- data/LICENSE +17 -0
- data/README +24 -0
- data/Rakefile +294 -0
- data/TODO +4 -0
- data/bin/cf2puppet +186 -0
- data/bin/puppet +176 -0
- data/bin/puppetca +213 -0
- data/bin/puppetd +246 -0
- data/bin/puppetdoc +184 -0
- data/bin/puppetmasterd +258 -0
- data/examples/code/allatonce +13 -0
- data/examples/code/assignments +11 -0
- data/examples/code/classing +35 -0
- data/examples/code/components +73 -0
- data/examples/code/execs +16 -0
- data/examples/code/failers/badclassnoparam +10 -0
- data/examples/code/failers/badclassparam +10 -0
- data/examples/code/failers/badcompnoparam +9 -0
- data/examples/code/failers/badcompparam +9 -0
- data/examples/code/failers/badtypeparam +3 -0
- data/examples/code/file.bl +11 -0
- data/examples/code/filedefaults +10 -0
- data/examples/code/fileparsing +116 -0
- data/examples/code/filerecursion +15 -0
- data/examples/code/functions +3 -0
- data/examples/code/groups +7 -0
- data/examples/code/head +30 -0
- data/examples/code/importing +8 -0
- data/examples/code/nodes +20 -0
- data/examples/code/one +8 -0
- data/examples/code/relationships +34 -0
- data/examples/code/selectors +28 -0
- data/examples/code/simpletests +11 -0
- data/examples/code/snippets/argumentdefaults +14 -0
- data/examples/code/snippets/casestatement +39 -0
- data/examples/code/snippets/classheirarchy.pp +15 -0
- data/examples/code/snippets/classincludes.pp +17 -0
- data/examples/code/snippets/classpathtest +11 -0
- data/examples/code/snippets/dirchmod +19 -0
- data/examples/code/snippets/failmissingexecpath.pp +13 -0
- data/examples/code/snippets/falsevalues.pp +3 -0
- data/examples/code/snippets/filecreate +11 -0
- data/examples/code/snippets/implicititeration +15 -0
- data/examples/code/snippets/multipleinstances +7 -0
- data/examples/code/snippets/namevartest +9 -0
- data/examples/code/snippets/scopetest +13 -0
- data/examples/code/snippets/selectorvalues.pp +22 -0
- data/examples/code/snippets/simpledefaults +5 -0
- data/examples/code/snippets/simpleselector +38 -0
- data/examples/code/svncommit +13 -0
- data/examples/root/bin/sleeper +69 -0
- data/examples/root/etc/configfile +0 -0
- data/examples/root/etc/debian-passwd +29 -0
- data/examples/root/etc/debian-syslog.conf +71 -0
- data/examples/root/etc/init.d/sleeper +65 -0
- data/examples/root/etc/otherfile +0 -0
- data/examples/root/etc/puppet/fileserver.conf +3 -0
- data/examples/root/etc/puppet/puppetmasterd.conf +10 -0
- data/ext/module:puppet +195 -0
- data/install.rb +270 -0
- data/lib/puppet.rb +249 -0
- data/lib/puppet/base64.rb +19 -0
- data/lib/puppet/client.rb +519 -0
- data/lib/puppet/config.rb +49 -0
- data/lib/puppet/daemon.rb +208 -0
- data/lib/puppet/element.rb +71 -0
- data/lib/puppet/event.rb +259 -0
- data/lib/puppet/log.rb +321 -0
- data/lib/puppet/metric.rb +250 -0
- data/lib/puppet/parsedfile.rb +38 -0
- data/lib/puppet/parser/ast.rb +1560 -0
- data/lib/puppet/parser/interpreter.rb +150 -0
- data/lib/puppet/parser/lexer.rb +226 -0
- data/lib/puppet/parser/parser.rb +1354 -0
- data/lib/puppet/parser/scope.rb +755 -0
- data/lib/puppet/server.rb +170 -0
- data/lib/puppet/server/authstore.rb +227 -0
- data/lib/puppet/server/ca.rb +140 -0
- data/lib/puppet/server/filebucket.rb +147 -0
- data/lib/puppet/server/fileserver.rb +477 -0
- data/lib/puppet/server/logger.rb +43 -0
- data/lib/puppet/server/master.rb +103 -0
- data/lib/puppet/server/servlet.rb +247 -0
- data/lib/puppet/sslcertificates.rb +737 -0
- data/lib/puppet/statechange.rb +150 -0
- data/lib/puppet/storage.rb +95 -0
- data/lib/puppet/transaction.rb +179 -0
- data/lib/puppet/transportable.rb +151 -0
- data/lib/puppet/type.rb +1354 -0
- data/lib/puppet/type/component.rb +141 -0
- data/lib/puppet/type/cron.rb +543 -0
- data/lib/puppet/type/exec.rb +316 -0
- data/lib/puppet/type/group.rb +152 -0
- data/lib/puppet/type/nameservice.rb +3 -0
- data/lib/puppet/type/nameservice/netinfo.rb +173 -0
- data/lib/puppet/type/nameservice/objectadd.rb +146 -0
- data/lib/puppet/type/nameservice/posix.rb +200 -0
- data/lib/puppet/type/package.rb +420 -0
- data/lib/puppet/type/package/apt.rb +70 -0
- data/lib/puppet/type/package/dpkg.rb +108 -0
- data/lib/puppet/type/package/rpm.rb +81 -0
- data/lib/puppet/type/package/sun.rb +117 -0
- data/lib/puppet/type/package/yum.rb +58 -0
- data/lib/puppet/type/pfile.rb +569 -0
- data/lib/puppet/type/pfile/checksum.rb +219 -0
- data/lib/puppet/type/pfile/create.rb +108 -0
- data/lib/puppet/type/pfile/group.rb +129 -0
- data/lib/puppet/type/pfile/mode.rb +131 -0
- data/lib/puppet/type/pfile/source.rb +264 -0
- data/lib/puppet/type/pfile/type.rb +31 -0
- data/lib/puppet/type/pfile/uid.rb +166 -0
- data/lib/puppet/type/pfilebucket.rb +80 -0
- data/lib/puppet/type/pprocess.rb +97 -0
- data/lib/puppet/type/service.rb +347 -0
- data/lib/puppet/type/service/base.rb +17 -0
- data/lib/puppet/type/service/debian.rb +50 -0
- data/lib/puppet/type/service/init.rb +145 -0
- data/lib/puppet/type/service/smf.rb +29 -0
- data/lib/puppet/type/state.rb +182 -0
- data/lib/puppet/type/symlink.rb +183 -0
- data/lib/puppet/type/tidy.rb +183 -0
- data/lib/puppet/type/typegen.rb +149 -0
- data/lib/puppet/type/typegen/filerecord.rb +243 -0
- data/lib/puppet/type/typegen/filetype.rb +316 -0
- data/lib/puppet/type/user.rb +290 -0
- data/lib/puppet/util.rb +138 -0
- data/test/certmgr/certmgr.rb +265 -0
- data/test/client/client.rb +203 -0
- data/test/executables/puppetbin.rb +53 -0
- data/test/executables/puppetca.rb +79 -0
- data/test/executables/puppetd.rb +71 -0
- data/test/executables/puppetmasterd.rb +153 -0
- data/test/executables/puppetmodule.rb +60 -0
- data/test/language/ast.rb +412 -0
- data/test/language/interpreter.rb +71 -0
- data/test/language/scope.rb +412 -0
- data/test/language/snippets.rb +445 -0
- data/test/other/events.rb +111 -0
- data/test/other/log.rb +195 -0
- data/test/other/metrics.rb +92 -0
- data/test/other/overrides.rb +115 -0
- data/test/other/parsedfile.rb +31 -0
- data/test/other/relationships.rb +113 -0
- data/test/other/state.rb +106 -0
- data/test/other/storage.rb +39 -0
- data/test/other/transactions.rb +235 -0
- data/test/parser/lexer.rb +120 -0
- data/test/parser/parser.rb +180 -0
- data/test/puppet/conffiles.rb +104 -0
- data/test/puppet/defaults.rb +100 -0
- data/test/puppet/error.rb +23 -0
- data/test/puppet/utiltest.rb +120 -0
- data/test/puppettest.rb +774 -0
- data/test/server/authstore.rb +209 -0
- data/test/server/bucket.rb +227 -0
- data/test/server/ca.rb +201 -0
- data/test/server/fileserver.rb +710 -0
- data/test/server/logger.rb +175 -0
- data/test/server/master.rb +150 -0
- data/test/server/server.rb +130 -0
- data/test/tagging/tagging.rb +80 -0
- data/test/test +51 -0
- data/test/types/basic.rb +119 -0
- data/test/types/component.rb +272 -0
- data/test/types/cron.rb +261 -0
- data/test/types/exec.rb +273 -0
- data/test/types/file.rb +616 -0
- data/test/types/filebucket.rb +167 -0
- data/test/types/fileignoresource.rb +287 -0
- data/test/types/filesources.rb +587 -0
- data/test/types/filetype.rb +162 -0
- data/test/types/group.rb +271 -0
- data/test/types/package.rb +205 -0
- data/test/types/query.rb +101 -0
- data/test/types/service.rb +100 -0
- data/test/types/symlink.rb +93 -0
- data/test/types/tidy.rb +124 -0
- data/test/types/type.rb +135 -0
- data/test/types/user.rb +371 -0
- metadata +243 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
# the class responsible for actually doing any work
|
2
|
+
|
3
|
+
# enables no-op and logging/rollback
|
4
|
+
|
5
|
+
module Puppet
|
6
|
+
class StateChange
|
7
|
+
attr_accessor :is, :should, :type, :path, :state, :transaction, :changed
|
8
|
+
|
9
|
+
#---------------------------------------------------------------
|
10
|
+
def initialize(state)
|
11
|
+
@state = state
|
12
|
+
@path = [state.path,"change"].flatten
|
13
|
+
@is = state.is
|
14
|
+
|
15
|
+
if state.is == state.should
|
16
|
+
raise Puppet::Error.new(
|
17
|
+
"Tried to create a change for in-sync state %s" % state.name
|
18
|
+
)
|
19
|
+
end
|
20
|
+
@should = state.should
|
21
|
+
|
22
|
+
@changed = false
|
23
|
+
end
|
24
|
+
#---------------------------------------------------------------
|
25
|
+
|
26
|
+
#---------------------------------------------------------------
|
27
|
+
def go
|
28
|
+
if @state.is == @state.should
|
29
|
+
@state.info "already in sync"
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
|
33
|
+
if @state.noop
|
34
|
+
@state.log "is %s, should be %s" %
|
35
|
+
[state.is_to_s, state.should_to_s]
|
36
|
+
#@state.debug "%s is noop" % @state
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
events = @state.sync
|
42
|
+
if events.nil?
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
if events.is_a?(Array)
|
47
|
+
if events.empty?
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
else
|
51
|
+
events = [events]
|
52
|
+
end
|
53
|
+
|
54
|
+
return events.collect { |event|
|
55
|
+
# default to a simple event type
|
56
|
+
if ! event.is_a?(Symbol)
|
57
|
+
@state.warning("State '%s' returned invalid event '%s'; resetting to default" %
|
58
|
+
[@state.class,event])
|
59
|
+
|
60
|
+
event = @state.parent.class.name.id2name + "_changed"
|
61
|
+
end
|
62
|
+
|
63
|
+
# i should maybe include object type, but the event type
|
64
|
+
# should basically point to that, right?
|
65
|
+
#:state => @state,
|
66
|
+
#:object => @state.parent,
|
67
|
+
@state.log @state.change_to_s
|
68
|
+
Puppet::Event.new(
|
69
|
+
:event => event,
|
70
|
+
:change => self,
|
71
|
+
:transaction => @transaction,
|
72
|
+
:source => @state.parent,
|
73
|
+
:message => self.to_s
|
74
|
+
)
|
75
|
+
}
|
76
|
+
rescue => detail
|
77
|
+
#@state.err "%s failed: %s" % [self.to_s,detail]
|
78
|
+
raise
|
79
|
+
# there should be a way to ask the state what type of event
|
80
|
+
# it would have generated, but...
|
81
|
+
pname = @state.parent.class.name.id2name
|
82
|
+
#if pname.is_a?(Symbol)
|
83
|
+
# pname = pname.id2name
|
84
|
+
#end
|
85
|
+
#:state => @state,
|
86
|
+
@state.log "Failed: " + @state.change_to_s
|
87
|
+
return Puppet::Event.new(
|
88
|
+
:event => pname + "_failed",
|
89
|
+
:change => self,
|
90
|
+
:source => @state.parent,
|
91
|
+
:transaction => @transaction,
|
92
|
+
:message => "Failed: " + self.to_s
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
#---------------------------------------------------------------
|
97
|
+
|
98
|
+
#---------------------------------------------------------------
|
99
|
+
def forward
|
100
|
+
#@state.debug "moving change forward"
|
101
|
+
|
102
|
+
unless defined? @transaction
|
103
|
+
raise Puppet::Error,
|
104
|
+
"StateChange '%s' tried to be executed outside of transaction" %
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
return self.go
|
109
|
+
end
|
110
|
+
#---------------------------------------------------------------
|
111
|
+
|
112
|
+
#---------------------------------------------------------------
|
113
|
+
def backward
|
114
|
+
@state.should = @is
|
115
|
+
@state.retrieve
|
116
|
+
|
117
|
+
unless defined? @transaction
|
118
|
+
raise Puppet::Error,
|
119
|
+
"StateChange '%s' tried to be executed outside of transaction" %
|
120
|
+
self
|
121
|
+
end
|
122
|
+
unless @state.insync?
|
123
|
+
@state.info "Backing %s" % self
|
124
|
+
return self.go
|
125
|
+
else
|
126
|
+
@state.debug "rollback is already in sync: %s vs. %s" %
|
127
|
+
[@state.is.inspect, @state.should.inspect]
|
128
|
+
return nil
|
129
|
+
end
|
130
|
+
|
131
|
+
#raise "Moving statechanges backward is currently unsupported"
|
132
|
+
#@type.change(@path,@should,@is)
|
133
|
+
end
|
134
|
+
#---------------------------------------------------------------
|
135
|
+
|
136
|
+
#---------------------------------------------------------------
|
137
|
+
def noop
|
138
|
+
return @state.noop
|
139
|
+
end
|
140
|
+
#---------------------------------------------------------------
|
141
|
+
|
142
|
+
def to_s
|
143
|
+
return "change %s.%s(%s)" %
|
144
|
+
[@transaction.object_id, self.object_id, @state.change_to_s]
|
145
|
+
#return "change %s.%s" % [@transaction.object_id, self.object_id]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# $Id: statechange.rb 740 2005-11-01 20:22:19Z luke $
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Puppet
|
2
|
+
# a class for storing state
|
3
|
+
class Storage
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.class.load
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.clear
|
11
|
+
@@state = nil
|
12
|
+
Storage.init
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.init
|
16
|
+
Puppet.debug "Initializing Storage"
|
17
|
+
@@state = Hash.new { |hash,key|
|
18
|
+
hash[key] = Hash.new(nil)
|
19
|
+
}
|
20
|
+
@@splitchar = "\t"
|
21
|
+
end
|
22
|
+
|
23
|
+
self.init
|
24
|
+
|
25
|
+
def self.load
|
26
|
+
if Puppet[:checksumfile].nil?
|
27
|
+
raise Puppet::DevError, "Somehow the statefile is nil"
|
28
|
+
end
|
29
|
+
|
30
|
+
unless File.exists?(Puppet[:checksumfile])
|
31
|
+
Puppet.info "Statefile %s does not exist" % Puppet[:checksumfile]
|
32
|
+
return
|
33
|
+
end
|
34
|
+
begin
|
35
|
+
#Puppet.debug "Loading statefile %s" % Puppet[:checksumfile]
|
36
|
+
File.open(Puppet[:checksumfile]) { |file|
|
37
|
+
file.each { |line|
|
38
|
+
myclass, key, value = line.split(@@splitchar)
|
39
|
+
|
40
|
+
begin
|
41
|
+
@@state[eval(myclass)][key] = Marshal::load(value)
|
42
|
+
rescue => detail
|
43
|
+
raise Puppet::Error,
|
44
|
+
"Failed to load value for %s::%s => %s" % [
|
45
|
+
myclass,key,detail
|
46
|
+
], caller
|
47
|
+
end
|
48
|
+
}
|
49
|
+
}
|
50
|
+
rescue => detail
|
51
|
+
Puppet.err "Could not read %s" % Puppet[:checksumfile]
|
52
|
+
end
|
53
|
+
|
54
|
+
#Puppet.debug "Loaded state is %s" % @@state.inspect
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.state(myclass)
|
58
|
+
unless myclass.is_a? Class
|
59
|
+
myclass = myclass.class
|
60
|
+
end
|
61
|
+
result = @@state[myclass]
|
62
|
+
return result
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.store
|
66
|
+
unless FileTest.directory?(File.dirname(Puppet[:checksumfile]))
|
67
|
+
begin
|
68
|
+
Puppet.recmkdir(File.dirname(Puppet[:checksumfile]))
|
69
|
+
Puppet.info "Creating state directory %s" %
|
70
|
+
File.dirname(Puppet[:checksumfile])
|
71
|
+
rescue => detail
|
72
|
+
Puppet.err "Could not create state file: %s" % detail
|
73
|
+
return
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
unless FileTest.exist?(Puppet[:checksumfile])
|
78
|
+
Puppet.info "Creating state file %s" % Puppet[:checksumfile]
|
79
|
+
end
|
80
|
+
|
81
|
+
File.open(Puppet[:checksumfile], File::CREAT|File::WRONLY, 0600) { |file|
|
82
|
+
@@state.each { |klass, thash|
|
83
|
+
thash.each { |key,value|
|
84
|
+
mvalue = Marshal::dump(value)
|
85
|
+
file.puts([klass,key,mvalue].join(@@splitchar))
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
#Puppet.debug "Stored state is %s" % @@state.inspect
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# $Id: storage.rb 742 2005-11-16 17:12:11Z luke $
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# the class that actually walks our object/state tree, collects the changes,
|
2
|
+
# and performs them
|
3
|
+
|
4
|
+
# there are two directions of walking:
|
5
|
+
# - first we recurse down the tree and collect changes
|
6
|
+
# - then we walk back up the tree through 'refresh' after the changes
|
7
|
+
|
8
|
+
require 'puppet'
|
9
|
+
require 'puppet/statechange'
|
10
|
+
|
11
|
+
#---------------------------------------------------------------
|
12
|
+
module Puppet
|
13
|
+
class Transaction
|
14
|
+
attr_accessor :toplevel, :component
|
15
|
+
|
16
|
+
#---------------------------------------------------------------
|
17
|
+
# a bit of a gross hack; a global list of objects that have failed to sync,
|
18
|
+
# so that we can verify during later syncs that our dependencies haven't
|
19
|
+
# failed
|
20
|
+
def Transaction.init
|
21
|
+
@@failures = Hash.new(0)
|
22
|
+
Puppet::Metric.init
|
23
|
+
@@changed = []
|
24
|
+
end
|
25
|
+
#---------------------------------------------------------------
|
26
|
+
|
27
|
+
#---------------------------------------------------------------
|
28
|
+
# for now, just store the changes for executing linearly
|
29
|
+
# later, we might execute them as we receive them
|
30
|
+
def change(change)
|
31
|
+
@changes.push change
|
32
|
+
end
|
33
|
+
#---------------------------------------------------------------
|
34
|
+
|
35
|
+
#---------------------------------------------------------------
|
36
|
+
# okay, here's the deal:
|
37
|
+
# a given transaction maps directly to a component, and each transaction
|
38
|
+
# will only ever receive changes from its respective component
|
39
|
+
# so, when looking for subscribers, we need to first see if the object
|
40
|
+
# that actually changed had any direct subscribers
|
41
|
+
# then, we need to pass the event to the object's containing component,
|
42
|
+
# to see if it or any of its parents have subscriptions on the event
|
43
|
+
def evaluate
|
44
|
+
Puppet.debug "executing %s changes " % @changes.length
|
45
|
+
|
46
|
+
events = @changes.collect { |change|
|
47
|
+
if change.is_a?(Puppet::StateChange)
|
48
|
+
change.transaction = self
|
49
|
+
events = nil
|
50
|
+
begin
|
51
|
+
# use an array, so that changes can return more than one
|
52
|
+
# event if they want
|
53
|
+
events = [change.forward].flatten.reject { |e| e.nil? }
|
54
|
+
#@@changed.push change.state.parent
|
55
|
+
rescue => detail
|
56
|
+
Puppet.err("%s failed: %s" % [change.to_s,detail])
|
57
|
+
if Puppet[:debug] and detail.respond_to?(:stack)
|
58
|
+
puts detail.stack
|
59
|
+
end
|
60
|
+
next
|
61
|
+
# FIXME this should support using onerror to determine
|
62
|
+
# behaviour; or more likely, the client calling us
|
63
|
+
# should do so
|
64
|
+
end
|
65
|
+
|
66
|
+
unless events.nil? or (events.is_a?(Array) and events.empty?)
|
67
|
+
change.changed = true
|
68
|
+
end
|
69
|
+
events
|
70
|
+
else
|
71
|
+
raise Puppet::DevError,
|
72
|
+
"Transactions cannot handle objects of type %s" % child.class
|
73
|
+
end
|
74
|
+
}.flatten.reject { |event|
|
75
|
+
event.nil?
|
76
|
+
}
|
77
|
+
|
78
|
+
#@triggerevents = []
|
79
|
+
events.each { |event|
|
80
|
+
object = event.source
|
81
|
+
#Puppet::Event::Subscriptions.propagate(object, event, self)
|
82
|
+
object.propagate(event, self)
|
83
|
+
}
|
84
|
+
|
85
|
+
#events += @triggerevents
|
86
|
+
end
|
87
|
+
#---------------------------------------------------------------
|
88
|
+
|
89
|
+
#---------------------------------------------------------------
|
90
|
+
# this should only be called by a Puppet::Container object now
|
91
|
+
# and it should only receive an array
|
92
|
+
def initialize(objects)
|
93
|
+
@objects = objects
|
94
|
+
@toplevel = false
|
95
|
+
|
96
|
+
@triggered = Hash.new { |hash, key|
|
97
|
+
hash[key] = Hash.new(0)
|
98
|
+
}
|
99
|
+
|
100
|
+
# of course, this won't work on the second run
|
101
|
+
unless defined? @@failures
|
102
|
+
@toplevel = true
|
103
|
+
self.class.init
|
104
|
+
end
|
105
|
+
# change collection is in-band, and message generation is out-of-band
|
106
|
+
# of course, exception raising is also out-of-band
|
107
|
+
@changes = @objects.collect { |child|
|
108
|
+
# these children are all Puppet::Type instances
|
109
|
+
# not all of the children will return a change, and Containers
|
110
|
+
# return transactions
|
111
|
+
child.evaluate
|
112
|
+
}.flatten.reject { |child|
|
113
|
+
child.nil? # remove empties
|
114
|
+
}
|
115
|
+
end
|
116
|
+
#---------------------------------------------------------------
|
117
|
+
|
118
|
+
#---------------------------------------------------------------
|
119
|
+
def rollback
|
120
|
+
events = @changes.reverse.collect { |change|
|
121
|
+
if change.is_a?(Puppet::StateChange)
|
122
|
+
# skip changes that were never actually run
|
123
|
+
unless change.changed
|
124
|
+
Puppet.debug "%s was not changed" % change.to_s
|
125
|
+
next
|
126
|
+
end
|
127
|
+
#change.transaction = self
|
128
|
+
begin
|
129
|
+
change.backward
|
130
|
+
#@@changed.push change.state.parent
|
131
|
+
rescue => detail
|
132
|
+
Puppet.err("%s rollback failed: %s" % [change,detail])
|
133
|
+
next
|
134
|
+
# at this point, we would normally do error handling
|
135
|
+
# but i haven't decided what to do for that yet
|
136
|
+
# so just record that a sync failed for a given object
|
137
|
+
#@@failures[change.state.parent] += 1
|
138
|
+
# this still could get hairy; what if file contents changed,
|
139
|
+
# but a chmod failed? how would i handle that error? dern
|
140
|
+
end
|
141
|
+
elsif change.is_a?(Puppet::Transaction)
|
142
|
+
raise Puppet::DevError, "Got a sub-transaction"
|
143
|
+
# yay, recursion
|
144
|
+
change.rollback
|
145
|
+
else
|
146
|
+
raise Puppe::DevError,
|
147
|
+
"Transactions cannot handle objects of type %s" % child.class
|
148
|
+
end
|
149
|
+
}.flatten.reject { |e| e.nil? }
|
150
|
+
|
151
|
+
#@triggerevents = []
|
152
|
+
events.each { |event|
|
153
|
+
object = event.source
|
154
|
+
object.propagate(event, self)
|
155
|
+
}
|
156
|
+
|
157
|
+
#events += @triggerevents
|
158
|
+
end
|
159
|
+
#---------------------------------------------------------------
|
160
|
+
|
161
|
+
#---------------------------------------------------------------
|
162
|
+
def triggered(object, method)
|
163
|
+
Puppet.notice "Triggered %s" % method
|
164
|
+
@triggered[object][method] += 1
|
165
|
+
#@triggerevents << ("%s_%sed" % [object.class.name.to_s, method.to_s]).intern
|
166
|
+
end
|
167
|
+
#---------------------------------------------------------------
|
168
|
+
|
169
|
+
#---------------------------------------------------------------
|
170
|
+
def triggered?(object, method)
|
171
|
+
Puppet.notice "Looking for triggered %s" % method
|
172
|
+
@triggered[object][method]
|
173
|
+
end
|
174
|
+
#---------------------------------------------------------------
|
175
|
+
end
|
176
|
+
end
|
177
|
+
#---------------------------------------------------------------
|
178
|
+
|
179
|
+
# $Id: transaction.rb 740 2005-11-01 20:22:19Z luke $
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'puppet'
|
2
|
+
|
3
|
+
module Puppet
|
4
|
+
# The transportable objects themselves. Basically just a hash with some
|
5
|
+
# metadata and a few extra methods.
|
6
|
+
class TransObject < Hash
|
7
|
+
attr_accessor :type, :name, :file, :line
|
8
|
+
|
9
|
+
attr_writer :tags
|
10
|
+
|
11
|
+
def initialize(name,type)
|
12
|
+
self[:name] = name
|
13
|
+
@type = type
|
14
|
+
@name = name
|
15
|
+
#self.class.add(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def longname
|
19
|
+
return [self.type,self[:name]].join('--')
|
20
|
+
end
|
21
|
+
|
22
|
+
def tags
|
23
|
+
return @tags
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
return "%s(%s) => %s" % [@type,self[:name],super]
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_type(parent = nil)
|
31
|
+
if parent
|
32
|
+
self[:parent] = parent
|
33
|
+
end
|
34
|
+
retobj = nil
|
35
|
+
if type = Puppet::Type.type(self.type)
|
36
|
+
unless retobj = type.create(self)
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
retobj.file = @file
|
40
|
+
retobj.line = @line
|
41
|
+
else
|
42
|
+
raise Puppet::Error.new("Could not find object type %s" % self.type)
|
43
|
+
end
|
44
|
+
|
45
|
+
if defined? @tags and @tags
|
46
|
+
#Puppet.debug "%s(%s) tags: %s" % [@type, @name, @tags.join(" ")]
|
47
|
+
retobj.tags = @tags
|
48
|
+
end
|
49
|
+
|
50
|
+
if parent
|
51
|
+
parent.push retobj
|
52
|
+
end
|
53
|
+
|
54
|
+
return retobj
|
55
|
+
end
|
56
|
+
end
|
57
|
+
#------------------------------------------------------------
|
58
|
+
|
59
|
+
#------------------------------------------------------------
|
60
|
+
# just a linear container for objects
|
61
|
+
class TransBucket < Array
|
62
|
+
attr_accessor :name, :type, :file, :line
|
63
|
+
|
64
|
+
def push(*args)
|
65
|
+
args.each { |arg|
|
66
|
+
case arg
|
67
|
+
when Puppet::TransBucket, Puppet::TransObject
|
68
|
+
# nada
|
69
|
+
else
|
70
|
+
raise Puppet::DevError,
|
71
|
+
"TransBuckets cannot handle objects of type %s" %
|
72
|
+
arg.class
|
73
|
+
end
|
74
|
+
}
|
75
|
+
super
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_type(parent = nil)
|
79
|
+
# this container will contain the equivalent of all objects at
|
80
|
+
# this level
|
81
|
+
#container = Puppet::Component.new(:name => @name, :type => @type)
|
82
|
+
unless defined? @name
|
83
|
+
raise Puppet::DevError, "TransBuckets must have names"
|
84
|
+
end
|
85
|
+
unless defined? @type
|
86
|
+
Puppet.debug "TransBucket '%s' has no type" % @name
|
87
|
+
end
|
88
|
+
hash = {
|
89
|
+
:name => @name,
|
90
|
+
:type => @type
|
91
|
+
}
|
92
|
+
if defined? @parameters
|
93
|
+
@parameters.each { |param,value|
|
94
|
+
Puppet.debug "Defining %s on %s of type %s" %
|
95
|
+
[param,@name,@type]
|
96
|
+
hash[param] = value
|
97
|
+
}
|
98
|
+
else
|
99
|
+
Puppet.debug "%s[%s] has no parameters" % [@type, @name]
|
100
|
+
end
|
101
|
+
|
102
|
+
if parent
|
103
|
+
hash[:parent] = parent
|
104
|
+
end
|
105
|
+
container = Puppet::Type::Component.create(hash)
|
106
|
+
|
107
|
+
if parent
|
108
|
+
parent.push container
|
109
|
+
end
|
110
|
+
|
111
|
+
# unless we successfully created the container, return an error
|
112
|
+
unless container
|
113
|
+
Puppet.warning "Got no container back"
|
114
|
+
return nil
|
115
|
+
end
|
116
|
+
|
117
|
+
self.each { |child|
|
118
|
+
# the fact that we descend here means that we are
|
119
|
+
# always going to execute depth-first
|
120
|
+
# which is _probably_ a good thing, but one never knows...
|
121
|
+
unless child.is_a?(Puppet::TransBucket) or
|
122
|
+
child.is_a?(Puppet::TransObject)
|
123
|
+
raise Puppet::DevError,
|
124
|
+
"TransBucket#to_type cannot handle objects of type %s" %
|
125
|
+
child.class
|
126
|
+
end
|
127
|
+
|
128
|
+
# Now just call to_type on them with the container as a parent
|
129
|
+
unless obj = child.to_type(container)
|
130
|
+
# nothing; we assume the method already warned
|
131
|
+
Puppet.warning "Could not create child %s" % child.name
|
132
|
+
end
|
133
|
+
}
|
134
|
+
|
135
|
+
# at this point, no objects at are level are still Transportable
|
136
|
+
# objects
|
137
|
+
return container
|
138
|
+
end
|
139
|
+
|
140
|
+
def param(param,value)
|
141
|
+
unless defined? @parameters
|
142
|
+
@parameters = {}
|
143
|
+
end
|
144
|
+
@parameters[param] = value
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
#------------------------------------------------------------
|
149
|
+
end
|
150
|
+
|
151
|
+
# $Id: transportable.rb 740 2005-11-01 20:22:19Z luke $
|