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/lorj_defaults.rb
CHANGED
@@ -33,7 +33,10 @@ module Lorj
|
|
33
33
|
# For setup meta data, use Lorj.defaults.get_meta,
|
34
34
|
# Lorj.defaults.get_meta_auto or Lorj.defaults.get_meta_section
|
35
35
|
#
|
36
|
-
# defaults.yaml is divided in 3 sections
|
36
|
+
# defaults.yaml is divided in 3 sections.
|
37
|
+
# But only defaults section is loaded in Defaults instance.
|
38
|
+
# Defaults implements a AppConfig class, which provides meta data access
|
39
|
+
# Accessible through PrcLib.appdata
|
37
40
|
#
|
38
41
|
# * :default: Contains a list of key = value representing the application
|
39
42
|
# default configuration.
|
@@ -52,233 +55,10 @@ module Lorj
|
|
52
55
|
# # => test
|
53
56
|
#
|
54
57
|
# * :setup: Contains :ask_step array
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# Array of group of keys/values to setup. Each group will be
|
58
|
-
# internally identified by a index starting at 0. parameters are as
|
59
|
-
# follow:
|
60
|
-
# - :desc: string to print out before group setup
|
61
|
-
#
|
62
|
-
# ERB template enable: To get config data in ERB context, use
|
63
|
-
# config[...]
|
64
|
-
#
|
65
|
-
# - :explanation: longer string to display after :desc:
|
66
|
-
#
|
67
|
-
# It is printed out in brown color.
|
68
|
-
#
|
69
|
-
# It supports ERB template. To get config data, type
|
70
|
-
# <%= config[...] %>
|
71
|
-
#
|
72
|
-
# In your defaults.yaml file, write multiline with |- after the key.
|
73
|
-
#
|
74
|
-
# Ex: if config['text'] returns 'text', defaults.yaml can have the
|
75
|
-
# following explanation.
|
76
|
-
#
|
77
|
-
# [...]
|
78
|
-
# :explanation: |-
|
79
|
-
# My complete explanation is in
|
80
|
-
# multiline <%= config['text'] %>
|
81
|
-
# [...]
|
82
|
-
#
|
83
|
-
#
|
84
|
-
# - :add: array of keys to add manually in the group. The Array can be
|
85
|
-
# written with [] or list of dash elements
|
86
|
-
#
|
87
|
-
# Example of a defaults.yaml content:
|
88
|
-
#
|
89
|
-
# [...]
|
90
|
-
# :ports: [22, 25]
|
91
|
-
#
|
92
|
-
# :ports:
|
93
|
-
# - 22
|
94
|
-
# - 25
|
95
|
-
# [...]
|
96
|
-
#
|
97
|
-
# By default, thanks to data model dependency, the group is
|
98
|
-
# automatically populated. So, you need update this part only for
|
99
|
-
# data that are not found from the dependency.
|
58
|
+
# For details, see Lorj::MetaAppConfig
|
100
59
|
# * :section: Contains a list of sections with several keys and attributes
|
101
60
|
# and eventually :default:
|
102
|
-
#
|
103
|
-
# This list of sections and keys will be used to build the account files
|
104
|
-
# with the lorj Lorj::Core.setup function.
|
105
|
-
# Those data is accessible through the Lorj.defaults.get_meta,
|
106
|
-
# Lorj.defaults.get_meta_auto or Lorj.defaults.get_meta_section
|
107
|
-
#
|
108
|
-
# Ex:
|
109
|
-
# # Use Lorj.defaults.data exceptionnaly
|
110
|
-
# Lorj.defaults.data.merge({sections: {:mysection: {key: {
|
111
|
-
# data1: 'test1',
|
112
|
-
# data2: 'test2'
|
113
|
-
# }}}})
|
114
|
-
#
|
115
|
-
# puts Lorj.defaults.get_meta(:mysection, :key)
|
116
|
-
# # => { data1: 'test1', data2: 'test2' }
|
117
|
-
# puts Lorj.defaults.get_meta(:mysection)
|
118
|
-
# # => {:key => { data1: 'test1', data2: 'test2' }}
|
119
|
-
# puts Lorj.defaults.get_meta_section(:key)
|
120
|
-
# # => :mysection
|
121
|
-
# puts Lorj.defaults.get_meta_auto(:key)
|
122
|
-
# # => { data1: 'test1', data2: 'test2' }
|
123
|
-
#
|
124
|
-
# - :default: This section define updatable data available from config.yaml.
|
125
|
-
# But will never be added in an account file.
|
126
|
-
#
|
127
|
-
# It contains a list of key and options.
|
128
|
-
#
|
129
|
-
# - :<aKey>: Possible options
|
130
|
-
# - :desc: default description for that <aKey>
|
131
|
-
#
|
132
|
-
# - :<aSectionName>: Name of the section which should contains a list
|
133
|
-
# - :<aKeyName>: Name of the key to setup.
|
134
|
-
# - :desc:
|
135
|
-
#
|
136
|
-
# Description of that key, printed out at setup time.
|
137
|
-
#
|
138
|
-
# - :readonly: true if this key is not modifiable by a simple
|
139
|
-
#
|
140
|
-
# Lorj::Account::set function. false otherwise.
|
141
|
-
#
|
142
|
-
# - :account_exclusive: true if the key cannot be set as default from
|
143
|
-
# config.yaml or defaults.yaml.
|
144
|
-
#
|
145
|
-
# - :account: true to ask setup to ask this key to the user.
|
146
|
-
#
|
147
|
-
# - :validate: Ruby Regex to validate the end user input.
|
148
|
-
#
|
149
|
-
# Ex: !ruby/regexp /^\w?\w*$/
|
150
|
-
#
|
151
|
-
# - :default_value: default value proposed to the user.
|
152
|
-
#
|
153
|
-
# - :ask_step: Define the group number to attach the key to be
|
154
|
-
# asked. ex: 2
|
155
|
-
#
|
156
|
-
# - :list_values: Provide capabililities to get a list and choose
|
157
|
-
# from.
|
158
|
-
#
|
159
|
-
# - :query_type: Can be:
|
160
|
-
#
|
161
|
-
# ':query_call' to execute a query on flavor, query_params is empty
|
162
|
-
# for all.
|
163
|
-
#
|
164
|
-
# ':process_call' to execute a process function to get the values.
|
165
|
-
#
|
166
|
-
# ':controller_call' to execute a controller query.
|
167
|
-
#
|
168
|
-
# - :object:
|
169
|
-
#
|
170
|
-
# Used with :query_type=:query_call. object type symbol to query.
|
171
|
-
#
|
172
|
-
# - :query
|
173
|
-
#
|
174
|
-
# Used with :query_type=:process_call. process function name to call
|
175
|
-
#
|
176
|
-
# - :query_call:
|
177
|
-
#
|
178
|
-
# Used with :query_type=:controller_call. Handler function to use.
|
179
|
-
# (query_e, create_e, ...)
|
180
|
-
#
|
181
|
-
# Used with :query_type=:process_call. Function name to call
|
182
|
-
#
|
183
|
-
# - :query_params:
|
184
|
-
#
|
185
|
-
# Used with :query_type=:query_call. Query hash defining filtering
|
186
|
-
# capabilities.
|
187
|
-
#
|
188
|
-
# Used with :query_type=:process_call. hParams data passed to the
|
189
|
-
# process function.
|
190
|
-
#
|
191
|
-
# - :value:
|
192
|
-
#
|
193
|
-
# fields to extract for the list of objects displayed.
|
194
|
-
#
|
195
|
-
# - :validate:
|
196
|
-
#
|
197
|
-
# if :list_strict, the value is limited to the possible values from
|
198
|
-
# the list
|
199
|
-
|
200
|
-
# meta data are defined in defaults.yaml and loaded in Lorj::Default class
|
201
|
-
# definition.
|
202
|
-
# Cloud provider can redefine ForjData defaults and add some extra
|
203
|
-
# parameters.
|
204
|
-
# To get Application defaults, read defaults.yaml, under :sections:
|
205
|
-
# Those values can be updated by the controller with define_data
|
206
|
-
# <Section>:
|
207
|
-
# <Data>: Required. Symbol/String. default: nil
|
208
|
-
# => Data name. This symbol must be unique, across
|
209
|
-
# sections.
|
210
|
-
# :desc: Required. String. default: nil
|
211
|
-
# => Description
|
212
|
-
# :explanation: |- Print a multiline explanation before ask the key
|
213
|
-
# value.
|
214
|
-
# ERB template enable. To get config data,
|
215
|
-
# type <%= config[...] %>
|
216
|
-
# :readonly: Optional. true/false. Default: false
|
217
|
-
# => oForjConfig.set() will fail if readonly is
|
218
|
-
# true. It can be set, only thanks to:
|
219
|
-
# - oForjConfig.setup()
|
220
|
-
# or using private
|
221
|
-
# - oForjConfig._set()
|
222
|
-
# :account_exclusive: Optional. true/false. Default: false
|
223
|
-
# => Only oConfig.account_get/set() can handle the
|
224
|
-
# value
|
225
|
-
# oConfig.set/get cannot.
|
226
|
-
# :account: Optional. default: False
|
227
|
-
# => setup will configure the account with this
|
228
|
-
# <Data>
|
229
|
-
# :ask_sort: Number which represents the ask order in the
|
230
|
-
# step group. (See /:setup/:ask_step for details)
|
231
|
-
# :after: <Data> Name of the previous <Data> to ask before the
|
232
|
-
# current one.
|
233
|
-
# :depends_on:
|
234
|
-
# => Identify :data type required to be set before
|
235
|
-
# the current one.
|
236
|
-
# :default_value: Default value at setup time. This is not
|
237
|
-
# necessarily the Application default value
|
238
|
-
# (See /:default)
|
239
|
-
# :validate: Regular expression to validate end user input
|
240
|
-
# during setup.
|
241
|
-
# :value_mapping: list of values to map as defined by the
|
242
|
-
# controller
|
243
|
-
# :controller: mapping for get controller value from process
|
244
|
-
# values
|
245
|
-
# <value> : <map> value map equivalence. See data_value_mapping
|
246
|
-
# function
|
247
|
-
# :process: mapping for get process value from controller
|
248
|
-
# values
|
249
|
-
# <value> : <map> value map equivalence. See data_value_mapping
|
250
|
-
# function
|
251
|
-
# :default: Default value. Replace /:default/<data>
|
252
|
-
# :list_values: Defines a list of valid values for the current
|
253
|
-
# data.
|
254
|
-
# :query_type :controller_call to execute a function defined
|
255
|
-
# in the controller object.
|
256
|
-
# :process_call to execute a function defined in
|
257
|
-
# the process object.
|
258
|
-
# :values to get list of values from :values.
|
259
|
-
# :object Object to load before calling the function.
|
260
|
-
# Only :query_type = :*_call
|
261
|
-
# :query_call Symbol. function name to call.
|
262
|
-
# Only :query_type = :*_call
|
263
|
-
# function must return an Array.
|
264
|
-
# :query_params Hash. Controler function parameters.
|
265
|
-
# Only :query_type = :*_call
|
266
|
-
# :validate :list_strict. valid only if value is one of
|
267
|
-
# thoselisted.
|
268
|
-
# :values: to retrieve from.
|
269
|
-
# otherwise define simply a list of possible
|
270
|
-
# values.
|
271
|
-
# :ask_step: Step number. By default, setup will determine
|
272
|
-
# the step, thanks to meta lorj object
|
273
|
-
# dependencies tree.
|
274
|
-
# This number start at 0. Each step can be defined
|
275
|
-
# by /:setup/:ask_step/<steps> list.
|
276
|
-
# :pre_step_function: Process called before asking the data.
|
277
|
-
# if it returns true, user interaction is
|
278
|
-
# cancelled.
|
279
|
-
# :post_step_function:Process called after asking the data.
|
280
|
-
# if it returns false, the user is requested to
|
281
|
-
# re-enter a new value.
|
61
|
+
# For details, see Lorj::MetaAppConfig
|
282
62
|
#
|
283
63
|
# :setup: This section describes group of fields to ask,
|
284
64
|
# step by step.
|
@@ -303,39 +83,39 @@ module Lorj
|
|
303
83
|
# If config doesn't exist, it will be created, empty with 'defaults:' only
|
304
84
|
|
305
85
|
# Loop on Config metadata
|
306
|
-
#
|
86
|
+
# This function is obsolete. Use Lorj.metadata.meta_each instead
|
307
87
|
#
|
308
88
|
# * *Args* :
|
309
|
-
# -
|
89
|
+
# - +code+ : Block of code on `section`, `key`, `value`
|
90
|
+
#
|
310
91
|
# * *Returns* :
|
311
|
-
# -
|
312
|
-
# * *Raises* :
|
313
|
-
# - ++ ->
|
92
|
+
# - nothing
|
314
93
|
def meta_each
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
94
|
+
PrcLib.debug("'Lorj.defaults.%s' is obsolete and will be removed "\
|
95
|
+
'in Lorj 2.0. Please update your code to call '\
|
96
|
+
"'Lorj.data.%s' instead.\n%s",
|
97
|
+
__method__, 'meta_each', caller[0])
|
98
|
+
Lorj.data.meta_each do |section, key, value|
|
99
|
+
yield section, key, value
|
321
100
|
end
|
322
101
|
end
|
323
102
|
|
324
|
-
#
|
103
|
+
# Check existence of the key in metadata.
|
104
|
+
# This function is obsolete. Use Lorj.metadata.auto_meta_exist? instead
|
105
|
+
# Consider also the Lorj.metadata.auto_meta_exist? which check from a
|
106
|
+
# section name, a well.
|
325
107
|
#
|
326
108
|
# * *Args* :
|
327
|
-
# -
|
109
|
+
# - +key+ : Key name to check.
|
110
|
+
#
|
328
111
|
# * *Returns* :
|
329
|
-
# -
|
330
|
-
# * *Raises* :
|
331
|
-
# - ++ ->
|
112
|
+
# - true if found, false otherwise.
|
332
113
|
def meta_exist?(key)
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
@data.rh_exist?(:sections, section, key)
|
114
|
+
PrcLib.debug("'Lorj.defaults.%s' is obsolete and will be removed "\
|
115
|
+
'in Lorj 2.0. Please update your code to call '\
|
116
|
+
"'Lorj.data.%s' instead.\n%s",
|
117
|
+
__method__, 'auto_meta_exist?', caller[0])
|
118
|
+
Lorj.data.auto_meta_exist?(key)
|
339
119
|
end
|
340
120
|
|
341
121
|
# Get model data options. Section name is determined by the associated
|
@@ -352,11 +132,12 @@ module Lorj
|
|
352
132
|
# - data was not found. defined in /:sections/<section>/<data
|
353
133
|
# * *Raises* :
|
354
134
|
# - ++ ->
|
355
|
-
def get_meta_auto(*
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
135
|
+
def get_meta_auto(data, *options)
|
136
|
+
PrcLib.debug("'Lorj.defaults.%s' is obsolete and will be removed "\
|
137
|
+
'in Lorj 2.0. Please update your code to call '\
|
138
|
+
"'Lorj.data.%s' instead.\n%s",
|
139
|
+
__method__, 'auto_section_data', caller[0])
|
140
|
+
Lorj.data.auto_section_data(data, *options)
|
360
141
|
end
|
361
142
|
|
362
143
|
# def get_meta_section(*keys)
|
@@ -379,39 +160,12 @@ module Lorj
|
|
379
160
|
# - data was not found. defined in /:sections/<section>/<data
|
380
161
|
# * *Raises* :
|
381
162
|
# - ++ ->
|
382
|
-
def get_meta(*
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
#
|
389
|
-
# * *Args* :
|
390
|
-
# - ++ ->
|
391
|
-
# * *Returns* :
|
392
|
-
# -
|
393
|
-
# * *Raises* :
|
394
|
-
# - ++ ->
|
395
|
-
def build_section_mapping
|
396
|
-
if @data.rh_get(:sections).nil?
|
397
|
-
PrcLib.warning('defaults.yaml do not defines :sections')
|
398
|
-
return nil
|
399
|
-
end
|
400
|
-
|
401
|
-
# TODO: Support multiple identical key name on distinct sections
|
402
|
-
# The primary data key should change from key to section & key.
|
403
|
-
@data.rh_get(:sections).each do |section, hValue|
|
404
|
-
next if section == :default
|
405
|
-
hValue.each_key do |map_key|
|
406
|
-
if @account_section_mapping.rh_exist?(map_key)
|
407
|
-
PrcLib.fatal(1, 'defaults.yaml: Duplicate entry between sections. '\
|
408
|
-
"'%s' defined in section '%s' already exists in"\
|
409
|
-
" section '%s'", map_key, section,
|
410
|
-
@account_section_mapping.rh_get(map_key))
|
411
|
-
end
|
412
|
-
@account_section_mapping.rh_set(section, map_key)
|
413
|
-
end
|
414
|
-
end
|
163
|
+
def get_meta(section, data, *options)
|
164
|
+
PrcLib.debug("'Lorj.defaults.%s' is obsolete and will be removed "\
|
165
|
+
'in Lorj 2.0. Please update your code to call '\
|
166
|
+
"'Lorj.data.%s' instead.\n%s",
|
167
|
+
__method__, 'section_data', caller[0])
|
168
|
+
Lorj.data.section_data(section, data, *options)
|
415
169
|
end
|
416
170
|
|
417
171
|
#
|
@@ -423,8 +177,11 @@ module Lorj
|
|
423
177
|
# * *Raises* :
|
424
178
|
# - ++ ->
|
425
179
|
def get_meta_section(key)
|
426
|
-
|
427
|
-
|
180
|
+
PrcLib.debug("'Lorj.defaults.%s' is obsolete and will be removed "\
|
181
|
+
'in Lorj 2.0. Please update your code to call '\
|
182
|
+
"'Lorj.data.%s' instead.\n%s",
|
183
|
+
__method__, 'first_section', caller[0])
|
184
|
+
Lorj.data.first_section(key)
|
428
185
|
end
|
429
186
|
|
430
187
|
#
|
@@ -436,8 +193,6 @@ module Lorj
|
|
436
193
|
# * *Raises* :
|
437
194
|
# - ++ ->
|
438
195
|
def load
|
439
|
-
@account_section_mapping = {}
|
440
|
-
|
441
196
|
if !PrcLib.app_defaults
|
442
197
|
PrcLib.warning('PrcLib.app_defaults is not set. Application defaults'\
|
443
198
|
" won't be loaded.")
|
@@ -447,9 +202,8 @@ module Lorj
|
|
447
202
|
PrcLib.info("Reading default configuration '%s'...", @filename)
|
448
203
|
|
449
204
|
if File.exist?(@filename)
|
450
|
-
|
205
|
+
p_load(@filename)
|
451
206
|
|
452
|
-
build_section_mapping
|
453
207
|
else
|
454
208
|
PrcLib.warning("PrcLib.app_defaults is set to '%s'. Trying to load"\
|
455
209
|
" '%s' but not found. Application defaults won't "\
|