coral_core 0.2.19 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/coral_core.rb DELETED
@@ -1,260 +0,0 @@
1
-
2
- #*******************************************************************************
3
- # Coral Core Library
4
- #
5
- # This provides core data elements and utilities used in the Coral gems.
6
- #
7
- # Author:: Adrian Webb (mailto:adrian.webb@coraltech.net)
8
- # License:: GPLv3
9
-
10
- #-------------------------------------------------------------------------------
11
- # Global namespace
12
-
13
- module Kernel
14
-
15
- def dbg(data, label = '')
16
- require 'pp'
17
-
18
- puts '>>----------------------'
19
- unless label.empty?
20
- puts label
21
- puts '---'
22
- end
23
- pp data
24
- puts '<<'
25
- end
26
-
27
- #---
28
-
29
- def locate(command)
30
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
31
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
32
- exts.each do |ext|
33
- exe = File.join(path, "#{command}#{ext}")
34
- return exe if File.executable?(exe)
35
- end
36
- end
37
- return nil
38
- end
39
- end
40
-
41
- #-------------------------------------------------------------------------------
42
- # Properties and
43
-
44
- home = File.dirname(__FILE__)
45
- dependencies = File.join(home, 'dependency')
46
-
47
- git_location = locate('git')
48
-
49
- #-------------------------------------------------------------------------------
50
-
51
- $:.unshift(home) unless
52
- $:.include?(home) || $:.include?(File.expand_path(home))
53
-
54
- #---
55
-
56
- require 'rubygems'
57
-
58
- #---
59
-
60
- begin
61
- require 'log4r'
62
-
63
- rescue LoadError
64
- log4r_lib = File.join(dependencies, 'log4r', 'lib')
65
-
66
- $:.push(log4r_lib)
67
- require File.join(log4r_lib, 'log4r.rb')
68
- end
69
-
70
- #---
71
-
72
- begin
73
- require 'deep_merge'
74
-
75
- rescue LoadError
76
- deep_merge_lib = File.join(dependencies, 'deep_merge', 'lib')
77
-
78
- $:.push(deep_merge_lib)
79
- require File.join(deep_merge_lib, 'deep_merge.rb')
80
- end
81
-
82
- #---
83
-
84
- begin
85
- require 'json'
86
-
87
- rescue LoadError
88
- json_lib = File.join(dependencies, 'json', 'lib')
89
-
90
- $:.push(json_lib)
91
- require File.join(json_lib, 'json.rb')
92
- end
93
-
94
- #---
95
-
96
- if git_location
97
- begin
98
- require 'git'
99
-
100
- rescue LoadError
101
- git_lib = File.join(dependencies, 'git', 'lib')
102
-
103
- $:.push(git_lib)
104
- require File.join(git_lib, 'git.rb')
105
- end
106
- end
107
-
108
- #---
109
-
110
- # Include pre core utilities (no internal dependencies)
111
- [ :data, :disk ].each do |name|
112
- require File.join('coral_core', 'util', name.to_s + ".rb")
113
- end
114
-
115
- if git_location
116
- require File.join('coral_core', 'util', 'git.rb')
117
-
118
- # Include Git overrides
119
- Dir.glob(File.join(home, 'coral_core', 'util', 'git', '*.rb')).each do |file|
120
- require file
121
- end
122
- end
123
-
124
- # Include core
125
- [ :config, :interface, :core, :resource, :template ].each do |name|
126
- require File.join('coral_core', name.to_s + ".rb")
127
- end
128
-
129
- # Include post core utilities
130
- # ( normally inherit from core and have no reverse dependencies with
131
- # core classes )
132
- #
133
- [ :shell ].each do |name|
134
- require File.join('coral_core', 'util', name.to_s + ".rb")
135
- end
136
-
137
- # Include data model
138
- [ :event, :command ].each do |name|
139
- require File.join('coral_core', name.to_s + ".rb")
140
- end
141
-
142
- if git_location
143
- [ :repository, :memory ].each do |name|
144
- require File.join('coral_core', name.to_s + ".rb")
145
- end
146
- end
147
-
148
- # Include specialized events
149
- Dir.glob(File.join(home, 'coral_core', 'event', '*.rb')).each do |file|
150
- require file
151
- end
152
-
153
- # Include bundled templates
154
- Dir.glob(File.join(home, 'coral_core', 'template', '*.rb')).each do |file|
155
- require file
156
- end
157
-
158
- #---
159
-
160
- require 'hiera_backend.rb'
161
-
162
- #*******************************************************************************
163
- # Coral Core Library
164
- #
165
- # This provides core data elements and utilities used in the Coral gems.
166
- #
167
- # Author:: Adrian Webb (mailto:adrian.webb@coraltech.net)
168
- # License:: GPLv3
169
- module Coral
170
-
171
- VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
172
-
173
- #---
174
-
175
- @@ui = Coral::Core.ui
176
-
177
- #---
178
-
179
- def self.ui
180
- return @@ui
181
- end
182
-
183
- #-----------------------------------------------------------------------------
184
- # Initialization
185
-
186
- def self.load(base_path)
187
- if File.exists?(base_path)
188
- Dir.glob(File.join(base_path, '*.rb')).each do |file|
189
- require file
190
- end
191
- Dir.glob(File.join(base_path, 'event', '*.rb')).each do |file|
192
- require file
193
- end
194
- Dir.glob(File.join(base_path, 'template', '*.rb')).each do |file|
195
- require file
196
- end
197
- end
198
- end
199
-
200
- #---
201
-
202
- @@initialized = false
203
-
204
- def self.initialize
205
- unless @@initialized
206
- Config.set_property('time', Time.now.to_i)
207
-
208
- # Include Coral extensions
209
- Puppet::Node::Environment.new.modules.each do |mod|
210
- load(File.join(mod.path, 'lib', 'coral'))
211
- end
212
-
213
- @@initialized = true
214
- end
215
- end
216
-
217
- #-----------------------------------------------------------------------------
218
- # External execution
219
-
220
- def self.run
221
- begin
222
- initialize
223
- yield
224
-
225
- rescue Exception => error
226
- ui.warn(error.inspect)
227
- ui.warn(Util::Data.to_yaml(error.backtrace))
228
- raise
229
- end
230
- end
231
- end
232
-
233
- #-------------------------------------------------------------------------------
234
- # Data type alterations
235
-
236
- class Hash
237
- def search(search_key, options = {})
238
- config = Coral::Config.ensure(options)
239
- value = nil
240
-
241
- recurse = config.get(:recurse, false)
242
- recurse_level = config.get(:recurse_level, -1)
243
-
244
- self.each do |key, data|
245
- if key == search_key
246
- value = data
247
-
248
- elsif data.is_a?(Hash) &&
249
- recurse && (recurse_level == -1 || recurse_level > 0)
250
-
251
- recurse_level -= 1 unless recurse_level == -1
252
- value = value.search(search_key,
253
- Coral::Config.new(config).set(:recurse_level, recurse_level)
254
- )
255
- end
256
- break unless value.nil?
257
- end
258
- return value
259
- end
260
- end
data/lib/hiera_backend.rb DELETED
@@ -1,63 +0,0 @@
1
- begin
2
- require 'hiera/backend'
3
-
4
- class Hiera
5
- module Backend
6
- #
7
- # NOTE: This function is overridden so we can collect accumulated hiera
8
- # parameters and their values on a particular puppet run for reporting
9
- # purposes.
10
- #
11
- # Calls out to all configured backends in the order they
12
- # were specified. The first one to answer will win.
13
- #
14
- # This lets you declare multiple backends, a possible
15
- # use case might be in Puppet where a Puppet module declares
16
- # default data using in-module data while users can override
17
- # using JSON/YAML etc. By layering the backends and putting
18
- # the Puppet one last you can override module author data
19
- # easily.
20
- #
21
- # Backend instances are cached so if you need to connect to any
22
- # databases then do so in your constructor, future calls to your
23
- # backend will not create new instances
24
- def lookup(key, default, scope, order_override, resolution_type)
25
- @backends ||= {}
26
- answer = nil
27
-
28
- Config[:backends].each do |backend|
29
- if constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
30
- @backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
31
- new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
32
-
33
- if not new_answer.nil?
34
- case resolution_type
35
- when :array
36
- raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
37
- answer ||= []
38
- answer << new_answer
39
- when :hash
40
- raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
41
- answer ||= {}
42
- answer = merge_answer(new_answer,answer)
43
- else
44
- answer = new_answer
45
- break
46
- end
47
- end
48
- end
49
- end
50
-
51
- answer = resolve_answer(answer, resolution_type) unless answer.nil?
52
- answer = parse_string(default, scope) if answer.nil? and default.is_a?(String)
53
-
54
- answer = default if answer.nil?
55
-
56
- Coral::Config.set_property(key, answer) # This is why we override this function!!
57
- return answer
58
- end
59
- end
60
- end
61
-
62
- rescue LoadError
63
- end