lib/kafo/configuration.rb in kafo-3.0.0 vs lib/kafo/configuration.rb in kafo-4.0.0
- old
+ new
@@ -2,15 +2,15 @@
require 'yaml'
require 'tmpdir'
require 'kafo/puppet_module'
require 'kafo/color_scheme'
require 'kafo/data_type_parser'
-require 'kafo/puppet_configurer'
+require 'kafo/execution_environment'
module Kafo
class Configuration
- attr_reader :config_file, :answer_file
+ attr_reader :config_file, :answer_file, :scenario_id
DEFAULT = {
:name => '',
:description => '',
:enabled => true,
@@ -25,15 +25,20 @@
:module_dirs => ['./modules'],
:colors => Kafo::ColorScheme.colors_possible?,
:color_of_background => :dark,
:hook_dirs => [],
:custom => {},
+ :facts => {},
:low_priority_modules => [],
:verbose_log_level => 'info',
:skip_puppet_version_check => false
}
+ def self.get_scenario_id(filename)
+ File.basename(filename, '.yaml')
+ end
+
def initialize(file, persist = true)
@config_file = file
@persist = persist
configure_application
@logger = KafoConfigure.logger
@@ -45,10 +50,11 @@
puts "No answer file at #{@answer_file} found, can not continue"
KafoConfigure.exit(:no_answer_file)
end
@config_dir = File.dirname(@config_file)
+ @scenario_id = Configuration.get_scenario_id(@config_file)
end
def save_configuration(configuration)
return true unless @persist
begin
@@ -88,10 +94,18 @@
def set_custom(key, value)
custom_storage[key.to_sym] = value
end
+ def get_custom_fact(key)
+ custom_fact_storage[key.to_s]
+ end
+
+ def set_custom_fact(key, value)
+ custom_fact_storage[key.to_s] = value
+ end
+
def modules
@modules ||= begin
register_data_types
@data.keys.map { |mod| PuppetModule.new(mod, PuppetModule.find_parser, self).parse }.sort
end
@@ -146,13 +160,15 @@
save_configuration(app)
end
def params_default_values
@params_default_values ||= begin
- puppetconf = PuppetConfigurer.new('noop' => true)
- KafoConfigure.exit_handler.register_cleanup_path puppetconf.config_path
+ execution_env = ExecutionEnvironment.new(self)
+ KafoConfigure.exit_handler.register_cleanup_path(execution_env.directory)
+ puppetconf = execution_env.configure_puppet('noop' => true)
+
dump_manifest = <<EOS
#{includes}
class { '::kafo_configure::dump_values':
lookups => [#{param_lookups_to_dump}],
variables => [#{params_to_dump}],
@@ -301,9 +317,13 @@
private
def custom_storage
app[:custom]
+ end
+
+ def custom_fact_storage
+ app[:facts]
end
def includes
modules.map do |mod|
module_dir = module_dirs.find do |dir|