Class: R10K::Action::Runner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/r10k/action/runner.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Constructor Details

#initialize(opts, argv, klass) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
16
17
# File 'lib/r10k/action/runner.rb', line 11

def initialize(opts, argv, klass)
  @opts = opts
  @argv = argv
  @klass = klass

  @settings = {}
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
# File 'lib/r10k/action/runner.rb', line 28

def call
  setup_logging
  setup_settings
  # @todo check arguments
  setup_authorization
  instance.call
end

#instanceObject



19
20
21
22
23
24
25
26
# File 'lib/r10k/action/runner.rb', line 19

def instance
  if @_instance.nil?
    iopts = @opts.dup
    iopts.delete(:loglevel)
    @_instance = @klass.new(iopts, @argv, @settings)
  end
  @_instance
end

#setup_authorizationObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/r10k/action/runner.rb', line 65

def setup_authorization
  begin
    license = R10K::Util::License.load

    if license.respond_to?(:authorization_token)
      PuppetForge::Connection.authorization = license.authorization_token
    end
  rescue R10K::Error => e
    logger.warn e.message
  end
end

#setup_loggingObject



36
37
38
39
40
# File 'lib/r10k/action/runner.rb', line 36

def setup_logging
  if @opts.key?(:loglevel)
    R10K::Logging.level = @opts[:loglevel]
  end
end

#setup_settingsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/r10k/action/runner.rb', line 42

def setup_settings
  config_settings = settings_from_config(@opts[:config])

  overrides = {}
  overrides[:cachedir] = @opts[:cachedir] if @opts.key?(:cachedir)
  overrides[:deploy] = {} if @opts.key?(:'puppet-path') || @opts.key?(:'generate-types')
  overrides[:deploy][:puppet_path] = @opts[:'puppet-path'] if @opts.key?(:'puppet-path')
  overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')

  with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
    newval = oldval.merge(newval) if oldval.is_a? Hash
    logger.debug2 _("Overriding config file setting '%{key}': '%{old_val}' -> '%{new_val}'") % {key: key, old_val: oldval, new_val: newval}
    newval
  end

  @settings = R10K::Settings.global_settings.evaluate(with_overrides)

  R10K::Initializers::GlobalInitializer.new(@settings).call
rescue R10K::Settings::Collection::ValidationError => e
  logger.error e.format
  exit(8)
end