Class: Puppet::Util::Storage
Overview
a class for storing state
Class Method Summary
collapse
Instance Method Summary
collapse
activerecord_version, benchmark, chuser, classproxy, #execfail, #execpipe, execute, logmethods, memory, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, which, withumask
Methods included from POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Constructor Details
Returns a new instance of Storage.
15
16
17
|
# File 'lib/puppet/util/storage.rb', line 15
def initialize
self.class.load
end
|
Class Method Details
.cache(object) ⇒ Object
Return a hash that will be stored to disk. It’s worth noting here that we use the object’s full path, not just the name/type combination. At the least, this is useful for those non-isomorphic types like exec, but it also means that if an object changes locations in the configuration it will lose its cache.
24
25
26
27
28
29
30
31
32
|
# File 'lib/puppet/util/storage.rb', line 24
def self.cache(object)
if object.is_a?(Symbol)
name = object
else
name = object.to_s
end
@@state[name] ||= {}
end
|
34
35
36
37
|
# File 'lib/puppet/util/storage.rb', line 34
def self.clear
@@state.clear
Storage.init
end
|
39
40
41
42
|
# File 'lib/puppet/util/storage.rb', line 39
def self.init
@@state = {}
@@splitchar = "\t"
end
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/puppet/util/storage.rb', line 46
def self.load
Puppet.settings.use(:main) unless FileTest.directory?(Puppet[:statedir])
unless File.exists?(Puppet[:statefile])
self.init unless !@@state.nil?
return
end
unless File.file?(Puppet[:statefile])
Puppet.warning("Checksumfile #{Puppet[:statefile]} is not a file, ignoring")
return
end
Puppet::Util.benchmark(:debug, "Loaded state") do
Puppet::Util::FileLocking.readlock(Puppet[:statefile]) do |file|
begin
@@state = YAML.load(file)
rescue => detail
Puppet.err "Checksumfile #{Puppet[:statefile]} is corrupt (#{detail}); replacing"
begin
File.rename(Puppet[:statefile], Puppet[:statefile] + ".bad")
rescue
raise Puppet::Error,
"Could not rename corrupt #{Puppet[:statefile]}; remove manually"
end
end
end
end
unless @@state.is_a?(Hash)
Puppet.err "State got corrupted"
self.init
end
end
|
11
12
13
|
# File 'lib/puppet/util/storage.rb', line 11
def self.state
@@state
end
|
.stateinspect ⇒ Object
81
82
83
|
# File 'lib/puppet/util/storage.rb', line 81
def self.stateinspect
@@state.inspect
end
|