Class: Puppet::Configurer

Inherits:
Object show all
Includes:
FactHandler, Util
Defined in:
lib/puppet/configurer.rb

Defined Under Namespace

Modules: FactHandler Classes: Downloader, DownloaderFactory, PluginHandler

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, deterministic_rand, execfail, execpipe, execute, exit_on_fail, logmethods, memory, path_to_uri, pretty_backtrace, proxy, replace_file, safe_posix_fork, symbolizehash, thinmark, uri_to_path, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from FactHandler

#facts_for_uploading, #find_facts

Constructor Details

#initialize(factory = Puppet::Configurer::DownloaderFactory.new) ⇒ Configurer

Returns a new instance of Configurer.



47
48
49
50
51
52
53
54
55
# File 'lib/puppet/configurer.rb', line 47

def initialize(factory = Puppet::Configurer::DownloaderFactory.new)
  Puppet.settings.use(:main, :ssl, :agent)

  @running = false
  @splayed = false
  @environment = Puppet[:environment]
  @transaction_uuid = SecureRandom.uuid
  @handler = Puppet::Configurer::PluginHandler.new(factory)
end

Instance Attribute Details

#compile_timeObject (readonly)



18
19
20
# File 'lib/puppet/configurer.rb', line 18

def compile_time
  @compile_time
end

#environmentObject (readonly)



18
19
20
# File 'lib/puppet/configurer.rb', line 18

def environment
  @environment
end

Class Method Details

.to_sObject

Provide more helpful strings to the logging that the Agent does



21
22
23
# File 'lib/puppet/configurer.rb', line 21

def self.to_s
  "Puppet configuration client"
end

Instance Method Details

#apply_catalog(catalog, options) ⇒ Object

Retrieve (optionally) and apply a catalog. If a catalog is passed in the options, then apply that one, otherwise retrieve it.



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/puppet/configurer.rb', line 115

def apply_catalog(catalog, options)
  report = options[:report]
  report.configuration_version = catalog.version

  benchmark(:notice, "Finished catalog run") do
    catalog.apply(options)
  end

  report.finalize_report
  report
end

#convert_catalog(result, duration) ⇒ Object

Convert a plain resource catalog into our full host catalog.



75
76
77
78
79
80
81
82
# File 'lib/puppet/configurer.rb', line 75

def convert_catalog(result, duration)
  catalog = result.to_ral
  catalog.finalize
  catalog.retrieval_duration = duration
  catalog.write_class_file
  catalog.write_resource_file
  catalog
end

#execute_postrun_commandObject



25
26
27
# File 'lib/puppet/configurer.rb', line 25

def execute_postrun_command
  execute_from_setting(:postrun_command)
end

#execute_prerun_commandObject



29
30
31
# File 'lib/puppet/configurer.rb', line 29

def execute_prerun_command
  execute_from_setting(:prerun_command)
end

#get_facts(options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/puppet/configurer.rb', line 84

def get_facts(options)
  if options[:pluginsync]
    remote_environment_for_plugins = Puppet::Node::Environment.remote(@environment)
    download_plugins(remote_environment_for_plugins)
  end

  facts_hash = {}
  if Puppet::Resource::Catalog.indirection.terminus_class == :rest
    # This is a bit complicated.  We need the serialized and escaped facts,
    # and we need to know which format they're encoded in.  Thus, we
    # get a hash with both of these pieces of information.
    #
    # facts_for_uploading may set Puppet[:node_name_value] as a side effect
    facts_hash = facts_for_uploading
  end
  facts_hash
end

#init_storageObject

Initialize and load storage



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/configurer.rb', line 34

def init_storage
    Puppet::Util::Storage.load
    @compile_time ||= Puppet::Util::Storage.cache(:configuration)[:compile_time]
rescue => detail
  Puppet.log_exception(detail, "Removing corrupt state file #{Puppet[:statefile]}: #{detail}")
  begin
    Puppet::FileSystem.unlink(Puppet[:statefile])
    retry
  rescue => detail
    raise Puppet::Error.new("Cannot remove #{Puppet[:statefile]}: #{detail}", detail)
  end
end

#prepare_and_retrieve_catalog(options, query_options) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/puppet/configurer.rb', line 102

def prepare_and_retrieve_catalog(options, query_options)
  # set report host name now that we have the fact
  options[:report].host = Puppet[:node_name_value]

  unless catalog = (options.delete(:catalog) || retrieve_catalog(query_options))
    Puppet.err "Could not retrieve catalog; skipping run"
    return
  end
  catalog
end

#retrieve_catalog(query_options) ⇒ Object

Get the remote catalog, yo. Returns nil if no catalog can be found.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/puppet/configurer.rb', line 58

def retrieve_catalog(query_options)
  query_options ||= {}
  # First try it with no cache, then with the cache.
  unless (Puppet[:use_cached_catalog] and result = retrieve_catalog_from_cache(query_options)) or result = retrieve_new_catalog(query_options)
    if ! Puppet[:usecacheonfailure]
      Puppet.warning "Not using cache on failed catalog"
      return nil
    end
    result = retrieve_catalog_from_cache(query_options)
  end

  return nil unless result

  convert_catalog(result, @duration)
end

#run(options = {}) ⇒ Object

The code that actually runs the catalog. This just passes any options on to the catalog, which accepts :tags and :ignoreschedules.



130
131
132
133
134
135
136
137
138
139
# File 'lib/puppet/configurer.rb', line 130

def run(options = {})
  pool = Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout])
  begin
    Puppet.override(:http_pool => pool) do
      run_internal(options)
    end
  ensure
    pool.close
  end
end

#save_last_run_summary(report) ⇒ Object



255
256
257
258
259
260
261
262
# File 'lib/puppet/configurer.rb', line 255

def save_last_run_summary(report)
  mode = Puppet.settings.setting(:lastrunfile).mode
  Puppet::Util.replace_file(Puppet[:lastrunfile], mode) do |fh|
    fh.print YAML.dump(report.raw_summary)
  end
rescue => detail
  Puppet.log_exception(detail, "Could not save last run local report: #{detail}")
end

#send_report(report) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/puppet/configurer.rb', line 247

def send_report(report)
  puts report.summary if Puppet[:summarize]
  save_last_run_summary(report)
  Puppet::Transaction::Report.indirection.save(report, nil, :environment => Puppet::Node::Environment.remote(@environment)) if Puppet[:report]
rescue => detail
  Puppet.log_exception(detail, "Could not send report: #{detail}")
end