Class: Puppet::Transaction::Persistence Private

Inherits:
Object
  • Object
show all
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).

API:

  • private

Instance Method Summary collapse

Constructor Details

#initializePersistence

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.

API:

  • private



9
10
11
12
# File 'lib/puppet/transaction/persistence.rb', line 9

def initialize
  @old_data = {}
  @new_data = {"resources" => {}}
end

Instance Method Details

#dataHash

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.

Returns:

  • hash of data stored in persistence store

API:

  • private



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

Parameters:

  • name of resource

  • name of the parameter

Returns:

  • the system_value

API:

  • private



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

#loadObject

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.

API:

  • private



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")
    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", { :level => :warning })

      begin
        File.rename(filename, filename + ".bad")
      rescue => detail
        Puppet.log_exception(detail, "Unable to rename corrupt transaction store file: #{detail}")
        raise Puppet::Error, "Could not rename corrupt transaction store file #{filename}; remove manually", 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."
    return
  end

  @old_data = result
end

#saveObject

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.

API:

  • private



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.

API:

  • private



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