lorj 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/students_1/students.rb +5 -6
- data/example/students_2/students.rb +4 -5
- data/example/students_3/students.rb +4 -5
- data/example/students_4/students.rb +4 -5
- data/example/students_5/students.rb +5 -5
- data/lib/core/core.rb +6 -1
- data/lib/core/core_controller.rb +1 -9
- data/lib/core/core_internal.rb +2 -1
- data/lib/core/core_model.rb +2 -10
- data/lib/core/core_object_data.rb +18 -0
- data/lib/core/core_object_params.rb +43 -4
- data/lib/core/core_process.rb +1 -9
- data/lib/core/core_process_setup.rb +32 -6
- data/lib/core/core_setup_ask.rb +41 -33
- data/lib/core/core_setup_encrypt.rb +29 -6
- data/lib/core/core_setup_init.rb +2 -2
- data/lib/core/definition.rb +33 -10
- data/lib/core/definition_internal.rb +10 -14
- data/lib/core/lorj_basedefinition.rb +16 -24
- data/lib/core/lorj_baseprocess.rb +113 -44
- data/lib/core/lorj_data.rb +2 -9
- data/lib/core/lorj_keypath.rb +5 -2
- data/lib/core_process/cloud/process/common.rb +4 -7
- data/lib/core_process/cloud/process/connection.rb +44 -45
- data/lib/core_process/cloud/process/external_network.rb +24 -28
- data/lib/core_process/cloud/process/flavor.rb +31 -34
- data/lib/core_process/cloud/process/images.rb +12 -15
- data/lib/core_process/cloud/process/internet_network.rb +13 -14
- data/lib/core_process/cloud/process/internet_server.rb +9 -10
- data/lib/core_process/cloud/process/keypairs.rb +34 -27
- data/lib/core_process/cloud/process/network.rb +21 -23
- data/lib/core_process/cloud/process/public_ip.rb +17 -18
- data/lib/core_process/cloud/process/router.rb +86 -92
- data/lib/core_process/cloud/process/rules.rb +30 -31
- data/lib/core_process/cloud/process/security_groups.rb +21 -22
- data/lib/core_process/cloud/process/server.rb +30 -31
- data/lib/core_process/cloud/process/server_log.rb +13 -14
- data/lib/core_process/cloud/process/subnetwork.rb +25 -40
- data/lib/logging.rb +4 -17
- data/lib/lorj/version.rb +1 -1
- data/lib/lorj.rb +2 -1
- data/lib/lorj_account.rb +137 -90
- data/lib/lorj_config.rb +13 -19
- data/lib/lorj_defaults.rb +46 -292
- data/lib/lorj_meta.rb +729 -0
- data/lib/prc.rb +119 -30
- data/lib/prc_base_config.rb +53 -47
- data/lib/prc_core_config.rb +837 -565
- data/lib/prc_section_config.rb +44 -16
- data/lib/providers/hpcloud/hpcloud.rb +1 -1
- data/lib/providers/openstack/openstack.rb +278 -21
- data/lib/providers/openstack/openstack_create.rb +205 -0
- data/lib/providers/openstack/openstack_delete.rb +28 -0
- data/lib/providers/openstack/openstack_get.rb +39 -0
- data/lib/providers/openstack/openstack_process.rb +26 -0
- data/lib/providers/openstack/openstack_query.rb +96 -0
- data/lib/providers/openstack/openstack_update.rb +35 -0
- data/lib/rh.rb +91 -6
- data/lorj-spec/defaults.yaml +18 -12
- data/lorj.gemspec +1 -0
- data/spec/01_hash_rh_spec.rb +41 -2
- data/spec/02_prc_base_config_spec.rb +1 -1
- data/spec/03_prc_section_config_spec.rb +1 -1
- data/spec/04_prc_core_config_spec.rb +148 -4
- data/spec/09_prc_spec.rb +104 -0
- data/spec/{00_lorj_log_spec.rb → 10_lorj_log_spec.rb} +23 -2
- data/spec/11_lorj_config_spec.rb +9 -27
- data/spec/12_lorj_account_spec.rb +36 -20
- data/spec/20_lorj_meta_spec.rb +271 -0
- data/spec/21_lorj_defaults_spec.rb +85 -0
- metadata +31 -4
data/lib/logging.rb
CHANGED
@@ -152,14 +152,8 @@ module PrcLib
|
|
152
152
|
end
|
153
153
|
|
154
154
|
# Log to STDOUT and Log file and FATAL class message
|
155
|
-
|
156
|
-
# the exception class is given.
|
157
|
-
# The exception class should provide message and backtrace.
|
158
|
-
def fatal(message, e = nil)
|
155
|
+
def fatal(message)
|
159
156
|
@out_logger.fatal(message + ANSI.clear_eol)
|
160
|
-
return @file_logger.fatal(format("%s\n%s\n%s",
|
161
|
-
message, e.message,
|
162
|
-
e.backtrace.join("\n"))) if e
|
163
157
|
@file_logger.fatal(message)
|
164
158
|
end
|
165
159
|
|
@@ -184,18 +178,11 @@ module PrcLib
|
|
184
178
|
private
|
185
179
|
|
186
180
|
def file_logger_initialize
|
187
|
-
|
188
|
-
if log_file.nil?
|
189
|
-
default_log_file = format('%s.log', PrcLib.app_name)
|
190
|
-
log_file = File.join(PrcLib.data_path, default_log_file)
|
191
|
-
end
|
192
|
-
|
193
|
-
@file_logger = Logger.new(log_file, 'weekly')
|
181
|
+
@file_logger = Logger.new(PrcLib.log_file, 'weekly')
|
194
182
|
@file_logger.level = Logger::DEBUG
|
195
183
|
@file_logger.formatter = proc do |severity, datetime, progname, msg|
|
196
184
|
"#{progname} : #{datetime}: #{severity}: #{msg} \n"
|
197
185
|
end
|
198
|
-
PrcLib.log_file = log_file
|
199
186
|
end
|
200
187
|
end
|
201
188
|
|
@@ -260,12 +247,12 @@ module PrcLib
|
|
260
247
|
# the exception class is given.
|
261
248
|
# The exception class should provide message and backtrace.
|
262
249
|
def fatal(rc, message, *p)
|
263
|
-
e = nil
|
264
250
|
if p.length > 0 && p[-1].is_a?(Exception)
|
265
251
|
e = p[-1]
|
266
252
|
p.pop
|
253
|
+
message = format("%s\n%s\n%s", message, e.message, e.backtrace.join("\n"))
|
267
254
|
end
|
268
|
-
log_object.fatal(format(message, *p)
|
255
|
+
log_object.fatal(format(message, *p))
|
269
256
|
puts format('Issues found. Please fix it and retry. Process aborted. '\
|
270
257
|
"See details in log file '%s'.", PrcLib.log_file)
|
271
258
|
exit rc
|
data/lib/lorj/version.rb
CHANGED
data/lib/lorj.rb
CHANGED
@@ -29,6 +29,7 @@ require 'logging.rb' # class PrcLib::Logging
|
|
29
29
|
require 'prc_base_config.rb' # PRC::BaseConfig class
|
30
30
|
require 'prc_section_config.rb' # PRC::SectionConfig class
|
31
31
|
require 'prc_core_config.rb' # PRC::CoreConfig class
|
32
|
+
require 'lorj_meta.rb' # PRC::Meta class - Application defaults
|
32
33
|
require 'lorj_defaults.rb' # PRC::Defaults class - Application defaults
|
33
34
|
require 'lorj_config.rb' # Lorj::Config class -
|
34
35
|
require 'lorj_account.rb' # Lorj::Account class - account config
|
@@ -72,7 +73,7 @@ module Lorj
|
|
72
73
|
if iLevel <= PrcLib.core_level
|
73
74
|
message = format('-%s- %s', iLevel, sMsg)
|
74
75
|
|
75
|
-
PrcLib.debug(
|
76
|
+
PrcLib.debug(message, *p)
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
data/lib/lorj_account.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
require 'rubygems'
|
19
19
|
|
20
|
+
# Lorj implements Lorj::Accounts
|
20
21
|
module Lorj
|
21
22
|
# Simple List of accounts class.
|
22
23
|
class Accounts
|
@@ -35,6 +36,7 @@ module Lorj
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
39
|
+
# Lorj implements Lorj::AccountConfig
|
38
40
|
module Lorj
|
39
41
|
# AccountConfig class layer
|
40
42
|
class AccountConfig < PRC::SectionConfig
|
@@ -48,11 +50,12 @@ module Lorj
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def data_options(options = { :section => :default })
|
51
|
-
|
53
|
+
p_data_options(options)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
58
|
+
# Lorj implements Lorj::Account
|
56
59
|
module Lorj
|
57
60
|
# Lorj::Account manage a list of key/value grouped by section.
|
58
61
|
# The intent of Lorj::Account is to attach some keys/values to
|
@@ -109,16 +112,25 @@ module Lorj
|
|
109
112
|
|
110
113
|
# This object manage data located in oConfig[:hpc_accounts/AccountName]
|
111
114
|
|
112
|
-
#
|
113
|
-
#
|
115
|
+
# Lorj::Account implements Config layers.
|
116
|
+
# - default : Represents the application defaults.yaml config.
|
117
|
+
# - controller : Represents the controller config redefinition.
|
118
|
+
# See BaseDefinition::define_data
|
119
|
+
# - local : Represents the config.yaml located in ~/.forj
|
120
|
+
# - account : Represents an Account data located in ~/.forj/accounts
|
121
|
+
# - runtime : Represents the runtime in memory data settings.
|
114
122
|
def initialize(config_name = nil)
|
115
123
|
config_layers = []
|
116
124
|
|
117
125
|
# Application layer
|
118
126
|
config_layers << define_default_layer
|
119
127
|
|
128
|
+
# runtime Config layer
|
129
|
+
config_layers << define_controller_data_layer
|
130
|
+
|
120
131
|
# Local Config layer
|
121
|
-
|
132
|
+
local = define_local_layer
|
133
|
+
config_layers << local
|
122
134
|
|
123
135
|
# Account config layer
|
124
136
|
config_layers << define_account_layer
|
@@ -130,7 +142,7 @@ module Lorj
|
|
130
142
|
PrcLib.fatal(1, 'Internal PrcLib.data_path was not set.')
|
131
143
|
end
|
132
144
|
|
133
|
-
initialize_local(
|
145
|
+
initialize_local(local[:config], config_name)
|
134
146
|
|
135
147
|
initialize_account
|
136
148
|
|
@@ -143,15 +155,15 @@ module Lorj
|
|
143
155
|
# otherwise, search in all layers.
|
144
156
|
#
|
145
157
|
# * *Args* :
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
158
|
+
# - +key+ : key name. It do not support it to be a key tree (Arrays of
|
159
|
+
# keys).
|
160
|
+
# - +default+ : default value, if not found.
|
161
|
+
# - +options+ : Options for get:
|
162
|
+
# - +:section+ : Get will use this section name instead of searching it.
|
163
|
+
# - +:names+ : array of layers name to exclusively get data.
|
164
|
+
# - +:indexes+ : array of layers index to exclusively get data.
|
165
|
+
# If neither :name or :index is set, get will search
|
166
|
+
# data on all predefined layers, first found.
|
155
167
|
# * *Returns* :
|
156
168
|
# - key value.
|
157
169
|
# * *Raises* :
|
@@ -161,21 +173,23 @@ module Lorj
|
|
161
173
|
options = {} unless options.is_a?(Hash)
|
162
174
|
|
163
175
|
section = options[:section]
|
164
|
-
section = Lorj.
|
176
|
+
section = Lorj.data.first_section(key) if section.nil?
|
165
177
|
|
166
178
|
options = { :keys => [key], :section => section }
|
167
179
|
|
168
|
-
indexes =
|
180
|
+
indexes = _identify_array_indexes(options, exclusive?(key, section))
|
169
181
|
names = []
|
170
182
|
indexes.each { |index| names << @config_layers[index][:name] }
|
171
183
|
|
172
184
|
options[:data_options] = _set_data_options_per_names(names)
|
173
185
|
|
174
|
-
return
|
186
|
+
return p_get(options) if p_exist?(options)
|
175
187
|
|
176
188
|
default
|
177
189
|
end
|
178
190
|
|
191
|
+
# Simple get call with default options
|
192
|
+
# Alternative is to use Account::get
|
179
193
|
def [](key, default = nil)
|
180
194
|
get(key, default)
|
181
195
|
end
|
@@ -186,14 +200,14 @@ module Lorj
|
|
186
200
|
# otherwise, search in all layers.
|
187
201
|
#
|
188
202
|
# * *Args* :
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
203
|
+
# - +key+ : key name. It do not support it to be a key tree (Arrays of
|
204
|
+
# keys).
|
205
|
+
# - +options+ : possible options:
|
206
|
+
# - +:section+ : Force to use a specific section name.
|
207
|
+
# - +:names+ : array of layers name to exclusively get data.
|
208
|
+
# - +:indexes+ : array of layers index to exclusively get data.
|
209
|
+
# If neither :name or :index is set, get will search data on all
|
210
|
+
# predefined layers, first found, first listed.
|
197
211
|
# * *Returns* :
|
198
212
|
# - key value.
|
199
213
|
# * *Raises* :
|
@@ -217,20 +231,20 @@ module Lorj
|
|
217
231
|
:data_options => _set_data_options_per_names(names)
|
218
232
|
}
|
219
233
|
|
220
|
-
|
234
|
+
p_where?(where_options)
|
221
235
|
end
|
222
236
|
|
223
237
|
# check key/value existence in config layers
|
224
238
|
#
|
225
239
|
# * *Args* :
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
240
|
+
# - +key+ : key name. It do not support it to be a key tree (Arrays of
|
241
|
+
# keys).
|
242
|
+
# - +options+ : possible options:
|
243
|
+
# - +:section+ : Force to use a specific section name.
|
244
|
+
# - +:names+ : array of layers name to exclusively get data.
|
245
|
+
# - +:indexes+ : array of layers index to exclusively get data.
|
246
|
+
# If neither :name or :index is set, get will search data on all
|
247
|
+
# predefined layers, first found.
|
234
248
|
#
|
235
249
|
# * *Returns* :
|
236
250
|
# - 'runtime' : if found in runtime.
|
@@ -246,27 +260,27 @@ module Lorj
|
|
246
260
|
options = {} unless options.is_a?(Hash)
|
247
261
|
|
248
262
|
section = options[:section]
|
249
|
-
section = Lorj.
|
263
|
+
section = Lorj.data.first_section(key) if section.nil?
|
250
264
|
options = { :keys => [key], :section => section }
|
251
265
|
|
252
|
-
indexes =
|
266
|
+
indexes = _identify_array_indexes(options, exclusive?(key, section))
|
253
267
|
|
254
268
|
names = []
|
255
269
|
indexes.each { |index| names << @config_layers[index][:name] }
|
256
270
|
|
257
271
|
options[:data_options] = _set_data_options_per_names(names)
|
258
272
|
|
259
|
-
|
273
|
+
p_exist?(options)
|
260
274
|
end
|
261
275
|
|
262
276
|
# Return true if readonly. set won't be able to update this value.
|
263
|
-
# Only
|
277
|
+
# Only p_set (private function) is able.
|
264
278
|
#
|
265
279
|
# * *Args* :
|
266
280
|
# - +key+ : key name. It can support it to be a key tree (Arrays of
|
267
|
-
#
|
281
|
+
# keys).
|
268
282
|
# - +section+ : optionnal. If missing the section name is determined by
|
269
|
-
#
|
283
|
+
# the data name associated
|
270
284
|
# * *Returns* :
|
271
285
|
# - true/false : readonly value
|
272
286
|
# OR
|
@@ -280,20 +294,20 @@ module Lorj
|
|
280
294
|
|
281
295
|
return nil if section.nil?
|
282
296
|
|
283
|
-
result = Lorj.
|
297
|
+
result = Lorj.data.section_data(section, key, :readonly)
|
284
298
|
return result if result.boolean?
|
285
299
|
false
|
286
300
|
end
|
287
301
|
|
288
302
|
# Return true if exclusive
|
289
303
|
# set won't be able to update this value.
|
290
|
-
# Only
|
304
|
+
# Only p_set (private function) is able.
|
291
305
|
#
|
292
306
|
# * *Args* :
|
293
307
|
# - +key+ : key name. It can support it to be a key tree (Arrays of
|
294
|
-
#
|
308
|
+
# keys).
|
295
309
|
# - +section+ : optionnal. If missing the section name is determined by
|
296
|
-
#
|
310
|
+
# the data name associated
|
297
311
|
# * *Returns* :
|
298
312
|
# - true/false : readonly value
|
299
313
|
# OR
|
@@ -303,37 +317,35 @@ module Lorj
|
|
303
317
|
return nil unless key
|
304
318
|
|
305
319
|
key = key.to_sym if key.class == String
|
306
|
-
section = Lorj.
|
320
|
+
section = Lorj.data.first_section(key) if section.nil?
|
307
321
|
|
308
322
|
return nil if section.nil?
|
309
|
-
result = Lorj.
|
310
|
-
:account_exclusive)
|
323
|
+
result = Lorj.data[:sections, section, key, :account_exclusive]
|
311
324
|
return result if result.boolean?
|
312
325
|
result
|
313
326
|
end
|
314
327
|
|
315
328
|
# This function update a section/key=value if the account structure is
|
316
|
-
# defined.
|
317
|
-
# If no section is defined,
|
329
|
+
# defined. (see Lorj::Defaults)
|
330
|
+
# If no section is defined, it will assume to be :default.
|
318
331
|
#
|
319
332
|
# * *Args* :
|
320
|
-
#
|
321
|
-
#
|
322
|
-
#
|
323
|
-
#
|
324
|
-
#
|
325
|
-
#
|
326
|
-
#
|
327
|
-
#
|
328
|
-
# 'runtime' layer.
|
333
|
+
# - +key+ : key name. It do not support it to be a key tree (Arrays of
|
334
|
+
# keys).
|
335
|
+
# - +value+ : value to set
|
336
|
+
# - +options+ : possible options:
|
337
|
+
# - +:section+ : Force to use a specific section name.
|
338
|
+
# - +:name+ : layer to exclusively set data.
|
339
|
+
# - +:index+ : layer index to exclusively set data.
|
340
|
+
# If neither :name or :index is set, set will use the 'runtime' layer.
|
329
341
|
#
|
330
342
|
# * *Returns* :
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#
|
334
|
-
#
|
335
|
-
#
|
336
|
-
#
|
343
|
+
# - the value set
|
344
|
+
# OR
|
345
|
+
# - nil if:
|
346
|
+
# - lorj data model set this key as readonly.
|
347
|
+
# - value is nil. The value is set to nil, then.
|
348
|
+
# - key is nil. No update is done.
|
337
349
|
#
|
338
350
|
# * *Raises* :
|
339
351
|
# Nothing
|
@@ -344,22 +356,48 @@ module Lorj
|
|
344
356
|
key = parameters[0][0]
|
345
357
|
layer_name, section = parameters[1]
|
346
358
|
|
347
|
-
section = Lorj.
|
359
|
+
section = Lorj.data.first_section(key) if section.nil?
|
348
360
|
section = :default if section.nil?
|
349
361
|
|
350
362
|
return nil if readonly?(key, section)
|
351
363
|
|
352
364
|
options = { :keys => [key], :section => section, :value => value }
|
353
365
|
|
354
|
-
options[:
|
366
|
+
options[:index] = index_to_update(layer_name, key, section)
|
355
367
|
|
356
|
-
|
368
|
+
p_set(options)
|
357
369
|
end
|
358
370
|
|
371
|
+
# Set a key to te runtime config layer.
|
372
|
+
# Alternative is to use Account::set
|
359
373
|
def []=(key, value)
|
360
374
|
set(key, value)
|
361
375
|
end
|
362
376
|
|
377
|
+
# This function delete a section/key.
|
378
|
+
# If no section is defined, it will assume to be :default.
|
379
|
+
# Without any options, the runtime layer is used to delete the key.
|
380
|
+
#
|
381
|
+
# * *Args* :
|
382
|
+
# - +key+ : key name. It do not support it to be a key tree (Arrays of
|
383
|
+
# keys).
|
384
|
+
# - +value+ : value to set
|
385
|
+
# - +options+ : possible options:
|
386
|
+
# - +:section+ : Force to use a specific section name.
|
387
|
+
# - +:name+ : layer to exclusively get data.
|
388
|
+
# - +:index+ : layer index to exclusively get data.
|
389
|
+
# If neither :name or :index is set, set will use the 'runtime' layer.
|
390
|
+
#
|
391
|
+
# * *Returns* :
|
392
|
+
# - the value set
|
393
|
+
# OR
|
394
|
+
# - nil if:
|
395
|
+
# - lorj data model set this key as readonly.
|
396
|
+
# - value is nil. The value is set to nil, then.
|
397
|
+
# - key is nil. No update is done.
|
398
|
+
#
|
399
|
+
# * *Raises* :
|
400
|
+
# Nothing
|
363
401
|
def del(key, options = {})
|
364
402
|
parameters = validate_key_and_options(key, options)
|
365
403
|
return nil if parameters.nil?
|
@@ -374,19 +412,20 @@ module Lorj
|
|
374
412
|
|
375
413
|
options = { :keys => [key], :section => section }
|
376
414
|
|
377
|
-
options[:
|
415
|
+
options[:index] = index_to_update(layer_name, key, section)
|
378
416
|
|
379
|
-
|
417
|
+
p_del(options)
|
380
418
|
end
|
381
419
|
end
|
382
420
|
|
383
421
|
# Defines Account exclusive functions
|
384
422
|
class Account
|
385
|
-
def ac_new(sAccountName, provider_name
|
423
|
+
def ac_new(sAccountName, provider_name)
|
386
424
|
return nil if sAccountName.nil?
|
387
425
|
@account_name = sAccountName
|
426
|
+
index = layer_index('account')
|
388
427
|
|
389
|
-
account = @config_layers[
|
428
|
+
account = @config_layers[index][:config]
|
390
429
|
account.erase
|
391
430
|
account.ac_new sAccountName, provider_name
|
392
431
|
end
|
@@ -399,8 +438,9 @@ module Lorj
|
|
399
438
|
|
400
439
|
account_file = File.join(@account_path, @account_name)
|
401
440
|
return false unless File.exist?(account_file)
|
441
|
+
index = layer_index('account')
|
402
442
|
|
403
|
-
_do_load(@config_layers[
|
443
|
+
_do_load(@config_layers[index][:config], account_file)
|
404
444
|
end
|
405
445
|
|
406
446
|
# Account save function.
|
@@ -425,25 +465,30 @@ module Lorj
|
|
425
465
|
|
426
466
|
account_file = File.join(@account_path, @account_name)
|
427
467
|
|
428
|
-
|
429
|
-
|
468
|
+
local_index = layer_index('local')
|
469
|
+
account_index = layer_index('account')
|
470
|
+
|
471
|
+
account = @config_layers[account_index][:config]
|
472
|
+
local = @config_layers[local_index][:config]
|
430
473
|
|
431
474
|
account.data_options(:section => :account)
|
432
|
-
|
433
|
-
|
434
|
-
|
475
|
+
|
476
|
+
[:provider].each do |key|
|
477
|
+
next if account.exist?(key) && !account[key].nil?
|
478
|
+
|
479
|
+
PrcLib.error "':%s' is not set. Unable to save the account '"\
|
480
|
+
"%s' to '%s'", key.to_s, @account_name, account_file
|
435
481
|
return false
|
436
482
|
end
|
437
483
|
|
438
|
-
|
439
|
-
result = account.save
|
484
|
+
result = local.save
|
440
485
|
|
441
486
|
return result unless result
|
442
487
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
488
|
+
account.data_options(:section => :account)
|
489
|
+
account[:name] = @account_name
|
490
|
+
account.filename = account_file
|
491
|
+
account.save
|
447
492
|
|
448
493
|
true
|
449
494
|
end
|
@@ -451,8 +496,9 @@ module Lorj
|
|
451
496
|
|
452
497
|
# Defines internal functions
|
453
498
|
class Account
|
454
|
-
# TODO: Strange function!!! To revisit
|
499
|
+
# TODO: Strange function!!! To revisit. Used by forj cli in forj-settings.rb
|
455
500
|
|
501
|
+
#
|
456
502
|
def meta_type?(key)
|
457
503
|
return nil unless key
|
458
504
|
|
@@ -494,7 +540,7 @@ module Lorj
|
|
494
540
|
|
495
541
|
def exclusive_indexes(account_exclusive)
|
496
542
|
return [0, 1] if account_exclusive
|
497
|
-
[0, 1, 2, 3]
|
543
|
+
[0, 1, 2, 3, 4]
|
498
544
|
end
|
499
545
|
|
500
546
|
def _identify_indexes(options, account_exclusive)
|
@@ -516,8 +562,9 @@ module Lorj
|
|
516
562
|
data_options
|
517
563
|
end
|
518
564
|
|
519
|
-
# This internal function defines default section name per config index.
|
520
565
|
# TODO: Change local and default way to get default values, not in /:default
|
566
|
+
|
567
|
+
# This internal function defines default section name per config index.
|
521
568
|
def _data_options_per_layer(layer_name)
|
522
569
|
# runtime and local and default uses :default section
|
523
570
|
case layer_name
|
@@ -552,14 +599,14 @@ module Lorj
|
|
552
599
|
end
|
553
600
|
|
554
601
|
def index_to_update(layer_name, key, section)
|
555
|
-
|
556
|
-
|
602
|
+
index = 0 # choose runtime by default.
|
603
|
+
index = layer_index(layer_name) unless layer_name.nil?
|
557
604
|
|
558
605
|
if layer_name.nil?
|
559
606
|
# Return runtime layer, if layer requested is not updatable.
|
560
|
-
return
|
607
|
+
return 0 if index <= (exclusive?(key, section) ? 1 : 3)
|
561
608
|
end
|
562
|
-
|
609
|
+
index
|
563
610
|
end
|
564
611
|
|
565
612
|
def define_account_layer
|
data/lib/lorj_config.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
require 'rubygems'
|
18
18
|
require 'yaml'
|
19
19
|
|
20
|
+
# Definition of Lorj::Config
|
20
21
|
module Lorj
|
21
22
|
# Lorj::Config is a generic class for configuration management.
|
22
23
|
# It is used by lorj to get/set data
|
@@ -101,7 +102,7 @@ module Lorj
|
|
101
102
|
#
|
102
103
|
# * *Args* :
|
103
104
|
# - +config_name+ : Config file name to use. By default, file path is
|
104
|
-
# built as PrcLib.data_path
|
105
|
+
# built as #{PrcLib.data_path}/config.yaml
|
105
106
|
# * *Returns* :
|
106
107
|
# -
|
107
108
|
# * *Raises* :
|
@@ -112,8 +113,12 @@ module Lorj
|
|
112
113
|
# Application layer
|
113
114
|
config_layers << define_default_layer
|
114
115
|
|
116
|
+
# runtime Config layer
|
117
|
+
config_layers << define_controller_data_layer
|
118
|
+
|
115
119
|
# Local Config layer
|
116
|
-
|
120
|
+
local = define_local_layer
|
121
|
+
config_layers << local
|
117
122
|
|
118
123
|
# runtime Config layer
|
119
124
|
config_layers << define_runtime_layer
|
@@ -122,7 +127,7 @@ module Lorj
|
|
122
127
|
PrcLib.fatal(1, 'Internal PrcLib.data_path was not set.')
|
123
128
|
end
|
124
129
|
|
125
|
-
initialize_local(
|
130
|
+
initialize_local(local[:config], config_name)
|
126
131
|
|
127
132
|
initialize_layers(config_layers)
|
128
133
|
end
|
@@ -139,6 +144,10 @@ module Lorj
|
|
139
144
|
:load => true, :save => true)
|
140
145
|
end
|
141
146
|
|
147
|
+
def define_controller_data_layer
|
148
|
+
PRC::CoreConfig.define_layer :name => 'controller'
|
149
|
+
end
|
150
|
+
|
142
151
|
def define_runtime_layer
|
143
152
|
PRC::CoreConfig.define_layer
|
144
153
|
end
|
@@ -230,7 +239,7 @@ module Lorj
|
|
230
239
|
# * *Raises* :
|
231
240
|
# nothing
|
232
241
|
def [](key, default = nil) # Re-define PRC::CoreConfig []= function
|
233
|
-
return
|
242
|
+
return p_get(:keys => [key]) if exist?(key)
|
234
243
|
default
|
235
244
|
end
|
236
245
|
|
@@ -290,21 +299,6 @@ module Lorj
|
|
290
299
|
@config_layers[index][:config][key]
|
291
300
|
end
|
292
301
|
|
293
|
-
# Get Application data
|
294
|
-
# Used to get any kind of section available in the Application default.yaml.
|
295
|
-
#
|
296
|
-
# * *Args* :
|
297
|
-
# - +section+ : section name to get the key.
|
298
|
-
# - +keys_tree+ : list of key name tree
|
299
|
-
# * *Returns* :
|
300
|
-
# value found
|
301
|
-
# * *Raises* :
|
302
|
-
# nothing
|
303
|
-
def app_default(*keys)
|
304
|
-
return Lorj.defaults.data.rh_get(*keys) if keys.length > 0
|
305
|
-
nil
|
306
|
-
end
|
307
|
-
|
308
302
|
# Save the config.yaml file.
|
309
303
|
#
|
310
304
|
# * *Args* :
|