Class: Kafo::KafoConfigure
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#dashize, #parametrize, #underscore, #with_prefix
Constructor Details
Returns a new instance of KafoConfigure.
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/kafo/kafo_configure.rb', line 101
def initialize(*args)
self.class.preset_color_scheme
self.class.logger = Logger.new
self.class.exit_handler = ExitHandler.new
@progress_bar = nil
@config_reload_requested = false
scenario_manager = setup_scenario_manager
self.class.scenario_manager = scenario_manager
scenario_manager.list_available_scenarios if ARGV.include?('--list-scenarios')
scenario_manager.check_enable_scenario
scenario_manager.check_disable_scenario
setup_config(config_file)
self.class.hooking.execute(:pre_migrations)
reload_config
applied_total = self.class.config.run_migrations
request_config_reload if applied_total > 0
if ARGV.include?('--migrations-only')
verbose = ARGV.include?('--verbose') || ARGV.include?('-v')
Logging.setup(verbose: verbose)
self.class.logger.notice('Log buffers flushed')
self.class.exit(0)
end
reload_config
if scenario_manager.configured?
scenario_manager.check_scenario_change(self.class.config_file)
if scenario_manager.scenario_changed?(self.class.config_file) && !self.class.in_help_mode?
prev_config = scenario_manager.load_configuration(scenario_manager.previous_scenario)
prev_config.run_migrations
self.class.config.migrate_configuration(prev_config, :skip => [:log_name])
setup_config(self.class.config_file)
self.class.logger.notice("Due to scenario change the configuration (#{self.class.config_file}) was updated with #{scenario_manager.previous_scenario} and reloaded.")
end
end
super
self.class.hooking.execute(:boot)
set_app_options parse clamp_app_arguments
parse_app_arguments
if ARGV.any? { |option| ['--help', '--full-help'].include? option }
Logging.setup_verbose(level: :error)
else
Logging.setup(verbose: config.app[:verbose])
end
logger.notice("Loading installer configuration. This will take some time.")
self.class.set_color_scheme
self.class.hooking.execute(:init)
set_parameters set_options
end
|
Class Attribute Details
.check_dirs ⇒ Object
Returns the value of attribute check_dirs.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def check_dirs
@check_dirs
end
|
.config ⇒ Object
Returns the value of attribute config.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def config
@config
end
|
.config_file ⇒ Object
Returns the value of attribute config_file.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def config_file
@config_file
end
|
.exit_handler ⇒ Object
Returns the value of attribute exit_handler.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def exit_handler
@exit_handler
end
|
.gem_root ⇒ Object
Returns the value of attribute gem_root.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def gem_root
@gem_root
end
|
.hooking ⇒ Object
49
50
51
|
# File 'lib/kafo/kafo_configure.rb', line 49
def hooking
@hooking ||= Hooking.new
end
|
.kafo_modules_dir ⇒ Object
Returns the value of attribute kafo_modules_dir.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def kafo_modules_dir
@kafo_modules_dir
end
|
.logger ⇒ Object
Returns the value of attribute logger.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def logger
@logger
end
|
.module_dirs ⇒ Object
Returns the value of attribute module_dirs.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def module_dirs
@module_dirs
end
|
.root_dir ⇒ Object
Returns the value of attribute root_dir.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def root_dir
@root_dir
end
|
.scenario_manager ⇒ Object
Returns the value of attribute scenario_manager.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def scenario_manager
@scenario_manager
end
|
.store ⇒ Object
Returns the value of attribute store.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def store
@store
end
|
.verbose ⇒ Object
Returns the value of attribute verbose.
44
45
46
|
# File 'lib/kafo/kafo_configure.rb', line 44
def verbose
@verbose
end
|
Instance Attribute Details
#puppet_report ⇒ Object
Returns the value of attribute puppet_report.
39
40
41
|
# File 'lib/kafo/kafo_configure.rb', line 39
def puppet_report
@puppet_report
end
|
Class Method Details
.exit(code, &block) ⇒ Object
59
60
61
|
# File 'lib/kafo/kafo_configure.rb', line 59
def exit(code, &block)
exit_handler.exit(code, &block)
end
|
.exit_code ⇒ Object
63
64
65
|
# File 'lib/kafo/kafo_configure.rb', line 63
def exit_code
self.exit_handler.exit_code
end
|
.help(*args) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/kafo/kafo_configure.rb', line 71
def help(*args)
kafo = args.pop
builder_class = kafo.full_help? ? HelpBuilders::Advanced : HelpBuilders::Basic
args.push builder_class.new(kafo.params)
super(*args)
end
|
.in_help_mode? ⇒ Boolean
67
68
69
|
# File 'lib/kafo/kafo_configure.rb', line 67
def in_help_mode?
ARGV.include?('--help') || ARGV.include?('--full-help') || ARGV.include?('-h')
end
|
.preset_color_scheme ⇒ Object
88
89
90
91
92
|
# File 'lib/kafo/kafo_configure.rb', line 88
def preset_color_scheme
match = ARGV.join(' ').match(/--color-of-background[ =](\w+)/)
background = match && match[1]
ColorScheme.new(:background => background, :colors => use_colors?).setup
end
|
.run ⇒ Object
53
54
55
56
57
|
# File 'lib/kafo/kafo_configure.rb', line 53
def run
return super
rescue SystemExit
self.exit_handler.exit(self.exit_code) end
|
.set_color_scheme ⇒ Object
94
95
96
97
98
|
# File 'lib/kafo/kafo_configure.rb', line 94
def set_color_scheme
ColorScheme.new(
:background => config.app[:color_of_background],
:colors => use_colors?).setup
end
|
.use_colors? ⇒ Boolean
78
79
80
81
82
83
84
85
86
|
# File 'lib/kafo/kafo_configure.rb', line 78
def use_colors?
if config
colors = config.app[:colors]
else
colors = ARGV.include?('--no-colors') ? false : nil
colors = ARGV.include?('--colors') ? true : nil if colors.nil?
end
colors
end
|
Instance Method Details
#add_module(name) ⇒ Object
255
256
257
258
259
|
# File 'lib/kafo/kafo_configure.rb', line 255
def add_module(name)
config.add_module(name)
reset_params_cache
self.module(name)
end
|
#config ⇒ Object
165
166
167
|
# File 'lib/kafo/kafo_configure.rb', line 165
def config
self.class.config
end
|
#enabled_params ⇒ Object
246
247
248
|
# File 'lib/kafo/kafo_configure.rb', line 246
def enabled_params
params.select { |p| p.module.enabled? }
end
|
#execute ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/kafo/kafo_configure.rb', line 189
def execute
parse_cli_arguments
if !config.app[:verbose]
@progress_bar = config.app[:colors] ? ProgressBars::Colored.new : ProgressBars::BlackWhite.new
end
if checks_only? || !skip_checks_i_know_better?
logger = Logger.new('checks')
if SystemChecker.check
logger.notice("System checks passed")
else
logger.error("Your system does not meet configuration criteria")
self.class.exit(:invalid_system)
end
end
self.class.exit(0) if checks_only?
self.class.hooking.execute(:pre_validations)
if interactive?
wizard = Wizard.new(self)
wizard.run
else
unless validate_all
puts "Error during configuration, exiting"
self.class.exit(:invalid_values)
end
end
self.class.hooking.execute(:pre_commit)
unless dont_save_answers? || noop?
config.configure_application
store_params
self.class.scenario_manager.link_last_scenario(self.class.config_file) if self.class.scenario_manager.configured?
end
run_installation
return self
rescue SystemExit
return self
end
|
#exit_code ⇒ Object
231
232
233
|
# File 'lib/kafo/kafo_configure.rb', line 231
def exit_code
self.class.exit_code
end
|
#help ⇒ Object
235
236
237
|
# File 'lib/kafo/kafo_configure.rb', line 235
def help
self.class.help(invocation_path, self)
end
|
#logger ⇒ Object
173
174
175
|
# File 'lib/kafo/kafo_configure.rb', line 173
def logger
self.class.logger
end
|
#module(name) ⇒ Object
265
266
267
|
# File 'lib/kafo/kafo_configure.rb', line 265
def module(name)
modules.detect { |m| m.name == name }
end
|
#modules ⇒ Object
261
262
263
|
# File 'lib/kafo/kafo_configure.rb', line 261
def modules
config.modules.sort
end
|
#param(mod, name) ⇒ Object
269
270
271
|
# File 'lib/kafo/kafo_configure.rb', line 269
def param(mod, name)
config.param(mod, name)
end
|
#params ⇒ Object
239
240
241
242
243
244
|
# File 'lib/kafo/kafo_configure.rb', line 239
def params
@params ||= modules.map(&:params).flatten
rescue KafoParsers::ModuleName => e
puts e
self.class.exit(:unknown_module)
end
|
#request_config_reload ⇒ Object
273
274
275
|
# File 'lib/kafo/kafo_configure.rb', line 273
def request_config_reload
@config_reload_requested = true
end
|
#reset_params_cache ⇒ Object
250
251
252
253
|
# File 'lib/kafo/kafo_configure.rb', line 250
def reset_params_cache
@params = nil
params
end
|
#run(*args) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/kafo/kafo_configure.rb', line 177
def run(*args)
started_at = Time.now
logger.debug("Running installer with args #{args.inspect}")
if config.app[:verbose]
logger.notice("Running installer with log based terminal output at level #{config.app[:verbose_log_level].upcase}.")
logger.notice("Use -l to set the terminal output log level to ERROR, WARN, NOTICE, INFO, or DEBUG. See --full-help for definitions.")
end
super
ensure
logger.debug("Installer finished in #{Time.now - started_at} seconds")
end
|
#store ⇒ Object
169
170
171
|
# File 'lib/kafo/kafo_configure.rb', line 169
def store
self.class.store
end
|