coral_core 0.2.30 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -8
- data/Gemfile.lock +15 -86
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/coral_core.gemspec +12 -102
- metadata +18 -239
- data/lib/coral/command/shell.rb +0 -140
- data/lib/coral/machine/fog.rb +0 -215
- data/lib/coral/network/default.rb +0 -26
- data/lib/coral/node/rackspace.rb +0 -23
- data/lib/coral_core/config/collection.rb +0 -57
- data/lib/coral_core/config/options.rb +0 -70
- data/lib/coral_core/config/project.rb +0 -225
- data/lib/coral_core/config.rb +0 -329
- data/lib/coral_core/core.rb +0 -58
- data/lib/coral_core/event/puppet_event.rb +0 -98
- data/lib/coral_core/event/regexp_event.rb +0 -55
- data/lib/coral_core/event.rb +0 -170
- data/lib/coral_core/mixin/config_collection.rb +0 -52
- data/lib/coral_core/mixin/config_ops.rb +0 -51
- data/lib/coral_core/mixin/config_options.rb +0 -38
- data/lib/coral_core/mixin/lookup.rb +0 -211
- data/lib/coral_core/mixin/macro/object_interface.rb +0 -292
- data/lib/coral_core/mixin/macro/plugin_interface.rb +0 -277
- data/lib/coral_core/mixin/settings.rb +0 -46
- data/lib/coral_core/mixin/sub_config.rb +0 -208
- data/lib/coral_core/mod/hash.rb +0 -29
- data/lib/coral_core/mod/hiera_backend.rb +0 -63
- data/lib/coral_core/plugin/command.rb +0 -95
- data/lib/coral_core/plugin/machine.rb +0 -152
- data/lib/coral_core/plugin/network.rb +0 -24
- data/lib/coral_core/plugin/node.rb +0 -184
- data/lib/coral_core/plugin.rb +0 -261
- data/lib/coral_core/plugin_base.rb +0 -147
- data/lib/coral_core/repository.rb +0 -553
- data/lib/coral_core/resource.rb +0 -243
- data/lib/coral_core/template/environment.rb +0 -72
- data/lib/coral_core/template/json.rb +0 -13
- data/lib/coral_core/template/wrapper.rb +0 -13
- data/lib/coral_core/template/yaml.rb +0 -13
- data/lib/coral_core/template.rb +0 -92
- data/lib/coral_core/util/cli.rb +0 -293
- data/lib/coral_core/util/data.rb +0 -389
- data/lib/coral_core/util/disk.rb +0 -105
- data/lib/coral_core/util/git.rb +0 -40
- data/lib/coral_core/util/interface.rb +0 -190
- data/lib/coral_core/util/process.rb +0 -43
- data/lib/coral_core/util/shell.rb +0 -183
- data/lib/coral_core.rb +0 -375
- data/locales/en.yml +0 -8
- data/spec/coral_core/interface_spec.rb +0 -489
- data/spec/coral_mock_input.rb +0 -29
- data/spec/coral_test_kernel.rb +0 -22
- data/spec/spec_helper.rb +0 -15
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::ConfigOptions
|
5
|
-
#
|
6
|
-
|
7
|
-
module Coral
|
8
|
-
module Mixin
|
9
|
-
module ConfigOptions
|
10
|
-
#-----------------------------------------------------------------------------
|
11
|
-
# Configuration options interface
|
12
|
-
|
13
|
-
def contexts(contexts = [], hierarchy = [])
|
14
|
-
return Config::Options.contexts(contexts, hierarchy)
|
15
|
-
end
|
16
|
-
|
17
|
-
#---
|
18
|
-
|
19
|
-
def get_options(contexts, force = true)
|
20
|
-
return Config::Options.get(contexts, force)
|
21
|
-
end
|
22
|
-
|
23
|
-
#---
|
24
|
-
|
25
|
-
def set_options(contexts, options, force = true)
|
26
|
-
Config::Options.set(contexts, options, force)
|
27
|
-
return self
|
28
|
-
end
|
29
|
-
|
30
|
-
#---
|
31
|
-
|
32
|
-
def clear_options(contexts)
|
33
|
-
Config::Options.clear(contexts)
|
34
|
-
return self
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,211 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::Lookup
|
5
|
-
#
|
6
|
-
|
7
|
-
module Coral
|
8
|
-
module Mixin
|
9
|
-
module Lookup
|
10
|
-
#-----------------------------------------------------------------------------
|
11
|
-
# Hiera configuration
|
12
|
-
|
13
|
-
@@hiera = nil
|
14
|
-
|
15
|
-
#---
|
16
|
-
|
17
|
-
def hiera_config
|
18
|
-
config_file = Puppet.settings[:hiera_config]
|
19
|
-
config = {}
|
20
|
-
|
21
|
-
if File.exist?(config_file)
|
22
|
-
config = Hiera::Config.load(config_file)
|
23
|
-
else
|
24
|
-
ui.warn("Config file #{config_file} not found, using Hiera defaults")
|
25
|
-
end
|
26
|
-
|
27
|
-
config[:logger] = 'puppet'
|
28
|
-
return config
|
29
|
-
end
|
30
|
-
|
31
|
-
#---
|
32
|
-
|
33
|
-
def hiera
|
34
|
-
@@hiera = Hiera.new(:config => hiera_config) unless @@hiera
|
35
|
-
return @@hiera
|
36
|
-
end
|
37
|
-
|
38
|
-
#-----------------------------------------------------------------------------
|
39
|
-
# Configuration lookup interface
|
40
|
-
|
41
|
-
def initialized?(options = {})
|
42
|
-
config = Config.ensure(options)
|
43
|
-
|
44
|
-
begin
|
45
|
-
require 'hiera'
|
46
|
-
puppet_scope = config.get(:puppet_scope, scope)
|
47
|
-
|
48
|
-
prefix_text = config.get(:prefix_text, '::')
|
49
|
-
init_fact = prefix_text + config.get(:init_fact, 'hiera_ready')
|
50
|
-
|
51
|
-
if Puppet::Parser::Functions.function('hiera') && puppet_scope.respond_to?('[]')
|
52
|
-
return true if Util::Data.true?(puppet_scope[init_fact])
|
53
|
-
end
|
54
|
-
return false
|
55
|
-
|
56
|
-
rescue Exception # Prevent abortions.
|
57
|
-
end
|
58
|
-
return false
|
59
|
-
end
|
60
|
-
|
61
|
-
#---
|
62
|
-
|
63
|
-
def lookup(properties, default = nil, options = {})
|
64
|
-
config = Config.ensure(options)
|
65
|
-
value = nil
|
66
|
-
|
67
|
-
hiera_scope = config.get(:hiera_scope, {})
|
68
|
-
context = config.get(:context, :priority)
|
69
|
-
override = config.get(:override, nil)
|
70
|
-
|
71
|
-
puppet_scope = config.get(:puppet_scope, scope)
|
72
|
-
|
73
|
-
base_names = config.get(:search, nil)
|
74
|
-
|
75
|
-
search_name = config.get(:search_name, true)
|
76
|
-
reverse_lookup = config.get(:reverse_lookup, true)
|
77
|
-
|
78
|
-
return_property = config.get(:return_property, false)
|
79
|
-
|
80
|
-
unless properties.is_a?(Array)
|
81
|
-
properties = [ properties ].flatten
|
82
|
-
end
|
83
|
-
|
84
|
-
first_property = nil
|
85
|
-
properties.each do |property|
|
86
|
-
first_property = property unless first_property
|
87
|
-
|
88
|
-
if initialized?(config)
|
89
|
-
unless hiera_scope.respond_to?('[]')
|
90
|
-
hiera_scope = Hiera::Scope.new(hiera_scope)
|
91
|
-
end
|
92
|
-
value = hiera.lookup(property, nil, hiera_scope, override, context)
|
93
|
-
end
|
94
|
-
|
95
|
-
if Util::Data.undef?(value)
|
96
|
-
log_level = Puppet::Util::Log.level
|
97
|
-
Puppet::Util::Log.level = :err # Don't want failed parameter lookup warnings here.
|
98
|
-
|
99
|
-
if base_names
|
100
|
-
if base_names.is_a?(String)
|
101
|
-
base_names = [ base_names ]
|
102
|
-
end
|
103
|
-
base_names = base_names.reverse if reverse_lookup
|
104
|
-
|
105
|
-
base_names.each do |base|
|
106
|
-
value = puppet_scope.lookupvar("::#{base}::#{property}")
|
107
|
-
break unless Util::Data.undef?(value)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
if Util::Data.undef?(value) && search_name
|
111
|
-
value = puppet_scope.lookupvar("::#{property}")
|
112
|
-
end
|
113
|
-
Puppet::Util::Log.level = log_level
|
114
|
-
end
|
115
|
-
end
|
116
|
-
value = default if Util::Data.undef?(value)
|
117
|
-
value = Util::Data.value(value)
|
118
|
-
|
119
|
-
if ! @@properties.has_key?(first_property) || ! Util::Data.undef?(value)
|
120
|
-
Config::Collection.set(first_property, value)
|
121
|
-
end
|
122
|
-
return value, first_property if return_property
|
123
|
-
return value
|
124
|
-
end
|
125
|
-
|
126
|
-
#---
|
127
|
-
|
128
|
-
def lookup_array(properties, default = [], options = {})
|
129
|
-
config = Config.ensure(options)
|
130
|
-
value, property = lookup(properties, nil, config.import({ :return_property => true }))
|
131
|
-
|
132
|
-
if Util::Data.undef?(value)
|
133
|
-
value = default
|
134
|
-
|
135
|
-
elsif ! Util::Data.empty?(default)
|
136
|
-
if config.get(:merge, false)
|
137
|
-
value = Util::Data.merge([default, value], config)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
unless value.is_a?(Array)
|
142
|
-
value = ( Util::Data.empty?(value) ? [] : [ value ] )
|
143
|
-
end
|
144
|
-
|
145
|
-
Config::Collection.set(property, value)
|
146
|
-
return value
|
147
|
-
end
|
148
|
-
|
149
|
-
#---
|
150
|
-
|
151
|
-
def lookup_hash(properties, default = {}, options = {})
|
152
|
-
config = Config.ensure(options)
|
153
|
-
value, property = lookup(properties, nil, config.import({ :return_property => true }))
|
154
|
-
|
155
|
-
if Util::Data.undef?(value)
|
156
|
-
value = default
|
157
|
-
|
158
|
-
elsif ! Util::Data.empty?(default)
|
159
|
-
if config.get(:merge, false)
|
160
|
-
value = Util::Data.merge([default, value], config)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
unless value.is_a?(Hash)
|
165
|
-
value = ( Util::Data.empty?(value) ? {} : { :value => value } )
|
166
|
-
end
|
167
|
-
|
168
|
-
Config::Collection.set(property, value)
|
169
|
-
return value
|
170
|
-
end
|
171
|
-
|
172
|
-
#---
|
173
|
-
|
174
|
-
def normalize(data, override = nil, options = {})
|
175
|
-
config = Config.ensure(options)
|
176
|
-
results = {}
|
177
|
-
|
178
|
-
unless Util::Data.undef?(override)
|
179
|
-
case data
|
180
|
-
when String, Symbol
|
181
|
-
data = [ data, override ] if data != override
|
182
|
-
when Array
|
183
|
-
data << override unless data.include?(override)
|
184
|
-
when Hash
|
185
|
-
data = [ data, override ]
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
case data
|
190
|
-
when String, Symbol
|
191
|
-
results = lookup(data.to_s, {}, config)
|
192
|
-
|
193
|
-
when Array
|
194
|
-
data.each do |item|
|
195
|
-
if item.is_a?(String) || item.is_a?(Symbol)
|
196
|
-
item = lookup(item.to_s, {}, config)
|
197
|
-
end
|
198
|
-
unless Util::Data.undef?(item)
|
199
|
-
results = Util::Data.merge([ results, item ], config)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
when Hash
|
204
|
-
results = data
|
205
|
-
end
|
206
|
-
|
207
|
-
return results
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
@@ -1,292 +0,0 @@
|
|
1
|
-
|
2
|
-
# Should be included via extend
|
3
|
-
#
|
4
|
-
# extend Mixin::Macro::ObjectInterface
|
5
|
-
#
|
6
|
-
|
7
|
-
module Coral
|
8
|
-
module Mixin
|
9
|
-
module Macro
|
10
|
-
module ObjectInterface
|
11
|
-
|
12
|
-
# requires Mixin::SubConfig
|
13
|
-
# requires Mixin::Settings
|
14
|
-
|
15
|
-
#-----------------------------------------------------------------------------
|
16
|
-
# Object collections
|
17
|
-
|
18
|
-
@@object_types = {}
|
19
|
-
|
20
|
-
#---
|
21
|
-
|
22
|
-
def object_collection(_type, _method_options = {})
|
23
|
-
_method_config = Config.ensure(_method_options)
|
24
|
-
|
25
|
-
_plural = _method_config.init(:plural, "#{_type}s").get(:plural)
|
26
|
-
|
27
|
-
unless _ensure_proc = _method_config.get(:ensure_proc, false)
|
28
|
-
_ensure_proc = Proc.new {|name, options = {}| options }
|
29
|
-
end
|
30
|
-
_delete_proc = _method_config.get(:delete_proc)
|
31
|
-
_search_proc = _method_config.get(:search_proc)
|
32
|
-
|
33
|
-
@@object_types[_type] = _method_config
|
34
|
-
|
35
|
-
#---------------------------------------------------------------------------
|
36
|
-
|
37
|
-
object_utilities
|
38
|
-
|
39
|
-
#---
|
40
|
-
|
41
|
-
unless respond_to? :each_object!
|
42
|
-
define_method :each_object! do |object_types = nil|
|
43
|
-
each_object_type!(object_types) do |type, plural, options|
|
44
|
-
send(plural).each do |name, obj|
|
45
|
-
yield(type, name, obj)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
#---------------------------------------------------------------------------
|
52
|
-
|
53
|
-
define_method "#{_type}_config" do |name = nil|
|
54
|
-
Config.new( name ? get([ _plural, name ], {}) : get(_plural, {}) )
|
55
|
-
end
|
56
|
-
|
57
|
-
#---
|
58
|
-
|
59
|
-
define_method "#{_type}_setting" do |name, property, default = nil, format = false|
|
60
|
-
get([ _plural, name, property ], default, format)
|
61
|
-
end
|
62
|
-
|
63
|
-
#---
|
64
|
-
|
65
|
-
define_method "#{_plural}" do
|
66
|
-
_get(_plural, {})
|
67
|
-
end
|
68
|
-
|
69
|
-
#---
|
70
|
-
|
71
|
-
define_method "init_#{_plural}" do
|
72
|
-
data = hash(_search_proc.call) if _search_proc
|
73
|
-
data = get_hash(_plural) unless data
|
74
|
-
|
75
|
-
symbol_map(data).each do |name, options|
|
76
|
-
if name != :settings
|
77
|
-
options[:object_container] = self
|
78
|
-
|
79
|
-
obj = _ensure_proc.call(name, options)
|
80
|
-
_set([ _plural, name ], obj)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
#---
|
86
|
-
|
87
|
-
define_method "set_#{_plural}" do |data = {}|
|
88
|
-
data = Config.ensure(data).export
|
89
|
-
|
90
|
-
send("clear_#{_plural}")
|
91
|
-
set(_plural, data)
|
92
|
-
|
93
|
-
data.each do |name, options|
|
94
|
-
options[:object_container] = self
|
95
|
-
|
96
|
-
obj = _ensure_proc.call(name, options)
|
97
|
-
_set([ _plural, name ], obj)
|
98
|
-
end
|
99
|
-
self
|
100
|
-
end
|
101
|
-
|
102
|
-
#---
|
103
|
-
|
104
|
-
define_method "#{_type}" do |name|
|
105
|
-
_get([ _plural, name ])
|
106
|
-
end
|
107
|
-
|
108
|
-
#---
|
109
|
-
|
110
|
-
define_method "set_#{_type}" do |name, options = {}|
|
111
|
-
options = Config.ensure(options).export
|
112
|
-
|
113
|
-
set([ _plural, name ], options)
|
114
|
-
|
115
|
-
options[:object_container] = self
|
116
|
-
|
117
|
-
obj = _ensure_proc.call(name, options)
|
118
|
-
_set([ _plural, name ], obj)
|
119
|
-
self
|
120
|
-
end
|
121
|
-
|
122
|
-
#---
|
123
|
-
|
124
|
-
define_method "set_#{_type}_setting" do |name, property, value = nil|
|
125
|
-
set([ _plural, name, property ], value)
|
126
|
-
self
|
127
|
-
end
|
128
|
-
|
129
|
-
#---
|
130
|
-
|
131
|
-
define_method "delete_#{_type}" do |name|
|
132
|
-
obj = send(_type, name)
|
133
|
-
|
134
|
-
delete([ _plural, name ])
|
135
|
-
_delete([ _plural, name ])
|
136
|
-
|
137
|
-
_delete_proc.call(obj) if _delete_proc
|
138
|
-
self
|
139
|
-
end
|
140
|
-
|
141
|
-
#---
|
142
|
-
|
143
|
-
define_method "delete_#{_type}_setting" do |name, property|
|
144
|
-
delete([ _plural, name, property ])
|
145
|
-
self
|
146
|
-
end
|
147
|
-
|
148
|
-
#---
|
149
|
-
|
150
|
-
define_method "clear_#{_plural}" do
|
151
|
-
_get(_plural).keys.each do |name|
|
152
|
-
send("delete_#{_type}", name)
|
153
|
-
end
|
154
|
-
self
|
155
|
-
end
|
156
|
-
|
157
|
-
#---------------------------------------------------------------------------
|
158
|
-
|
159
|
-
define_method "search_#{_type}" do |name, keys, default = '', format = false|
|
160
|
-
obj_config = send("#{_type}_config", name)
|
161
|
-
search_object(obj_config, keys, default, format)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
#-----------------------------------------------------------------------------
|
166
|
-
# Utilities
|
167
|
-
|
168
|
-
def object_utilities
|
169
|
-
|
170
|
-
unless respond_to? :foreach_object_type!
|
171
|
-
define_method :foreach_object_type! do |object_types = nil, filter_proc = nil|
|
172
|
-
object_types = @@object_types.keys unless object_types
|
173
|
-
object_types = [ object_types ] unless object_types.is_a?(Array)
|
174
|
-
|
175
|
-
object_types.keys.each do |type|
|
176
|
-
unless filter_proc && ! filter_proc.call(type, @@object_types[type])
|
177
|
-
plural = @@object_types[type][:plural]
|
178
|
-
yield(type, plural, @@object_types[type])
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
#---
|
185
|
-
|
186
|
-
unless respond_to? :init_objects
|
187
|
-
define_method :init_objects do |object_types = nil, filter_proc = nil|
|
188
|
-
foreach_object_type!(object_types, filter_proc) do |type, plural, options|
|
189
|
-
send("init_#{plural}")
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
#---
|
195
|
-
|
196
|
-
unless respond_to? :clear_objects
|
197
|
-
define_method :clear_objects do |object_types = nil, filter_proc = nil|
|
198
|
-
foreach_object_type!(object_types, filter_proc) do |type, plural, options|
|
199
|
-
send("clear_#{plural}")
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
#---------------------------------------------------------------------------
|
205
|
-
|
206
|
-
unless respond_to? :search_object
|
207
|
-
define_method :search_object do |obj_config, keys, default = '', format = false|
|
208
|
-
obj_config = Marshal.load(Marshal.dump(obj_config))
|
209
|
-
value = obj_config.get(keys)
|
210
|
-
|
211
|
-
#dbg(obj_config, 'search object config')
|
212
|
-
|
213
|
-
if ! value || value.is_a?(Hash)
|
214
|
-
settings = {}
|
215
|
-
|
216
|
-
keys = [ keys ] unless keys.is_a?(Array)
|
217
|
-
temp = keys.dup
|
218
|
-
|
219
|
-
#dbg('specialized settings')
|
220
|
-
|
221
|
-
until temp.empty? do
|
222
|
-
#dbg(temp, 'temporary settings prefix')
|
223
|
-
if obj_settings = obj_config.delete([ temp, :settings ])
|
224
|
-
#dbg(obj_settings, 'object settings')
|
225
|
-
array(obj_settings).each do |group_name|
|
226
|
-
#dbg(group_name, 'group name')
|
227
|
-
if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
|
228
|
-
#dbg(group_settings, 'group settings')
|
229
|
-
settings = Util::Data.merge([ group_settings.dup, settings ], true)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
temp.pop
|
234
|
-
end
|
235
|
-
|
236
|
-
#dbg(settings, 'specialized settings')
|
237
|
-
|
238
|
-
#dbg('general settings')
|
239
|
-
|
240
|
-
if obj_settings = obj_config.delete(:settings)
|
241
|
-
#dbg(obj_settings, 'object settings')
|
242
|
-
array(obj_settings).each do |group_name|
|
243
|
-
#dbg(group_name, 'group name')
|
244
|
-
if group_settings = Marshal.load(Marshal.dump(settings(group_name)))
|
245
|
-
#dbg(group_settings, 'group settings')
|
246
|
-
settings = Util::Data.merge([ group_settings, settings ], true)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
#dbg(settings, 'general settings')
|
252
|
-
|
253
|
-
unless settings.empty?
|
254
|
-
#dbg(obj_config, 'initial object config')
|
255
|
-
final_config = Config.new(Util::Data.merge([ settings, obj_config.export ], true))
|
256
|
-
value = final_config.get(keys)
|
257
|
-
#dbg(final_config, 'final object config')
|
258
|
-
end
|
259
|
-
|
260
|
-
value = default if Util::Data.undef?(value)
|
261
|
-
end
|
262
|
-
filter(value, format)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
#---------------------------------------------------------------------------
|
267
|
-
# Configuration loading saving
|
268
|
-
|
269
|
-
unless respond_to? :load
|
270
|
-
define_method :load do |options = {}|
|
271
|
-
if config.respond_to?(:load)
|
272
|
-
clear_objects
|
273
|
-
config.load(options)
|
274
|
-
init_objects
|
275
|
-
end
|
276
|
-
self
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
#---
|
281
|
-
|
282
|
-
unless respond_to? :save
|
283
|
-
define_method :save do |options = {}|
|
284
|
-
config.save(options) if config.respond_to?(:save)
|
285
|
-
self
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|