hieracles 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +4 -0
- data/bin/hc +2 -0
- data/bin/hieracles +34 -0
- data/lib/hieracles.rb +1 -0
- data/lib/hieracles/commands.rb +59 -0
- data/lib/hieracles/formats/console.rb +26 -29
- data/lib/hieracles/formats/csv.rb +10 -0
- data/lib/hieracles/formats/json.rb +22 -6
- data/lib/hieracles/formats/rawyaml.rb +8 -0
- data/lib/hieracles/formats/yaml.rb +8 -0
- data/lib/hieracles/options/hieracles.rb +106 -0
- data/lib/hieracles/outputs/console.rb +40 -0
- data/lib/hieracles/registry.rb +62 -6
- data/spec/files/config.yml +1 -1
- data/spec/files/farm_modules/{dev.pp → dev/manifests/init.pp} +0 -0
- data/spec/files/farm_modules/{dev2.pp → dev2/manifests/init.pp} +0 -0
- data/spec/files/farm_modules/{dev4.pp → dev4/manifests/init.pp} +0 -0
- data/spec/files/modules/unused_module/manifests/init.pp +3 -0
- data/spec/lib/config_spec.rb +2 -2
- data/spec/lib/formats/console_spec.rb +0 -71
- data/spec/lib/registry_spec.rb +51 -1
- metadata +26 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1e246fada2e7e691f6a3c1f92ef9f3bae438ceb
|
4
|
+
data.tar.gz: a69b8fcd3a63ecb3df2d6064068f6a747c9c65fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 041246165f6e2474bfc6a134a07553cf4b1ae588a8a7842de33e1eb728ec90742db7beb32762f65f2f3cc36cc9cd20e9704a623c280d022e599cfff3563a77b5
|
7
|
+
data.tar.gz: 7f1ad137bf9f1c1c09f4bead0c8e9b8ae16ffca9668ca2ffd945d6ed38b237b3d6e0ac88d6bf18d3f74f673df2c8a73383c69e92d3247f036e724d21cffd98ed
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Hieracles Changelog
|
2
2
|
=======================
|
3
3
|
|
4
|
+
### 0.4.0 - 2016-12-30
|
5
|
+
- prepare a new command `hieracles` for preparing version 1.0.0
|
6
|
+
- refactoring of main lib to be less node-centric
|
7
|
+
- make farms list not to use cache by default
|
8
|
+
|
4
9
|
### 0.3.6 - 2016-04-27
|
5
10
|
- avoid abusive caching for all farms information
|
6
11
|
|
data/README.md
CHANGED
data/bin/hc
CHANGED
data/bin/hieracles
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'hieracles'
|
6
|
+
require 'hieracles/options/hieracles'
|
7
|
+
require 'hieracles/commands'
|
8
|
+
|
9
|
+
opt = Hieracles::Options::Hieracles.new(ARGV)
|
10
|
+
|
11
|
+
if opt.options.has_key? :version
|
12
|
+
puts Hieracles.version
|
13
|
+
exit(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
command = opt.payload.shift
|
17
|
+
arg = opt.payload.shift
|
18
|
+
extra = opt.payload
|
19
|
+
|
20
|
+
if !command || command == 'help'
|
21
|
+
puts Hieracles::Options::Hieracles.usage
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
config = Hieracles::Config.new opt.options
|
26
|
+
commands = Hieracles::Commands.new config
|
27
|
+
|
28
|
+
if commands.available.include? command
|
29
|
+
commands.run command, arg, extra
|
30
|
+
elsif commands.respond_to? command
|
31
|
+
commands.send command, arg, extra
|
32
|
+
else
|
33
|
+
puts 'Command not found.'
|
34
|
+
end
|
data/lib/hieracles.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
module Hieracles
|
3
|
+
class Commands
|
4
|
+
|
5
|
+
attr_reader :available
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
@formatter = Object.const_get("Hieracles::Formats::#{@config.format}")
|
10
|
+
@available = %w(info files params paths modules allparams facts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run(command, arg, extra)
|
14
|
+
if arg and arg[/\./] # poor way to detect if it is a fqdn
|
15
|
+
if Hieracles::Registry.nodes(@config).include? arg
|
16
|
+
puts call_node(command.to_sym, arg, extra)
|
17
|
+
else
|
18
|
+
puts "node '#{arg}' not found"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
if respond_to? command
|
22
|
+
send command.to_sym, arg, extra
|
23
|
+
else
|
24
|
+
# not a node
|
25
|
+
puts "'#{arg}' is not a FQDN."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def farms(arg, extra)
|
31
|
+
if arg
|
32
|
+
arg = [arg]
|
33
|
+
else
|
34
|
+
arg = []
|
35
|
+
end
|
36
|
+
formatter = @formatter.new nil
|
37
|
+
farms = Hieracles::Registry.farms_nodes(@config, 'local', true)
|
38
|
+
puts formatter.build_list(farms, nil, arg)
|
39
|
+
end
|
40
|
+
|
41
|
+
def modules(arg, extra)
|
42
|
+
if arg
|
43
|
+
arg = [arg]
|
44
|
+
else
|
45
|
+
arg = []
|
46
|
+
end
|
47
|
+
formatter = @formatter.new nil
|
48
|
+
modules = Hieracles::Registry.nodes_modules(@config, 'local', arg)
|
49
|
+
puts formatter.build_list(modules, nil, arg)
|
50
|
+
end
|
51
|
+
|
52
|
+
def call_node(command, fqdn, extra)
|
53
|
+
node = Hieracles::Node.new fqdn, @config
|
54
|
+
formatter = @formatter.new node
|
55
|
+
formatter.send command, extra
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -73,43 +73,40 @@ module Hieracles
|
|
73
73
|
@node.paths.join("\n") + "\n"
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
76
|
+
def show_params(without_common, args)
|
77
|
+
filter = args[0]
|
78
78
|
@node.files(without_common).each_with_index do |f, i|
|
79
79
|
output << format("#{COLORS[i]}\n", "[#{i}] #{f}")
|
80
80
|
@colors[f] = i
|
81
81
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
@node.params(without_common).each do |key, v|
|
83
|
+
if !filter || Regexp.new(filter).match(key)
|
84
|
+
if v[:overriden]
|
85
|
+
output << format(
|
86
|
+
"%s #{COLORS[7]} %s\n", "[-]",
|
87
|
+
key,
|
88
|
+
sanitize(value[:value])
|
89
|
+
)
|
90
|
+
value[:found_in].each do |val|
|
91
|
+
output << format(
|
92
|
+
" #{COLORS[8]}\n",
|
93
|
+
"[#{filecolor_index}] #{key} #{val[:value]}"
|
94
|
+
)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
filecolor_index = @colors[value[:file]]
|
98
|
+
filecolor = COLORS[filecolor_index]
|
99
|
+
output << format(
|
100
|
+
"#{filecolor} #{COLORS[7]} %s\n", "[#{filecolor_index}]",
|
101
|
+
key,
|
102
|
+
sanitize(value[:value])
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
89
106
|
end
|
90
107
|
output
|
91
108
|
end
|
92
109
|
|
93
|
-
def build_line_item(key, value)
|
94
|
-
if value[:overriden]
|
95
|
-
format("%s #{COLORS[7]} %s\n", "[-]", key, sanitize(value[:value]) ) +
|
96
|
-
build_overriden(key, value[:found_in])
|
97
|
-
else
|
98
|
-
filecolor_index = @colors[value[:file]]
|
99
|
-
filecolor = COLORS[filecolor_index]
|
100
|
-
format("#{filecolor} #{COLORS[7]} %s\n", "[#{filecolor_index}]", key, sanitize(value[:value]) )
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def build_overriden(key, found_in)
|
105
|
-
back = ''
|
106
|
-
found_in.each do |v|
|
107
|
-
filecolor_index = @colors[v[:file]]
|
108
|
-
back << format(" #{COLORS[8]}\n", "[#{filecolor_index}] #{key} #{v[:value]}")
|
109
|
-
end
|
110
|
-
back
|
111
|
-
end
|
112
|
-
|
113
110
|
def build_modules_line(key, value)
|
114
111
|
length = max_key_length(@node.modules) + 3
|
115
112
|
value_color = '%s'
|
@@ -48,6 +48,16 @@ module Hieracles
|
|
48
48
|
make_csv [key, value]
|
49
49
|
end
|
50
50
|
|
51
|
+
def build_list(hash, notifications, filter)
|
52
|
+
if filter[0]
|
53
|
+
hash.select! { |k, e| Regexp.new(filter[0]).match k }
|
54
|
+
end
|
55
|
+
hash.reduce([]) do |a, (k, v)|
|
56
|
+
a << make_csv([k, v.join(',')])
|
57
|
+
a
|
58
|
+
end.join()
|
59
|
+
end
|
60
|
+
|
51
61
|
private
|
52
62
|
|
53
63
|
def build_line(whatfile, key, value, overriden = '0')
|
@@ -5,11 +5,13 @@ module Hieracles
|
|
5
5
|
# format intended to be used for an api server
|
6
6
|
class Json < Hieracles::Format
|
7
7
|
|
8
|
-
def info(
|
8
|
+
def info(args)
|
9
|
+
filter(@node.info, args)
|
9
10
|
@node.info.merge(alerts).to_json
|
10
11
|
end
|
11
12
|
|
12
|
-
def facts(
|
13
|
+
def facts(args)
|
14
|
+
filter(@node.facts, args)
|
13
15
|
@node.facts.merge(alerts).to_json
|
14
16
|
end
|
15
17
|
|
@@ -34,10 +36,15 @@ module Hieracles
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def build_list(hash, notifications, filter)
|
37
|
-
|
38
|
-
'notifications' => notifications,
|
39
|
-
|
40
|
-
|
39
|
+
if filter[0]
|
40
|
+
{ 'notifications' => notifications,
|
41
|
+
'payload' => hash.select { |k, e| Regexp.new(filter[0]).match k }
|
42
|
+
}.to_json
|
43
|
+
else
|
44
|
+
{ 'notifications' => notifications,
|
45
|
+
'payload' => hash
|
46
|
+
}.to_json
|
47
|
+
end
|
41
48
|
end
|
42
49
|
|
43
50
|
private
|
@@ -49,6 +56,15 @@ module Hieracles
|
|
49
56
|
{}
|
50
57
|
end
|
51
58
|
end
|
59
|
+
|
60
|
+
def filter(what, args)
|
61
|
+
if args and args[0]
|
62
|
+
what.select! { |k, v| Regexp.new(args[0]).match(k.to_s) }
|
63
|
+
else
|
64
|
+
what
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
52
68
|
end
|
53
69
|
end
|
54
70
|
end
|
@@ -30,6 +30,14 @@ module Hieracles
|
|
30
30
|
def allparams(args)
|
31
31
|
@node.params_tree(false).to_yaml
|
32
32
|
end
|
33
|
+
|
34
|
+
def build_list(hash, notifications, filter)
|
35
|
+
if filter[0]
|
36
|
+
hash.select { |k, e| Regexp.new(filter[0]).match k }.to_yaml
|
37
|
+
else
|
38
|
+
hash.to_yaml
|
39
|
+
end
|
40
|
+
end
|
33
41
|
|
34
42
|
end
|
35
43
|
end
|
@@ -92,6 +92,14 @@ module Hieracles
|
|
92
92
|
added output, key, '', params
|
93
93
|
end
|
94
94
|
|
95
|
+
def build_list(hash, notifications, filter)
|
96
|
+
if filter[0]
|
97
|
+
hash.select { |k, e| Regexp.new(filter[0]).match k }.to_yaml
|
98
|
+
else
|
99
|
+
hash.to_yaml
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
95
103
|
private
|
96
104
|
|
97
105
|
def added(output, key, leaf, params)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'hieracles/optparse'
|
2
|
+
|
3
|
+
module Hieracles
|
4
|
+
module Options
|
5
|
+
class Hieracles < Hieracles::Optparse
|
6
|
+
|
7
|
+
def available_options
|
8
|
+
{
|
9
|
+
config: {
|
10
|
+
has_arg: true,
|
11
|
+
aliases: ['c', 'conf', 'config']
|
12
|
+
},
|
13
|
+
format: {
|
14
|
+
has_arg: true,
|
15
|
+
aliases: ['f', 'format']
|
16
|
+
},
|
17
|
+
params: {
|
18
|
+
has_arg: true,
|
19
|
+
aliases: ['p', 'params']
|
20
|
+
},
|
21
|
+
hierafile: {
|
22
|
+
has_arg: true,
|
23
|
+
aliases: ['h', 'hierafile']
|
24
|
+
},
|
25
|
+
basepath: {
|
26
|
+
has_arg: true,
|
27
|
+
aliases: ['b', 'basepath']
|
28
|
+
},
|
29
|
+
encpath: {
|
30
|
+
has_arg: true,
|
31
|
+
aliases: ['e', 'encpath']
|
32
|
+
},
|
33
|
+
version: {
|
34
|
+
has_arg: false,
|
35
|
+
aliases: ['v', 'version']
|
36
|
+
},
|
37
|
+
yaml_facts: {
|
38
|
+
has_arg: true,
|
39
|
+
aliases: ['y', 'yaml']
|
40
|
+
},
|
41
|
+
json_facts: {
|
42
|
+
has_arg: true,
|
43
|
+
aliases: ['j', 'json']
|
44
|
+
},
|
45
|
+
interactive: {
|
46
|
+
has_arg: false,
|
47
|
+
aliases: ['i', 'interactive']
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.usage
|
53
|
+
return <<-END
|
54
|
+
|
55
|
+
Usage: hieracles <command> [extra_args]
|
56
|
+
|
57
|
+
Available commands:
|
58
|
+
|
59
|
+
info <fqdn>
|
60
|
+
provides the farm, datacenter, country
|
61
|
+
associated to the given fqdn
|
62
|
+
An extra param can be added for filtering
|
63
|
+
eg. hieracles info <fqdn> timestamp
|
64
|
+
eg. hieracles info <fqdn> farm
|
65
|
+
|
66
|
+
files <fqdn|farm|module>
|
67
|
+
list all files containing params affecting this fqdn
|
68
|
+
(in more than commons)
|
69
|
+
|
70
|
+
paths <fqdn|farm|module>
|
71
|
+
list all file paths for files with params
|
72
|
+
|
73
|
+
modules <fqdn>
|
74
|
+
list modules included in the farm where the node is
|
75
|
+
|
76
|
+
params <fqdn>
|
77
|
+
list params for the node matching the fqdn
|
78
|
+
An extra filter string can be added to limit the list
|
79
|
+
use ruby regexp without the enclosing slashes
|
80
|
+
eg. hieracles params <fqdn> postfix.*version
|
81
|
+
eg. hieracles params <fqdn> '^postfix'
|
82
|
+
eg. hieracles params <fqdn> 'version$'
|
83
|
+
|
84
|
+
allparams <fqdn>
|
85
|
+
same as params but including the common.yaml params (huge)
|
86
|
+
Also accepts a search string
|
87
|
+
|
88
|
+
Extra args:
|
89
|
+
-f <plain|console|csv|yaml|rawyaml|json> default console
|
90
|
+
-p extraparam=what,anotherparam=this
|
91
|
+
-c <configfile>
|
92
|
+
-h <hierafile>
|
93
|
+
-b <basepath> default ./
|
94
|
+
-e <encdir>
|
95
|
+
-y <fact_file> - facts in yaml format
|
96
|
+
-j <fact_file> - facts in json format
|
97
|
+
-v just displays the version of Hieracles
|
98
|
+
-i - interactive mode
|
99
|
+
END
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
|
3
|
+
module Hieracles
|
4
|
+
module Outputs
|
5
|
+
# format accepting colors
|
6
|
+
# for display in the terminal
|
7
|
+
class Console
|
8
|
+
include Hieracles::Utils
|
9
|
+
|
10
|
+
COLORS = [
|
11
|
+
"\e[31m%s\e[0m",
|
12
|
+
"\e[32m%s\e[0m",
|
13
|
+
"\e[33m%s\e[0m",
|
14
|
+
"\e[34m%s\e[0m",
|
15
|
+
"\e[35m%s\e[0m",
|
16
|
+
"\e[37m%s\e[0m",
|
17
|
+
"\e[38m%s\e[0m",
|
18
|
+
"\e[36m%s\e[0m",
|
19
|
+
"\e[97m%s\e[0m",
|
20
|
+
"\e[35;1m%s\e[0m"
|
21
|
+
]
|
22
|
+
|
23
|
+
def initialize()
|
24
|
+
@colors = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def hash_list(headers, hash)
|
28
|
+
back = "\n"
|
29
|
+
if headers.count > 0
|
30
|
+
notifications.each do |v|
|
31
|
+
back << format("#{COLORS[9]}\n", "*** #{v.source}: #{v.message} ***")
|
32
|
+
end
|
33
|
+
back << "\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/hieracles/registry.rb
CHANGED
@@ -5,8 +5,8 @@ module Hieracles
|
|
5
5
|
|
6
6
|
def farms(config)
|
7
7
|
Dir.glob(format(config.classpath, '*')).sort.map do |f|
|
8
|
-
|
9
|
-
f.sub(
|
8
|
+
extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
|
9
|
+
f.sub(extract_path, "\\1")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -25,9 +25,11 @@ module Hieracles
|
|
25
25
|
def reload_nodes()
|
26
26
|
@_nodes_parameters = {}
|
27
27
|
@_nodes_modules = {}
|
28
|
+
@_farms_modules = {}
|
28
29
|
end
|
29
30
|
|
30
|
-
def nodes_parameters(config, env = 'production')
|
31
|
+
def nodes_parameters(config, env = 'production', reload = true)
|
32
|
+
reload_nodes if reload
|
31
33
|
@_nodes_parameters ||= {}
|
32
34
|
@_nodes_parameters[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
|
33
35
|
fqdn = File.basename(f, '.yaml')
|
@@ -36,7 +38,18 @@ module Hieracles
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
def
|
41
|
+
def farms_modules(config, env = 'production')
|
42
|
+
@_farms_modules ||= {}
|
43
|
+
regex = Regexp.new('\s*include\s*([-_a-z0-9]*)')
|
44
|
+
extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
|
45
|
+
@_farms_modules[env] ||= Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
|
46
|
+
name = f.sub(extract_path, "\\1")
|
47
|
+
a[name] = find_item(f, regex)
|
48
|
+
a
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def nodes_modules(config, env = 'production', filter = nil)
|
40
53
|
@_nodes_modules ||= {}
|
41
54
|
@_nodes_modules[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
|
42
55
|
YAML.load_file(f)['classes'].each do |cl|
|
@@ -50,17 +63,60 @@ module Hieracles
|
|
50
63
|
|
51
64
|
def farms_counted(config, env = 'production', reload = false)
|
52
65
|
reload_nodes if reload
|
66
|
+
extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
|
53
67
|
Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
|
54
|
-
|
55
|
-
name = f.sub(sub, "\\1")
|
68
|
+
name = f.sub(extract_path, "\\1")
|
56
69
|
a[name] = nodes_parameters(config, env).select { |k, v| v['farm'] == name }.length
|
57
70
|
a
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
74
|
+
def farms_nodes(config, env = 'production', reload = false, filter = nil)
|
75
|
+
reload_nodes if reload
|
76
|
+
extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
|
77
|
+
Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
|
78
|
+
name = f.sub(extract_path, "\\1")
|
79
|
+
a[name] = nodes_parameters(config, env).select { |k, v| v['farm'] == name }.keys
|
80
|
+
a
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
61
84
|
def modules_counted(config, env = 'production', reload = false)
|
62
85
|
reload_nodes if reload
|
63
86
|
Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
|
87
|
+
mod = File.basename(mod)
|
88
|
+
acc[mod] = farms_modules(config, env).select { |k, v| v.include? mod }.length
|
89
|
+
acc
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def modules_farms(config, env = 'production', reload = false)
|
94
|
+
reload_nodes if reload
|
95
|
+
Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
|
96
|
+
mod = File.basename(mod)
|
97
|
+
acc[mod] = farms_modules(config, env).select { |k, v| v.include? mod }.keys
|
98
|
+
acc
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def modules_nodes(config, env = 'production', reload = false, filter = nil)
|
103
|
+
reload_nodes if reload
|
104
|
+
Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
|
105
|
+
if filter and Regexp.new(filter[0]).match(mod)
|
106
|
+
mod = File.basename(mod)
|
107
|
+
farms = farms_modules(config, env).select { |k, v| v.include? mod }
|
108
|
+
# acc[mod] = farms.map { |f| farms_nodes(config, env, reload, f).values }
|
109
|
+
acc[mod] = farms
|
110
|
+
end
|
111
|
+
acc
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def find_item(file, regexp)
|
116
|
+
File.readlines(file).reduce([]) do |acc, line|
|
117
|
+
if regexp.match line
|
118
|
+
acc.push $1
|
119
|
+
end
|
64
120
|
acc
|
65
121
|
end
|
66
122
|
end
|
data/spec/files/config.yml
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/spec/lib/config_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Hieracles::Config do
|
|
6
6
|
let(:options) { { config: 'spec/files/config.yml' } }
|
7
7
|
let(:expected) do
|
8
8
|
{
|
9
|
-
classpath: File.expand_path('spec/files/farm_modules/%s.pp'),
|
9
|
+
classpath: File.expand_path('spec/files/farm_modules/%s/manifests/init.pp'),
|
10
10
|
modulepath: File.expand_path('spec/files/modules'),
|
11
11
|
hierafile: File.expand_path('spec/files/hiera.yaml')
|
12
12
|
}
|
@@ -31,7 +31,7 @@ describe Hieracles::Config do
|
|
31
31
|
end
|
32
32
|
let(:expected) do
|
33
33
|
{
|
34
|
-
classpath: File.expand_path('spec/files/farm_modules/%s.pp'),
|
34
|
+
classpath: File.expand_path('spec/files/farm_modules/%s/manifests/init.pp'),
|
35
35
|
modulepath: File.expand_path('spec/files/modules'),
|
36
36
|
hierafile: File.expand_path('spec/files/hiera.yaml')
|
37
37
|
}
|
@@ -63,77 +63,6 @@ describe Hieracles::Formats::Console do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
describe ".build_head" do
|
67
|
-
let(:expected) { "[-] (merged)\n\e[31m[0] path1\e[0m\n\e[32m[1] path2\e[0m\n\n" }
|
68
|
-
before {
|
69
|
-
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
70
|
-
}
|
71
|
-
it "outputs proper text" do
|
72
|
-
expect(console_format.send :build_head, true).to eq expected
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe ".build_params_line" do
|
77
|
-
context "when not merged" do
|
78
|
-
let(:expected) {
|
79
|
-
"[-] \e[36mparams.this.var\e[0m value1\n" +
|
80
|
-
" \e[97m[0] params.this.var value1\e[0m\n" +
|
81
|
-
" \e[97m[1] params.this.var value2\e[0m\n"
|
82
|
-
}
|
83
|
-
let(:params) {
|
84
|
-
{
|
85
|
-
file: '-',
|
86
|
-
value: 'value1',
|
87
|
-
overriden: true,
|
88
|
-
found_in: [
|
89
|
-
{ file: 'path1', value: 'value1' },
|
90
|
-
{ file: 'path2', value: 'value2' }
|
91
|
-
]
|
92
|
-
}
|
93
|
-
}
|
94
|
-
before {
|
95
|
-
console_format.instance_variable_set(:@colors,
|
96
|
-
{'path1' => 0, 'path2' => 1}
|
97
|
-
)
|
98
|
-
}
|
99
|
-
it "outputs proper text" do
|
100
|
-
expect(console_format.send :build_params_line,
|
101
|
-
"params.this.var",
|
102
|
-
params,
|
103
|
-
nil).to eq expected
|
104
|
-
end
|
105
|
-
end
|
106
|
-
context "when merged" do
|
107
|
-
let(:expected) {
|
108
|
-
"[-] \e[36mparams.this.var\e[0m [\"value1\", \"value2\"]\n"+
|
109
|
-
" \e[97m[0] params.this.var [\"value1\"]\e[0m\n"+
|
110
|
-
" \e[97m[1] params.this.var [\"value2\"]\e[0m\n"
|
111
|
-
}
|
112
|
-
let(:params) {
|
113
|
-
{
|
114
|
-
file: '-',
|
115
|
-
value: ['value1','value2'],
|
116
|
-
overriden: true,
|
117
|
-
found_in: [
|
118
|
-
{ file: 'path1', value: ['value1'] },
|
119
|
-
{ file: 'path2', value: ['value2'] }
|
120
|
-
]
|
121
|
-
}
|
122
|
-
}
|
123
|
-
before {
|
124
|
-
console_format.instance_variable_set(:@colors,
|
125
|
-
{'path1' => 0, 'path2' => 1}
|
126
|
-
)
|
127
|
-
}
|
128
|
-
it "outputs proper text" do
|
129
|
-
expect(console_format.send :build_params_line,
|
130
|
-
"params.this.var",
|
131
|
-
params,
|
132
|
-
nil).to eq expected
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
66
|
describe ".build_modules_line" do
|
138
67
|
before {
|
139
68
|
allow(node).to receive(:modules).and_return(
|
data/spec/lib/registry_spec.rb
CHANGED
@@ -19,6 +19,27 @@ describe Hieracles::Registry do
|
|
19
19
|
it { expect(Hieracles::Registry.farms config).to eq expected }
|
20
20
|
end
|
21
21
|
|
22
|
+
describe '.farm_modules' do
|
23
|
+
let(:config) { Hieracles::Config.new options }
|
24
|
+
let(:expected) { {
|
25
|
+
'dev' => [
|
26
|
+
"fake_module",
|
27
|
+
"fake_module2",
|
28
|
+
"fake_module3"
|
29
|
+
],
|
30
|
+
'dev2' => [
|
31
|
+
"fake_module",
|
32
|
+
"fake_module2",
|
33
|
+
"fake_module4"
|
34
|
+
],
|
35
|
+
'dev4' => [
|
36
|
+
"faux_module1",
|
37
|
+
"faux_module2"
|
38
|
+
]
|
39
|
+
} }
|
40
|
+
it { expect(Hieracles::Registry.farms_modules config).to eq expected }
|
41
|
+
end
|
42
|
+
|
22
43
|
describe '.nodes' do
|
23
44
|
let(:expected) { [
|
24
45
|
'server.example.com',
|
@@ -36,7 +57,8 @@ describe Hieracles::Registry do
|
|
36
57
|
'fake_module2',
|
37
58
|
'fake_module3',
|
38
59
|
'faux_module1',
|
39
|
-
|
60
|
+
'faux_module2',
|
61
|
+
'unused_module'
|
40
62
|
] }
|
41
63
|
let(:config) { Hieracles::Config.new options }
|
42
64
|
it { expect(Hieracles::Registry.modules config).to eq expected }
|
@@ -83,5 +105,33 @@ describe Hieracles::Registry do
|
|
83
105
|
it { expect(Hieracles::Registry.farms_counted config).to eq expected }
|
84
106
|
end
|
85
107
|
|
108
|
+
describe '.modules_counted' do
|
109
|
+
let(:expected) {
|
110
|
+
{
|
111
|
+
'fake_module' => 2,
|
112
|
+
'fake_module2' => 2,
|
113
|
+
'fake_module3' => 1,
|
114
|
+
'faux_module1' => 1,
|
115
|
+
'faux_module2' => 1,
|
116
|
+
'unused_module' => 0
|
117
|
+
}
|
118
|
+
}
|
119
|
+
let(:config) { Hieracles::Config.new options }
|
120
|
+
it { expect(Hieracles::Registry.modules_counted config).to eq expected }
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.find_item' do
|
124
|
+
let(:config) { Hieracles::Config.new options }
|
125
|
+
let(:expected) {
|
126
|
+
[
|
127
|
+
'fake_module',
|
128
|
+
'fake_module2',
|
129
|
+
'fake_module3'
|
130
|
+
]
|
131
|
+
}
|
132
|
+
let(:file) { format(config.classpath, 'dev') }
|
133
|
+
let(:regex) { Regexp.new('\s*include\s*([-_a-z0-9]*)') }
|
134
|
+
it { expect(Hieracles::Registry.find_item file, regex).to eq expected }
|
135
|
+
end
|
86
136
|
|
87
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hieracles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.12.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 0.12.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +140,7 @@ description: CLI tool for Hiera parameters visualization and analysis.
|
|
140
140
|
email:
|
141
141
|
- mose@gandi.net
|
142
142
|
executables:
|
143
|
+
- hieracles
|
143
144
|
- hc
|
144
145
|
- ppdb
|
145
146
|
extensions: []
|
@@ -150,11 +151,13 @@ files:
|
|
150
151
|
- LICENSE
|
151
152
|
- README.md
|
152
153
|
- bin/hc
|
154
|
+
- bin/hieracles
|
153
155
|
- bin/ppdb
|
154
156
|
- hc.1
|
155
157
|
- lib/hieracles.rb
|
156
158
|
- lib/hieracles/actions.rb
|
157
159
|
- lib/hieracles/actions/modules.rb
|
160
|
+
- lib/hieracles/commands.rb
|
158
161
|
- lib/hieracles/config.rb
|
159
162
|
- lib/hieracles/format.rb
|
160
163
|
- lib/hieracles/formats/console.rb
|
@@ -168,8 +171,10 @@ files:
|
|
168
171
|
- lib/hieracles/node.rb
|
169
172
|
- lib/hieracles/notification.rb
|
170
173
|
- lib/hieracles/options/hc.rb
|
174
|
+
- lib/hieracles/options/hieracles.rb
|
171
175
|
- lib/hieracles/options/ppdb.rb
|
172
176
|
- lib/hieracles/optparse.rb
|
177
|
+
- lib/hieracles/outputs/console.rb
|
173
178
|
- lib/hieracles/puppetdb.rb
|
174
179
|
- lib/hieracles/puppetdb/apierror.rb
|
175
180
|
- lib/hieracles/puppetdb/client.rb
|
@@ -189,9 +194,9 @@ files:
|
|
189
194
|
- spec/files/enc/server4.example.com.yaml
|
190
195
|
- spec/files/facts.json
|
191
196
|
- spec/files/facts.yaml
|
192
|
-
- spec/files/farm_modules/dev.pp
|
193
|
-
- spec/files/farm_modules/dev2.pp
|
194
|
-
- spec/files/farm_modules/dev4.pp
|
197
|
+
- spec/files/farm_modules/dev/manifests/init.pp
|
198
|
+
- spec/files/farm_modules/dev2/manifests/init.pp
|
199
|
+
- spec/files/farm_modules/dev4/manifests/init.pp
|
195
200
|
- spec/files/hiera.yaml
|
196
201
|
- spec/files/hiera_columns.yaml
|
197
202
|
- spec/files/hiera_deep.yaml
|
@@ -203,6 +208,7 @@ files:
|
|
203
208
|
- spec/files/modules/fake_module3/manifests/init.pp
|
204
209
|
- spec/files/modules/faux_module1/manifests/init.pp
|
205
210
|
- spec/files/modules/faux_module2/manifests/init.pp
|
211
|
+
- spec/files/modules/unused_module/manifests/init.pp
|
206
212
|
- spec/files/params/common/common.yml
|
207
213
|
- spec/files/params/farm/dev.yaml
|
208
214
|
- spec/files/params/farm_datacenter/dev_dc1.yaml
|
@@ -260,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
266
|
version: '0'
|
261
267
|
requirements: []
|
262
268
|
rubyforge_project:
|
263
|
-
rubygems_version: 2.5.
|
269
|
+
rubygems_version: 2.5.2
|
264
270
|
signing_key:
|
265
271
|
specification_version: 4
|
266
272
|
summary: CLI tool for Hiera parameters visualization.
|
@@ -286,13 +292,14 @@ test_files:
|
|
286
292
|
- spec/files/enc/server.example.com.yaml
|
287
293
|
- spec/files/enc/server4.example.com.yaml
|
288
294
|
- spec/files/enc/server3.example.com.yaml
|
289
|
-
- spec/files/farm_modules/
|
290
|
-
- spec/files/farm_modules/
|
291
|
-
- spec/files/farm_modules/
|
295
|
+
- spec/files/farm_modules/dev2/manifests/init.pp
|
296
|
+
- spec/files/farm_modules/dev4/manifests/init.pp
|
297
|
+
- spec/files/farm_modules/dev/manifests/init.pp
|
292
298
|
- spec/files/hiera_yamlbackend_notfound.yaml
|
293
299
|
- spec/files/hiera.yaml
|
294
300
|
- spec/files/modules/fake_module3/manifests/init.pp
|
295
301
|
- spec/files/modules/fake_module/manifests/init.pp
|
302
|
+
- spec/files/modules/unused_module/manifests/init.pp
|
296
303
|
- spec/files/modules/fake_module2/manifests/init.pp
|
297
304
|
- spec/files/modules/faux_module2/manifests/init.pp
|
298
305
|
- spec/files/modules/faux_module1/manifests/init.pp
|