Class: Puppet::Util::Storage Private
- Includes:
- Puppet::Util, Singleton
- Defined in:
- lib/puppet/util/storage.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
a class for storing state
Constant Summary
Constants included from Puppet::Util
ALNUM, ALPHA, AbsolutePathPosix, AbsolutePathWindows, DEFAULT_POSIX_MODE, DEFAULT_WINDOWS_MODE, ESCAPED, HEX, HttpProxy, PUPPET_STACK_INSERTION_FRAME, RESERVED, RFC_3986_URI_REGEX, UNRESERVED, UNSAFE
Constants included from POSIX
POSIX::LOCALE_ENV_VARS, POSIX::USER_ENV_VARS
Constants included from SymbolicFileMode
Puppet::Util::SymbolicFileMode::SetGIDBit, Puppet::Util::SymbolicFileMode::SetUIDBit, Puppet::Util::SymbolicFileMode::StickyBit, Puppet::Util::SymbolicFileMode::SymbolicMode, Puppet::Util::SymbolicFileMode::SymbolicSpecialToBit
Class Method Summary collapse
-
.cache(object) ⇒ Object
private
Return a hash that will be stored to disk.
- .clear ⇒ Object private
- .init ⇒ Object private
- .load ⇒ Object private
- .state ⇒ Object private
- .stateinspect ⇒ Object private
- .store ⇒ Object private
Instance Method Summary collapse
-
#initialize ⇒ Storage
constructor
private
A new instance of Storage.
Methods included from Puppet::Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
Methods included from POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from SymbolicFileMode
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Constructor Details
#initialize ⇒ Storage
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 |
.clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/puppet/util/storage.rb', line 34 def self.clear @@state.clear end |
.init ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/puppet/util/storage.rb', line 38 def self.init @@state = {} end |
.load ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 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 |
# File 'lib/puppet/util/storage.rb', line 44 def self.load Puppet.settings.use(:main) unless FileTest.directory?(Puppet[:statedir]) filename = Puppet[:statefile] unless Puppet::FileSystem.exist?(filename) self.init if @@state.nil? return end unless File.file?(filename) Puppet.warning(_("Checksumfile %{filename} is not a file, ignoring") % { filename: filename }) return end Puppet::Util.benchmark(:debug, "Loaded state in %{seconds} seconds") do begin @@state = Puppet::Util::Yaml.safe_load_file(filename, [Symbol, Time]) rescue Puppet::Util::Yaml::YamlLoadError => detail Puppet.err _("Checksumfile %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail } begin File.rename(filename, filename + ".bad") rescue raise Puppet::Error, _("Could not rename corrupt %{filename}; remove manually") % { filename: filename }, detail.backtrace end end end unless @@state.is_a?(Hash) Puppet.err _("State got corrupted") self.init end end |
.state ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/puppet/util/storage.rb', line 11 def self.state @@state end |
.stateinspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/puppet/util/storage.rb', line 76 def self.stateinspect @@state.inspect end |
.store ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppet/util/storage.rb', line 80 def self.store Puppet.debug "Storing state" Puppet.info _("Creating state file %{file}") % { file: Puppet[:statefile] } unless Puppet::FileSystem.exist?(Puppet[:statefile]) if Puppet[:statettl] == 0 || Puppet[:statettl] == Float::INFINITY Puppet.debug "Not pruning old state cache entries" else Puppet::Util.benchmark(:debug, "Pruned old state cache entries in %{seconds} seconds") do ttl_cutoff = Time.now - Puppet[:statettl] @@state.reject! do |k,v| @@state[k][:checked] && @@state[k][:checked] < ttl_cutoff end end end Puppet::Util.benchmark(:debug, "Stored state in %{seconds} seconds") do Puppet::Util::Yaml.dump(@@state, Puppet[:statefile]) end end |