diff options
author | mh <mh@immerda.ch> | 2016-06-07 21:59:33 +0200 |
---|---|---|
committer | mh <mh@immerda.ch> | 2016-06-07 22:28:48 +0200 |
commit | bbedb788a7951e2f69c1c2815a5c3c669ff02ae6 (patch) | |
tree | a857ea3da2063501abe90ad1fc80bfd281bff8a6 /lib/puppet | |
parent | 70b87a890319b262641503e78495b83df24f20ea (diff) |
keep trocla object around - addresses #18
Per puppet function call we now created a new Trocla object. This
is a) a very naive approach and b) obviously can lead to a lot of
inefficiency as we for example need to build up trocla each time
again. Also this means that we are running into problems like
opening a connection to a database system each time a trocla
lookup is done (and we never close the connection :-/).
The proper way to solve this is to make sure we don't create too
many trocla objects. With this change, we should now create once
a global trocla object PER puppet(-master/-server) process and
keep it around for the life time of such a process.
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/util/trocla_helper.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/puppet/util/trocla_helper.rb b/lib/puppet/util/trocla_helper.rb index 94670ae..ce583f5 100644 --- a/lib/puppet/util/trocla_helper.rb +++ b/lib/puppet/util/trocla_helper.rb @@ -22,13 +22,22 @@ module Puppet::Util::TroclaHelper options = YAML.load(options) end - configfile = File.join(File.dirname(Puppet.settings[:config]), "troclarc.yaml") + has_options ? store.send(trocla_func, key, format, options) : store.send(trocla_func, key, format) + end + module_function :trocla + + private - raise(Puppet::ParseError, "Trocla config file #{configfile} is not readable") unless File.exist?(configfile) + def store + @store ||= begin + require 'trocla' + configfile = File.join(File.dirname(Puppet.settings[:config]), "troclarc.yaml") - require 'trocla' + raise(Puppet::ParseError, "Trocla config file #{configfile} is not readable") unless File.exist?(configfile) - has_options ? Trocla.new(configfile).send(trocla_func, key, format, options) : Trocla.new(configfile).send(trocla_func, key, format) + Trocla.new(configfile) + end end - module_function :trocla + module_function :store + end |