Class: Puppet::Transaction::Persistence Private
- Defined in:
- lib/puppet/transaction/persistence.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 persistence store implementation for storing information between transaction runs for the purposes of information inference (such as calculating corrective_change).
Class Method Summary collapse
- .allowed_classes ⇒ Object private
Instance Method Summary collapse
- #copy_skipped(resource_name) ⇒ Object private
-
#data ⇒ Hash
private
Obtain the full raw data from the persistence store.
-
#enabled?(catalog) ⇒ boolean
private
Use the catalog and run_mode to determine if persistence should be enabled or not.
-
#get_system_value(resource_name, param_name) ⇒ Object?
private
Retrieve the system value using the resource and parameter name.
-
#initialize ⇒ Persistence
constructor
private
A new instance of Persistence.
-
#load ⇒ Object
private
Load data from the persistence store on disk.
-
#save ⇒ Object
private
Save data from internal class to persistence store on disk.
- #set_system_value(resource_name, param_name, value) ⇒ Object private
Constructor Details
#initialize ⇒ Persistence
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 Persistence.
30 31 32 33 |
# File 'lib/puppet/transaction/persistence.rb', line 30 def initialize @old_data = {} @new_data = { "resources" => {} } end |
Class Method Details
.allowed_classes ⇒ 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 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet/transaction/persistence.rb', line 11 def self.allowed_classes @allowed_classes ||= [ Symbol, Time, Regexp, # URI is excluded, because it serializes all instance variables including the # URI parser. Better to serialize the URL encoded representation. SemanticPuppet::Version, # SemanticPuppet::VersionRange has many nested classes and is unlikely to be # used directly, so ignore it Puppet::Pops::Time::Timestamp, Puppet::Pops::Time::TimeData, Puppet::Pops::Time::Timespan, Puppet::Pops::Types::PBinaryType::Binary # Puppet::Pops::Types::PSensitiveType::Sensitive values are excluded from # the persistence store, ignore it. ].freeze end |
Instance Method Details
#copy_skipped(resource_name) ⇒ 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.
64 65 66 67 68 69 70 |
# File 'lib/puppet/transaction/persistence.rb', line 64 def copy_skipped(resource_name) @old_data["resources"] ||= {} old_value = @old_data["resources"][resource_name] unless old_value.nil? @new_data["resources"][resource_name] = old_value end end |
#data ⇒ Hash
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.
Obtain the full raw data from the persistence store.
37 38 39 |
# File 'lib/puppet/transaction/persistence.rb', line 37 def data @old_data end |
#enabled?(catalog) ⇒ boolean
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.
Use the catalog and run_mode to determine if persistence should be enabled or not
116 117 118 |
# File 'lib/puppet/transaction/persistence.rb', line 116 def enabled?(catalog) catalog.host_config? && Puppet.run_mode.name == :agent end |
#get_system_value(resource_name, param_name) ⇒ 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.
Retrieve the system value using the resource and parameter name
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet/transaction/persistence.rb', line 45 def get_system_value(resource_name, param_name) if !@old_data["resources"].nil? && !@old_data["resources"][resource_name].nil? && !@old_data["resources"][resource_name]["parameters"].nil? && !@old_data["resources"][resource_name]["parameters"][param_name].nil? @old_data["resources"][resource_name]["parameters"][param_name]["system_value"] else nil end 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.
Load data from the persistence store on disk.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/puppet/transaction/persistence.rb', line 73 def load filename = Puppet[:transactionstorefile] unless Puppet::FileSystem.exist?(filename) return end unless File.file?(filename) Puppet.warning(_("Transaction store file %{filename} is not a file, ignoring") % { filename: filename }) return end result = nil Puppet::Util.benchmark(:debug, _("Loaded transaction store file in %{seconds} seconds")) do result = Puppet::Util::Yaml.safe_load_file(filename, self.class.allowed_classes) rescue Puppet::Util::Yaml::YamlLoadError => detail Puppet.log_exception(detail, _("Transaction store file %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail }) begin File.rename(filename, filename + ".bad") rescue => detail Puppet.log_exception(detail, _("Unable to rename corrupt transaction store file: %{detail}") % { detail: detail }) raise Puppet::Error, _("Could not rename corrupt transaction store file %{filename}; remove manually") % { filename: filename }, detail.backtrace end result = {} end unless result.is_a?(Hash) Puppet.err _("Transaction store file %{filename} is valid YAML but not returning a hash. Check the file for corruption, or remove it before continuing.") % { filename: filename } return end @old_data = result end |
#save ⇒ 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.
Save data from internal class to persistence store on disk.
109 110 111 |
# File 'lib/puppet/transaction/persistence.rb', line 109 def save Puppet::Util::Yaml.dump(@new_data, Puppet[:transactionstorefile]) end |
#set_system_value(resource_name, param_name, value) ⇒ 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.
56 57 58 59 60 61 62 |
# File 'lib/puppet/transaction/persistence.rb', line 56 def set_system_value(resource_name, param_name, value) @new_data["resources"] ||= {} @new_data["resources"][resource_name] ||= {} @new_data["resources"][resource_name]["parameters"] ||= {} @new_data["resources"][resource_name]["parameters"][param_name] ||= {} @new_data["resources"][resource_name]["parameters"][param_name]["system_value"] = value end |