kafo 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kafo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +192 -0
- data/bin/kafo-configure +1 -4
- data/bin/kafo-export-params +92 -68
- data/bin/kafofy +1 -1
- data/lib/kafo/condition.rb +25 -0
- data/lib/kafo/configuration.rb +104 -102
- data/lib/kafo/doc_parser.rb +129 -0
- data/lib/kafo/exceptions.rb +14 -3
- data/lib/kafo/help_builder.rb +3 -0
- data/lib/kafo/help_builders/advanced.rb +19 -0
- data/lib/kafo/help_builders/base.rb +82 -0
- data/lib/kafo/help_builders/basic.rb +12 -0
- data/lib/kafo/hooking.rb +37 -0
- data/lib/kafo/kafo_configure.rb +270 -243
- data/lib/kafo/logger.rb +54 -52
- data/lib/kafo/param.rb +83 -60
- data/lib/kafo/param_builder.rb +69 -45
- data/lib/kafo/param_group.rb +27 -0
- data/lib/kafo/params/array.rb +14 -12
- data/lib/kafo/params/boolean.rb +17 -15
- data/lib/kafo/params/integer.rb +11 -9
- data/lib/kafo/params/password.rb +44 -38
- data/lib/kafo/params/string.rb +8 -2
- data/lib/kafo/password_manager.rb +34 -32
- data/lib/kafo/progress_bar.rb +51 -48
- data/lib/kafo/progress_bars/black_white.rb +11 -9
- data/lib/kafo/progress_bars/colored.rb +20 -18
- data/lib/kafo/puppet_command.rb +34 -36
- data/lib/kafo/puppet_module.rb +92 -68
- data/lib/kafo/puppet_module_parser.rb +63 -60
- data/lib/kafo/string_helper.rb +19 -15
- data/lib/kafo/system_checker.rb +20 -18
- data/lib/kafo/validator.rb +49 -47
- data/lib/kafo/version.rb +1 -1
- data/lib/kafo/wizard.rb +135 -95
- metadata +28 -6
data/lib/kafo/puppet_command.rb
CHANGED
@@ -1,45 +1,43 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@options = options.push("--modulepath #{File.expand_path(modules_path)}")
|
10
|
-
@logger = KafoConfigure.logger
|
11
|
-
end
|
2
|
+
module Kafo
|
3
|
+
class PuppetCommand
|
4
|
+
def initialize(command, options = [])
|
5
|
+
@command = command
|
6
|
+
@options = options.push("--modulepath #{modules_path}")
|
7
|
+
@logger = KafoConfigure.logger
|
8
|
+
end
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
def custom_answer_file
|
11
|
+
KafoConfigure.temp_config_file.nil? ? '' : "$kafo_answer_file=\"#{KafoConfigure.temp_config_file}\""
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def add_progress
|
15
|
+
KafoConfigure.verbose ? '' : "$kafo_add_progress=true"
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
def command
|
19
|
+
result = [
|
20
|
+
"echo '$kafo_config_file=\"#{KafoConfigure.config_file}\" #{custom_answer_file} #{add_progress} #{@command}'",
|
21
|
+
'|',
|
22
|
+
"RUBYLIB=#{["#{KafoConfigure.gem_root}/modules", ENV['RUBYLIB']].join(File::PATH_SEPARATOR)}",
|
23
|
+
"puppet apply #{@options.join(' ')} #{@suffix}",
|
24
|
+
].join(' ')
|
25
|
+
@logger.debug result
|
26
|
+
result
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
def append(suffix)
|
30
|
+
@suffix = suffix
|
31
|
+
self
|
32
|
+
end
|
36
33
|
|
37
|
-
|
34
|
+
private
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
def modules_path
|
37
|
+
[
|
38
|
+
KafoConfigure.modules_dir,
|
39
|
+
KafoConfigure.kafo_modules_dir,
|
40
|
+
].join(':')
|
41
|
+
end
|
44
42
|
end
|
45
43
|
end
|
data/lib/kafo/puppet_module.rb
CHANGED
@@ -4,90 +4,114 @@ require 'kafo/param_builder'
|
|
4
4
|
require 'kafo/puppet_module_parser'
|
5
5
|
require 'kafo/validator'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
module Kafo
|
8
|
+
class PuppetModule
|
9
|
+
PRIMARY_GROUP_NAME = 'Parameters'
|
10
|
+
|
11
|
+
attr_reader :name, :params, :dir_name, :class_name, :manifest_name, :manifest_path,
|
12
|
+
:groups
|
13
|
+
|
14
|
+
def initialize(name, parser = PuppetModuleParser)
|
15
|
+
@name = name
|
16
|
+
@dir_name = get_dir_name
|
17
|
+
@manifest_name = get_manifest_name
|
18
|
+
@class_name = get_class_name
|
19
|
+
@params = []
|
20
|
+
@manifest_path = File.join(KafoConfigure.root_dir, '/modules/', module_manifest_path)
|
21
|
+
@parser = parser
|
22
|
+
@validations = []
|
23
|
+
@logger = KafoConfigure.logger
|
24
|
+
@groups = {}
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
def enabled?
|
28
|
+
@enabled.nil? ? @enabled = KafoConfigure.config.module_enabled?(self) : @enabled
|
29
|
+
end
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
def disable
|
32
|
+
@enabled = false
|
33
|
+
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
def enable
|
36
|
+
@enabled = true
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
def parse(builder_klass = ParamBuilder)
|
40
|
+
@params = []
|
41
|
+
raw_data = @parser.parse(manifest_path)
|
42
|
+
builder = builder_klass.new(self, raw_data)
|
43
|
+
@validations = raw_data[:validations]
|
39
44
|
|
40
|
-
|
41
|
-
|
45
|
+
builder.validate
|
46
|
+
@params = builder.build_params
|
47
|
+
@groups = builder.build_param_groups(@params)
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
self
|
50
|
+
rescue ConfigurationException => e
|
51
|
+
@logger.error "Unable to continue because of: #{e.message}"
|
52
|
+
KafoConfigure.exit(:manifest_error)
|
53
|
+
end
|
54
|
+
|
55
|
+
def primary_parameter_group
|
56
|
+
@groups.detect { |g| g.formatted_name == PRIMARY_GROUP_NAME } || dummy_primary_group
|
57
|
+
end
|
49
58
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
def other_parameter_groups
|
60
|
+
@groups.select { |g| g.formatted_name != PRIMARY_GROUP_NAME }
|
61
|
+
end
|
62
|
+
|
63
|
+
def validations(param = nil)
|
64
|
+
if param.nil?
|
65
|
+
@validations
|
66
|
+
else
|
67
|
+
@validations.select do |validation|
|
68
|
+
validation.arguments.map(&:to_s).include?("$#{param.name}")
|
69
|
+
end
|
56
70
|
end
|
57
71
|
end
|
58
|
-
end
|
59
72
|
|
60
|
-
|
61
|
-
|
62
|
-
|
73
|
+
def params_hash
|
74
|
+
Hash[params.map { |param| [param.name, param.value] }]
|
75
|
+
end
|
63
76
|
|
64
|
-
|
65
|
-
|
66
|
-
|
77
|
+
def <=> o
|
78
|
+
self.name <=> o.name
|
79
|
+
end
|
67
80
|
|
68
|
-
|
81
|
+
private
|
69
82
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
83
|
+
# used when user haven't specified any primary group by name, we create a new group
|
84
|
+
# that holds all other groups as children, if we have no other groups (no children)
|
85
|
+
# we set all parameters that this module hold
|
86
|
+
def dummy_primary_group
|
87
|
+
group = ParamGroup.new(PRIMARY_GROUP_NAME)
|
88
|
+
other_parameter_groups.each { |child| group.add_child(child) }
|
89
|
+
@params.each { |p| group.add_param(p) } if group.children.empty?
|
90
|
+
group
|
91
|
+
end
|
74
92
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
93
|
+
# mapping from configuration with stringified keys
|
94
|
+
def mapping
|
95
|
+
@mapping ||= Hash[KafoConfigure.config.app[:mapping].map { |k, v| [k.to_s, v] }]
|
96
|
+
end
|
79
97
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
98
|
+
# custom module directory name
|
99
|
+
def get_dir_name
|
100
|
+
mapping[name].nil? ? name : mapping[name][:dir_name]
|
101
|
+
end
|
84
102
|
|
85
|
-
|
86
|
-
|
87
|
-
|
103
|
+
# custom manifest filename without .pp extension
|
104
|
+
def get_manifest_name
|
105
|
+
mapping[name].nil? ? 'init' : mapping[name][:manifest_name]
|
106
|
+
end
|
88
107
|
|
89
|
-
|
90
|
-
|
91
|
-
|
108
|
+
def get_class_name
|
109
|
+
manifest_name == 'init' ? name : "#{dir_name}::#{manifest_name}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def module_manifest_path
|
113
|
+
"#{dir_name}/manifests/#{manifest_name}.pp"
|
114
|
+
end
|
92
115
|
|
116
|
+
end
|
93
117
|
end
|
@@ -1,74 +1,77 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'puppet'
|
3
|
-
require '
|
4
|
-
require 'rdoc/markup' # required for RDoc < 0.9.5
|
5
|
-
require 'rdoc/markup/parser' # required for RDoc < 0.9.5
|
3
|
+
require 'kafo/doc_parser'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module Kafo
|
6
|
+
# Based on ideas from puppet-parse by Johan van den Dorpe
|
7
|
+
# we don't build any tree structure since e.g. params from doc does not
|
8
|
+
# have to be defined in puppet DSL and vice versa, we just gather all info
|
9
|
+
# we can read from the whole manifest
|
10
|
+
class PuppetModuleParser
|
11
|
+
def self.parse(file)
|
12
|
+
content = new(file)
|
13
|
+
docs = content.docs
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
data = {
|
16
|
+
:values => content.values,
|
17
|
+
:validations => content.validations
|
18
|
+
}
|
19
|
+
data[:parameters] = data[:values].keys
|
20
|
+
data.merge!(docs)
|
21
|
+
data
|
22
|
+
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
def initialize(file)
|
25
|
+
@file = file
|
26
|
+
raise ModuleName, "File not found #{file}, check you answer file" unless File.exists?(file)
|
27
|
+
parser = Puppet::Parser::Parser.new('production')
|
28
|
+
values = Puppet.settings.instance_variable_get('@values')
|
29
|
+
values[:production][:confdir] ||= '/' # just some stubbing
|
30
|
+
parser.import(@file)
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
# Find object corresponding to class defined in init.pp in list of hostclasses
|
33
|
+
parser.environment.known_resource_types.hostclasses.each do |ast_objects|
|
34
|
+
ast_type = ast_objects.last
|
35
|
+
@object = ast_type if ast_type.file == file
|
36
|
+
end
|
37
|
+
# Find object in list of definitions
|
38
|
+
parser.environment.known_resource_types.definitions.each do |ast_objects|
|
39
|
+
ast_type = ast_objects.last
|
40
|
+
@object = ast_type.last if ast_type.last.file == file
|
41
|
+
end
|
33
42
|
end
|
34
|
-
end
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
def klass
|
45
|
-
@object.name if @object.class.respond_to?(:name)
|
46
|
-
end
|
44
|
+
# TODO - store parsed object type (Puppet::Parser::AST::Variable must be dumped later)
|
45
|
+
def values
|
46
|
+
parameters = {}
|
47
|
+
arguments = @object.respond_to?(:arguments) ? @object.arguments : {}
|
48
|
+
arguments.each { |k, v| parameters[k] = v.respond_to?(:value) ? v.value : nil }
|
49
|
+
parameters
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
def validations(param = nil)
|
53
|
+
@object.code.select { |stmt| stmt.is_a?(Puppet::Parser::AST::Function) && stmt.name =~ /^validate_/ }
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
docs[key] = item.parts.first.parts.map!(&:strip)
|
56
|
+
# returns data in following form
|
57
|
+
# {
|
58
|
+
# :docs => { $param1 => 'documentation without types and conditions'}
|
59
|
+
# :types => { $param1 => 'boolean'},
|
60
|
+
# :groups => { $param1 => ['Parameters', 'Advanced']},
|
61
|
+
# :conditions => { $param1 => '$db_type == "mysql"'},
|
62
|
+
# }
|
63
|
+
def docs
|
64
|
+
data = { :docs => {}, :types => {}, :groups => {}, :conditions => {} }
|
65
|
+
if @object.nil?
|
66
|
+
raise DocParseError, "no documentation found for manifest #{@file}, parsing error?"
|
67
|
+
elsif !@object.doc.nil?
|
68
|
+
parser = DocParser.new(@object.doc).parse
|
69
|
+
data[:docs] = parser.docs
|
70
|
+
data[:groups] = parser.groups
|
71
|
+
data[:types] = parser.types
|
72
|
+
data[:conditions] = parser.conditions
|
70
73
|
end
|
74
|
+
data
|
71
75
|
end
|
72
|
-
docs
|
73
76
|
end
|
74
77
|
end
|
data/lib/kafo/string_helper.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module
|
3
|
-
|
4
|
-
string
|
5
|
-
|
6
|
-
|
2
|
+
module Kafo
|
3
|
+
module StringHelper
|
4
|
+
def dashize(string)
|
5
|
+
string.tr('_', '-')
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
string.tr('-', '_')
|
10
|
-
end
|
11
|
-
alias :u :underscore
|
8
|
+
alias :d :dashize
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def underscore(string)
|
11
|
+
string.tr('-', '_')
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :u :underscore
|
15
|
+
|
16
|
+
def with_prefix(param)
|
17
|
+
prefix = KafoConfigure.config.app[:no_prefix] ? '' : "#{d(param.module_name)}-"
|
18
|
+
"#{prefix}#{d(param.name)}"
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
def parametrize(param)
|
22
|
+
"--#{with_prefix(param)}"
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
data/lib/kafo/system_checker.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(path)
|
9
|
-
@checkers = Dir.glob(path)
|
10
|
-
end
|
3
|
+
module Kafo
|
4
|
+
class SystemChecker
|
5
|
+
def self.check
|
6
|
+
new(File.join(KafoConfigure.root_dir, 'checks', '*')).check
|
7
|
+
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def initialize(path)
|
10
|
+
@checkers = Dir.glob(path)
|
11
|
+
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
logger.debug "Executing checker: #{checker}"
|
19
|
-
stdout = `#{checker}`
|
20
|
-
logger.error stdout unless stdout.empty?
|
21
|
-
$?.exitstatus == 0
|
13
|
+
def logger
|
14
|
+
Logging::logger['checks']
|
22
15
|
end
|
23
16
|
|
24
|
-
|
17
|
+
def check
|
18
|
+
@checkers.map! do |checker|
|
19
|
+
logger.debug "Executing checker: #{checker}"
|
20
|
+
stdout = `#{checker}`
|
21
|
+
logger.error stdout unless stdout.empty?
|
22
|
+
$?.exitstatus == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
@checkers.all?
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|