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).
Instance Method Summary collapse
-
#data ⇒ Hash
private
Obtain the full raw data from the persistence store.
-
#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.
9 10 11 12 |
# File 'lib/puppet/transaction/persistence.rb', line 9 def initialize @old_data = {} @new_data = {"resources" => {}} end |
Instance Method Details
#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.
16 17 18 |
# File 'lib/puppet/transaction/persistence.rb', line 16 def data @old_data 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
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet/transaction/persistence.rb', line 24 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.
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 75 76 77 78 |
# File 'lib/puppet/transaction/persistence.rb', line 44 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")) do begin result = Puppet::Util::Yaml.load_file(filename, false, true) rescue Puppet::Util::Yaml::YamlLoadError => detail Puppet.log_exception(detail, _("Transaction store file %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail }, { :level => :warning }) 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 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.
81 82 83 |
# File 'lib/puppet/transaction/persistence.rb', line 81 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.
35 36 37 38 39 40 41 |
# File 'lib/puppet/transaction/persistence.rb', line 35 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 |