Module: Hieracles::Registry

Extended by:
Registry
Included in:
Registry
Defined in:
lib/hieracles/registry.rb

Instance Method Summary collapse

Instance Method Details

#farms(config) ⇒ Object



6
7
8
9
10
11
# File 'lib/hieracles/registry.rb', line 6

def farms(config)
	Dir.glob(format(config.classpath, '*')).sort.map do |f|
     extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
     f.sub(extract_path, "\\1")
   end
end

#farms_counted(config, env = 'production', reload = false) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/hieracles/registry.rb', line 64

def farms_counted(config, env = 'production', reload = false)
  reload_nodes if reload
  extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
  Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
    name = f.sub(extract_path, "\\1")
    a[name] = nodes_parameters(config, env).select { |k, v| v['farm'] == name }.length
    a
  end
end

#farms_modules(config, env = 'production') ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/hieracles/registry.rb', line 41

def farms_modules(config, env = 'production')
  @_farms_modules ||= {}
  regex = Regexp.new('\s*include\s*([-_a-z0-9]*)')
  extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
  @_farms_modules[env] ||= Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
    name = f.sub(extract_path, "\\1")
    a[name] = find_item(f, regex)
    a
  end
end

#farms_nodes(config, env = 'production', reload = false, filter = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/hieracles/registry.rb', line 74

def farms_nodes(config, env = 'production', reload = false, filter = nil)
  reload_nodes if reload
  extract_path = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
  Dir.glob(format(config.classpath, '*')).sort.reduce({}) do |a, f|
    name = f.sub(extract_path, "\\1")
    a[name] = nodes_parameters(config, env).select { |k, v| v['farm'] == name }.keys
    a
  end
end

#find_item(file, regexp) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/hieracles/registry.rb', line 115

def find_item(file, regexp)
  File.readlines(file).reduce([]) do |acc, line|
    if regexp.match line
      acc.push $1
    end
    acc
  end
end

#modules(config) ⇒ Object



19
20
21
22
23
# File 'lib/hieracles/registry.rb', line 19

def modules(config)
  Dir.glob(File.join(config.modulepath, '*')).sort.map do |f|
    File.basename(f)
  end
end

#modules_counted(config, env = 'production', reload = false) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/hieracles/registry.rb', line 84

def modules_counted(config, env = 'production', reload = false)
  reload_nodes if reload
  Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
    mod = File.basename(mod)
    acc[mod] = farms_modules(config, env).select { |k, v| v.include? mod }.length
    acc
  end
end

#modules_farms(config, env = 'production', reload = false) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/hieracles/registry.rb', line 93

def modules_farms(config, env = 'production', reload = false)
  reload_nodes if reload
  Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
    mod = File.basename(mod)
    acc[mod] = farms_modules(config, env).select { |k, v| v.include? mod }.keys
    acc
  end
end

#modules_nodes(config, env = 'production', reload = false, filter = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hieracles/registry.rb', line 102

def modules_nodes(config, env = 'production', reload = false, filter = nil)
  reload_nodes if reload
  Dir.glob(File.join(config.modulepath, '*')).sort.reduce({}) do |acc, mod|
    if filter and Regexp.new(filter[0]).match(mod)
      mod = File.basename(mod)
      farms = farms_modules(config, env).select { |k, v| v.include? mod }
      # acc[mod] = farms.map { |f| farms_nodes(config, env, reload, f).values }
      acc[mod] = farms
    end
    acc
  end
end

#nodes(config) ⇒ Object



13
14
15
16
17
# File 'lib/hieracles/registry.rb', line 13

def nodes(config)
  Dir.glob(File.join(config.encpath, '*.yaml')).sort.map do |f|
    File.basename(f, '.yaml')
  end
end

#nodes_modules(config, env = 'production', filter = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hieracles/registry.rb', line 52

def nodes_modules(config, env = 'production', filter = nil)
  @_nodes_modules ||= {}
  @_nodes_modules[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
    YAML.load_file(f)['classes'].each do |cl|

    end
    fqdn = File.basename(f, '.yaml')
    a[fqdn] = YAML.load_file(f)['parameters']
    a
  end
end

#nodes_parameters(config, env = 'production', reload = true) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/hieracles/registry.rb', line 31

def nodes_parameters(config, env = 'production', reload = true)
  reload_nodes if reload
  @_nodes_parameters ||= {}
  @_nodes_parameters[env] ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.reduce({}) do |a, f|
    fqdn = File.basename(f, '.yaml')
    a[fqdn] = YAML.load_file(f)['parameters']
    a
  end
end

#reload_nodesObject



25
26
27
28
29
# File 'lib/hieracles/registry.rb', line 25

def reload_nodes()
  @_nodes_parameters = {}
  @_nodes_modules = {}
  @_farms_modules = {}
end