lorj 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/example/students_1/process/students.rb +1 -1
- data/example/students_1/student_v1.md +2 -0
- data/example/students_1/students.rb +2 -1
- data/example/students_2/process/students.rb +1 -1
- data/example/students_2/students.rb +4 -2
- data/example/students_3/controller/yaml_students_def.rb +1 -1
- data/example/students_3/process/students.rb +1 -1
- data/example/students_3/student_v3.md +5 -3
- data/example/students_3/students.rb +5 -3
- data/example/students_4/controller/yaml_students_def.rb +1 -1
- data/example/students_4/process/students/definition/students.rb +1 -1
- data/example/students_4/students.rb +5 -3
- data/example/students_5/controller/yaml_students.rb +1 -1
- data/example/students_5/process/students.rb +1 -1
- data/example/students_5/student_v5.md +4 -4
- data/example/students_5/students.rb +8 -7
- data/example/yaml_students/students.rb +4 -4
- data/lib/core/core.rb +110 -64
- data/lib/core/core_internal.rb +110 -15
- data/lib/core/core_object_data.rb +4 -4
- data/lib/core/core_process_setup.rb +3 -30
- data/lib/core/lorj_data.rb +1 -1
- data/lib/core/lorj_keypath.rb +3 -1
- data/lib/core/process.rb +67 -0
- data/lib/lorj/version.rb +2 -1
- data/lib/lorj.rb +3 -4
- data/lib/lorj_account.rb +6 -5
- data/lib/lorj_config.rb +3 -2
- data/lib/providers/templates/compute.rb +1 -1
- data/lorj-spec/controllers/mock/mock.rb +144 -0
- data/lorj-spec/data.yaml +0 -0
- data/lorj-spec/process/mock2_process.rb +48 -0
- data/lorj-spec/process/mock_process.rb +48 -0
- data/lorj-spec/providers/mock2/mock2.rb +0 -0
- data/lorj.gemspec +2 -4
- data/spec/05_lorj_keypath_spec.rb +78 -0
- data/spec/20_lorj_meta_spec.rb +1 -1
- data/spec/21_lorj_processes_spec.rb +115 -0
- metadata +27 -42
- data/lib/core_process/cloud/process/common.rb +0 -60
- data/lib/core_process/cloud/process/connection.rb +0 -92
- data/lib/core_process/cloud/process/external_network.rb +0 -90
- data/lib/core_process/cloud/process/flavor.rb +0 -97
- data/lib/core_process/cloud/process/images.rb +0 -99
- data/lib/core_process/cloud/process/internet_network.rb +0 -33
- data/lib/core_process/cloud/process/internet_server.rb +0 -29
- data/lib/core_process/cloud/process/keypairs.rb +0 -332
- data/lib/core_process/cloud/process/network.rb +0 -107
- data/lib/core_process/cloud/process/public_ip.rb +0 -102
- data/lib/core_process/cloud/process/router.rb +0 -267
- data/lib/core_process/cloud/process/rules.rb +0 -120
- data/lib/core_process/cloud/process/security_groups.rb +0 -120
- data/lib/core_process/cloud/process/server.rb +0 -126
- data/lib/core_process/cloud/process/server_log.rb +0 -34
- data/lib/core_process/cloud/process/subnetwork.rb +0 -96
- data/lib/core_process/cloud_process.rb +0 -30
- data/lib/prc_base_config.rb +0 -300
- data/lib/prc_core_config.rb +0 -1258
- data/lib/prc_section_config.rb +0 -90
- data/lib/providers/hpcloud/compute.rb +0 -105
- data/lib/providers/hpcloud/hpcloud.rb +0 -462
- data/lib/providers/hpcloud/network.rb +0 -115
- data/lib/providers/hpcloud/security_groups.rb +0 -68
- data/lib/providers/openstack/openstack.rb +0 -410
- data/lib/providers/openstack/openstack_create.rb +0 -205
- data/lib/providers/openstack/openstack_delete.rb +0 -28
- data/lib/providers/openstack/openstack_get.rb +0 -39
- data/lib/providers/openstack/openstack_process.rb +0 -26
- data/lib/providers/openstack/openstack_query.rb +0 -96
- data/lib/providers/openstack/openstack_update.rb +0 -35
- data/lib/rh.rb +0 -426
- data/spec/01_hash_rh_spec.rb +0 -282
- data/spec/02_prc_base_config_spec.rb +0 -227
- data/spec/03_prc_section_config_spec.rb +0 -196
- data/spec/04_prc_core_config_spec.rb +0 -325
data/lib/core/core_internal.rb
CHANGED
@@ -57,6 +57,7 @@ module Lorj
|
|
57
57
|
# - model : Basic model.
|
58
58
|
def initialize_model
|
59
59
|
{ :def_class => BaseDefinition,
|
60
|
+
:processes => [],
|
60
61
|
:process_class => nil, :process_class_name => nil,
|
61
62
|
:controller_class => nil, :controller_class_name => nil }
|
62
63
|
end
|
@@ -115,7 +116,7 @@ module Lorj
|
|
115
116
|
if the_controller.include?('/')
|
116
117
|
file = File.expand_path(the_controller)
|
117
118
|
else
|
118
|
-
file = controllerfile_from_default(the_controller)
|
119
|
+
file = controllerfile_from_default(model, the_controller)
|
119
120
|
end
|
120
121
|
|
121
122
|
return PrcLib.warning('Controller not loaded: Controller file '\
|
@@ -146,7 +147,7 @@ module Lorj
|
|
146
147
|
the_controller_process['.rb'] = '_process.rb'
|
147
148
|
file = File.expand_path(the_controller_process)
|
148
149
|
else
|
149
|
-
file = controllerfile_from_default(the_controller, '_process')
|
150
|
+
file = controllerfile_from_default(model, the_controller, '_process')
|
150
151
|
end
|
151
152
|
|
152
153
|
return Lorj.debug(2, 'Process not loaded: Process controller file '\
|
@@ -197,7 +198,7 @@ module Lorj
|
|
197
198
|
#
|
198
199
|
# * *Returns* :
|
199
200
|
# - file : absolute file path.
|
200
|
-
def controllerfile_from_default(the_controller, suffix = '')
|
201
|
+
def controllerfile_from_default(_model, the_controller, suffix = '')
|
201
202
|
File.join(PrcLib.controller_path, the_controller,
|
202
203
|
the_controller + suffix + '.rb')
|
203
204
|
end
|
@@ -211,26 +212,120 @@ module Lorj
|
|
211
212
|
#
|
212
213
|
# * *Args* :
|
213
214
|
# - +model+ : Application model loaded.
|
214
|
-
# - +processes+ :
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
215
|
+
# - +processes+ : Array of processes and controller to load
|
216
|
+
# - each element contains a Hash with:
|
217
|
+
# If you are using a process module, set the following:
|
218
|
+
# - :process_module : Name of the process module to load
|
219
|
+
#
|
220
|
+
# If you are not using a Process module, you need to set the following
|
221
|
+
# - :process_path : Path to a local process code.
|
222
|
+
# This path must contains at least 'process' subdir. And if needed
|
223
|
+
# a 'controllers' path
|
224
|
+
# - :process_name : Name of the local process
|
225
|
+
#
|
226
|
+
# Optionnally, you can set a controller name to use with the process.
|
227
|
+
# - :controller_name: Name of the controller to use.
|
228
|
+
# - :controller_path: Path to the controller file.
|
219
229
|
#
|
220
230
|
# * *Returns* :
|
221
231
|
# - model : Application model loaded.
|
222
232
|
def init_processes(model, processes)
|
223
|
-
|
233
|
+
processes.each do |a_process|
|
234
|
+
my_process = {}
|
224
235
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
236
|
+
if a_process.key?(:process_module)
|
237
|
+
my_process = _process_module_to_load(my_process, a_process)
|
238
|
+
else
|
239
|
+
my_process = _process_local_to_load(my_process, a_process)
|
229
240
|
end
|
241
|
+
|
242
|
+
next if my_process.nil?
|
243
|
+
|
244
|
+
model[:processes] << my_process
|
245
|
+
|
246
|
+
_process_load(model, my_process)
|
230
247
|
end
|
248
|
+
|
231
249
|
model
|
232
250
|
end
|
233
251
|
|
252
|
+
# high level function to load process
|
253
|
+
def _process_load(model, my_process)
|
254
|
+
if load_process(model, my_process[:process_path])
|
255
|
+
controller_class = my_process[:controller_path]
|
256
|
+
controller_class = my_process[:controller_name] if controller_class.nil?
|
257
|
+
|
258
|
+
init_controller(model, controller_class) if controller_class
|
259
|
+
else
|
260
|
+
PrcLib.warning("Process '%s' not properly loaded.",
|
261
|
+
my_process[:process_path])
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# function prepare of loading a local process
|
266
|
+
def _process_local_to_load(my_process, a_process)
|
267
|
+
my_process[:process_path] = a_process[:process_path]
|
268
|
+
|
269
|
+
if a_process[:process_name].nil?
|
270
|
+
my_process[:process_name] = File.basename(a_process[:process_path])
|
271
|
+
else
|
272
|
+
my_process[:process_name] = a_process[:process_name]
|
273
|
+
end
|
274
|
+
|
275
|
+
if a_process[:controller_path]
|
276
|
+
my_process[:controller_path] = a_process[:controller_path]
|
277
|
+
else
|
278
|
+
my_process[:controller_name] = a_process[:controller_name]
|
279
|
+
end
|
280
|
+
my_process
|
281
|
+
end
|
282
|
+
|
283
|
+
# Function prepare of loading a module process.
|
284
|
+
def _process_module_to_load(my_process, a_process)
|
285
|
+
name = a_process[:process_module]
|
286
|
+
|
287
|
+
if name.nil?
|
288
|
+
PrcLib.warning(':process_module is empty. Process not properly loaded.')
|
289
|
+
return
|
290
|
+
end
|
291
|
+
|
292
|
+
name = name.to_s if name.is_a?(Symbol)
|
293
|
+
|
294
|
+
unless Lorj.processes.key?(name)
|
295
|
+
PrcLib.warning("Unable to find Process module '%s'. Process not "\
|
296
|
+
'properly loaded.', name)
|
297
|
+
return
|
298
|
+
end
|
299
|
+
|
300
|
+
module_process = Lorj.processes[name]
|
301
|
+
my_process[:process_name] = name
|
302
|
+
my_process[:process_path] = module_process.process
|
303
|
+
|
304
|
+
if a_process[:controller_path]
|
305
|
+
my_process[:controller_path] = a_process[:controller_path]
|
306
|
+
return my_process
|
307
|
+
end
|
308
|
+
|
309
|
+
_process_module_set_ctr(my_process, module_process.controllers,
|
310
|
+
a_process[:controller_name])
|
311
|
+
|
312
|
+
my_process
|
313
|
+
end
|
314
|
+
|
315
|
+
def _process_module_set_ctr(my_process, controllers, controller_name)
|
316
|
+
return if controller_name.nil?
|
317
|
+
|
318
|
+
controller_path = controllers[controller_name]
|
319
|
+
|
320
|
+
if controller_path.nil?
|
321
|
+
PrcLib.warning("Controller '%s' was not found. Please check. The "\
|
322
|
+
'process may not work.', controller_name)
|
323
|
+
return
|
324
|
+
end
|
325
|
+
|
326
|
+
my_process[:controller_path] = controller_path
|
327
|
+
end
|
328
|
+
|
234
329
|
# Function analyzing the process class parameter
|
235
330
|
# and return the list of processes in an
|
236
331
|
# array of processes.
|
@@ -266,7 +361,7 @@ module Lorj
|
|
266
361
|
if the_process.include?('/')
|
267
362
|
file = File.expand_path(the_process)
|
268
363
|
else
|
269
|
-
file = processfile_from_default(the_process)
|
364
|
+
file = processfile_from_default(model, the_process)
|
270
365
|
end
|
271
366
|
|
272
367
|
return PrcLib.warning("Process file definition '%s' is missing. ",
|
@@ -311,7 +406,7 @@ module Lorj
|
|
311
406
|
# * *Returns* :
|
312
407
|
# - file : absolute file path composed by:
|
313
408
|
# PrcLib.process_path/the_process_class + '.rb'
|
314
|
-
def processfile_from_default(the_process_class)
|
409
|
+
def processfile_from_default(_model, the_process_class)
|
315
410
|
File.join(PrcLib.process_path, the_process_class + '.rb')
|
316
411
|
end
|
317
412
|
|
@@ -172,7 +172,7 @@ module Lorj
|
|
172
172
|
if obj.is_a?(Symbol)
|
173
173
|
object_type = obj
|
174
174
|
obj = @params[object_type]
|
175
|
-
@params
|
175
|
+
@params.delete(object_type)
|
176
176
|
else
|
177
177
|
object_data_delete(obj)
|
178
178
|
end
|
@@ -236,8 +236,8 @@ module Lorj
|
|
236
236
|
|
237
237
|
def type?(key)
|
238
238
|
return nil unless @params.rh_exist?(key)
|
239
|
+
return :DataObject if @params[key].type == :object
|
239
240
|
:data
|
240
|
-
:DataObject if @params[key].type == :object
|
241
241
|
end
|
242
242
|
|
243
243
|
def to_s
|
@@ -327,10 +327,10 @@ module Lorj
|
|
327
327
|
" framework data Object. Is a '%s'",
|
328
328
|
obj.class unless obj.is_a?(Lorj::Data)
|
329
329
|
if obj.type == :list
|
330
|
-
@params.
|
330
|
+
@params.rh_del(:query, obj.object_type?)
|
331
331
|
else
|
332
332
|
object_type = obj.object_type?
|
333
|
-
@params
|
333
|
+
@params.delete(object_type)
|
334
334
|
end
|
335
335
|
end
|
336
336
|
|
@@ -118,23 +118,19 @@ module Lorj
|
|
118
118
|
#
|
119
119
|
# * *Args* :
|
120
120
|
# - +ObjectType+ : Top object type to ask.
|
121
|
-
# - +sAccountName+ : Optional. Account Name to load if you are using a
|
122
|
-
# Lorj::Account Object.
|
123
121
|
#
|
124
122
|
# * *Returns* :
|
125
123
|
# - nothing.
|
126
124
|
#
|
127
125
|
# * *Raises* :
|
128
126
|
#
|
129
|
-
def process_setup(sObjectType
|
127
|
+
def process_setup(sObjectType)
|
130
128
|
unless PrcLib.model.meta_obj.rh_exist?(sObjectType)
|
131
129
|
PrcLib.runtime_fail "Setup: '%s' not a valid object type."
|
132
130
|
end
|
133
131
|
|
134
132
|
setup_steps = _setup_load
|
135
133
|
|
136
|
-
return nil unless _process_setup_init(sAccountName)
|
137
|
-
|
138
134
|
Lorj.debug(2, "Setup is identifying account data to ask for '%s'",
|
139
135
|
sObjectType)
|
140
136
|
# Loop in dependencies to get list of data object to setup
|
@@ -147,35 +143,12 @@ module Lorj
|
|
147
143
|
|
148
144
|
_setup_ask(setup_steps)
|
149
145
|
|
150
|
-
PrcLib.info("Configuring account : '#{
|
151
|
-
" provider '#{config[:
|
146
|
+
PrcLib.info("Configuring account : '#{config[:name]}',"\
|
147
|
+
" provider '#{config[:provider]}'")
|
152
148
|
end
|
153
149
|
|
154
150
|
private
|
155
151
|
|
156
|
-
# Internal function to initialize the account.
|
157
|
-
#
|
158
|
-
# return true if initialized, false otherwise.
|
159
|
-
def _process_setup_init(sAccountName)
|
160
|
-
return false unless sAccountName
|
161
|
-
|
162
|
-
if @config.ac_load(sAccountName)
|
163
|
-
if @config[:provider] != @config[:provider_name]
|
164
|
-
s_ask = format("Account '%s' was configured with a different "\
|
165
|
-
"provider '%s'.\nAre you sure to re-initialize this "\
|
166
|
-
"account with '%s' provider instead? "\
|
167
|
-
'All data will be lost',
|
168
|
-
sAccountName, @config[:provider],
|
169
|
-
@config[:provider_name])
|
170
|
-
PrcLib.fatal(0, 'Exited by user request.') unless agree(s_ask)
|
171
|
-
@config.ac_new(sAccountName, config[:provider_name])
|
172
|
-
end
|
173
|
-
else
|
174
|
-
@config.ac_new(sAccountName, config[:provider_name])
|
175
|
-
end
|
176
|
-
true
|
177
|
-
end
|
178
|
-
|
179
152
|
# Internal function to insert the data after several data to ask.
|
180
153
|
#
|
181
154
|
# * *Args* :
|
data/lib/core/lorj_data.rb
CHANGED
@@ -547,7 +547,7 @@ module Lorj
|
|
547
547
|
|
548
548
|
def elem_exist?(*key)
|
549
549
|
return true if key[0] == :object && @data.key?(key[0])
|
550
|
-
return true if key[0] == :attrs
|
550
|
+
return true if key[0] == :attrs && @data.rh_exist?(key)
|
551
551
|
(@data.rh_lexist?(:attrs, key) == key.length + 1)
|
552
552
|
end
|
553
553
|
|
data/lib/core/lorj_keypath.rb
CHANGED
@@ -113,7 +113,9 @@ module Lorj
|
|
113
113
|
private
|
114
114
|
|
115
115
|
def string_to_sarray(sKeyPath)
|
116
|
-
|
116
|
+
# rubocop: disable Style/RegexpLiteral
|
117
|
+
if %r{[^\\/]?/[^/]} =~ sKeyPath || %r{:[^:/]} =~ sKeyPath
|
118
|
+
# rubocop: enable Style/RegexpLiteral
|
117
119
|
# keypath to interpret
|
118
120
|
res = sKeyPath.split('/')
|
119
121
|
res.each_index do |iIndex|
|
data/lib/core/process.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# Define process module management in Lorj
|
19
|
+
#
|
20
|
+
module Lorj
|
21
|
+
# This class defines a Process module
|
22
|
+
#
|
23
|
+
#
|
24
|
+
class ProcessResource
|
25
|
+
attr_reader :defaults_file, :data_file, :process, :name, :controllers
|
26
|
+
|
27
|
+
def initialize(name, path, props = {})
|
28
|
+
# Determine resources
|
29
|
+
name = name.to_s if name.is_a?(Symbol)
|
30
|
+
|
31
|
+
process_path = File.expand_path(File.join(path, 'process',
|
32
|
+
name + '_process.rb'))
|
33
|
+
|
34
|
+
return nil unless File.exist?(process_path)
|
35
|
+
@process = process_path
|
36
|
+
@name = name
|
37
|
+
|
38
|
+
controller_dir = 'controllers'
|
39
|
+
controller_dir = props[:controllers_dir] if props.key?(:controllers_dir)
|
40
|
+
controller_path = File.expand_path(File.join(path, controller_dir))
|
41
|
+
|
42
|
+
_identify_controllers(controller_path)
|
43
|
+
|
44
|
+
defaults_file = File.expand_path(File.join(path, 'defaults.yaml'))
|
45
|
+
@defaults_file = defaults_file if File.exist?(defaults_file)
|
46
|
+
|
47
|
+
data_file = File.expand_path(File.join(path, 'data.yaml'))
|
48
|
+
@data_file = data_file if File.exist?(data_file)
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def _identify_controllers(controller_path)
|
56
|
+
@controllers = {}
|
57
|
+
|
58
|
+
Dir.foreach(controller_path) do |dir|
|
59
|
+
next if dir.match(/^\.\.?$/)
|
60
|
+
|
61
|
+
next unless File.exist?(File.join(controller_path, dir, dir + '.rb'))
|
62
|
+
|
63
|
+
@controllers[dir] = File.join(controller_path, dir, dir + '.rb')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/lorj/version.rb
CHANGED
data/lib/lorj.rb
CHANGED
@@ -23,12 +23,10 @@ require 'lorj/version'
|
|
23
23
|
|
24
24
|
# To use it, add require 'lorj'
|
25
25
|
|
26
|
+
require 'config_layers' # ConfigLayers
|
27
|
+
|
26
28
|
require 'prc.rb' # PrcLib Base module
|
27
|
-
require 'rh.rb' # recursive Hash
|
28
29
|
require 'logging.rb' # class PrcLib::Logging
|
29
|
-
require 'prc_base_config.rb' # PRC::BaseConfig class
|
30
|
-
require 'prc_section_config.rb' # PRC::SectionConfig class
|
31
|
-
require 'prc_core_config.rb' # PRC::CoreConfig class
|
32
30
|
require 'lorj_meta.rb' # PRC::Meta class - Application defaults
|
33
31
|
require 'lorj_defaults.rb' # PRC::Defaults class - Application defaults
|
34
32
|
require 'lorj_config.rb' # Lorj::Config class -
|
@@ -54,6 +52,7 @@ require 'core/lorj_basecontroller' # Lorj Lorj::BaseController object
|
|
54
52
|
require 'core/lorj_keypath' # Lorj Lorj::BaseDefinition object
|
55
53
|
require 'core/definition' # Lorj Process definition
|
56
54
|
require 'core/definition_internal' # Lorj internal functions
|
55
|
+
require 'core/process' # Lorj Process Module feature
|
57
56
|
|
58
57
|
# lorj module
|
59
58
|
module Lorj
|
data/lib/lorj_account.rb
CHANGED
@@ -139,7 +139,7 @@ module Lorj
|
|
139
139
|
# - local : Represents the config.yaml located in ~/.forj
|
140
140
|
# - account : Represents an Account data located in ~/.forj/accounts
|
141
141
|
# - runtime : Represents the runtime in memory data settings.
|
142
|
-
def initialize(config_name = nil)
|
142
|
+
def initialize(config_name = nil, latest_version = nil)
|
143
143
|
config_layers = []
|
144
144
|
|
145
145
|
# Application layer
|
@@ -149,11 +149,11 @@ module Lorj
|
|
149
149
|
config_layers << define_controller_data_layer
|
150
150
|
|
151
151
|
# Local Config layer
|
152
|
-
local = define_local_layer
|
152
|
+
local = define_local_layer(latest_version)
|
153
153
|
config_layers << local
|
154
154
|
|
155
155
|
# Account config layer
|
156
|
-
config_layers << define_account_layer
|
156
|
+
config_layers << define_account_layer(latest_version)
|
157
157
|
|
158
158
|
# runtime Config layer
|
159
159
|
config_layers << define_runtime_layer
|
@@ -650,9 +650,10 @@ module Lorj
|
|
650
650
|
index
|
651
651
|
end
|
652
652
|
|
653
|
-
def define_account_layer
|
653
|
+
def define_account_layer(latest_version = nil)
|
654
654
|
PRC::CoreConfig.define_layer(:name => 'account',
|
655
|
-
:config =>
|
655
|
+
:config => \
|
656
|
+
Lorj::AccountConfig.new(nil, latest_version),
|
656
657
|
:file_set => true,
|
657
658
|
:load => true, :save => true)
|
658
659
|
end
|
data/lib/lorj_config.rb
CHANGED
@@ -138,9 +138,10 @@ module Lorj
|
|
138
138
|
:set => false, :load => true)
|
139
139
|
end
|
140
140
|
|
141
|
-
def define_local_layer
|
141
|
+
def define_local_layer(latest_version = nil)
|
142
142
|
PRC::CoreConfig.define_layer(:name => 'local',
|
143
|
-
:config =>
|
143
|
+
:config => \
|
144
|
+
PRC::SectionConfig.new(nil, latest_version),
|
144
145
|
:load => true, :save => true)
|
145
146
|
end
|
146
147
|
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# This class describes how to process some actions, and will do everything prior
|
18
|
+
# this task to make it to work.
|
19
|
+
|
20
|
+
# This Mock controller keep the data in memory in hash/Array data.
|
21
|
+
class Mock
|
22
|
+
# mock do not need to use any mapping. It adapts itself to what the process
|
23
|
+
# has defined.
|
24
|
+
end
|
25
|
+
|
26
|
+
# This Mock controller keep the data in memory in hash/Array data.
|
27
|
+
class MockController
|
28
|
+
@@data = {} # rubocop: disable ClassVars
|
29
|
+
|
30
|
+
def create(sObjectType, hParams)
|
31
|
+
PrcLib.debug("Mock: create object '%s' with parameters (hdata) '%s'",
|
32
|
+
sObjectType, hParams[:hdata])
|
33
|
+
|
34
|
+
result = {}
|
35
|
+
hParams[].keys.each do |key|
|
36
|
+
next if key == :hdata
|
37
|
+
result[key] = hParams[key]
|
38
|
+
end
|
39
|
+
result.merge!(hParams[:hdata])
|
40
|
+
|
41
|
+
@@data[sObjectType] = [] unless @@data.key?(sObjectType)
|
42
|
+
|
43
|
+
array = @@data[sObjectType]
|
44
|
+
|
45
|
+
array.each do |value|
|
46
|
+
fail if value.key?(result[:name])
|
47
|
+
end
|
48
|
+
array << result
|
49
|
+
|
50
|
+
result[:id] = array.length - 1
|
51
|
+
|
52
|
+
# Typical code:
|
53
|
+
# ~ case sObjectType
|
54
|
+
# ~ when :public_ip
|
55
|
+
# Following function can be executed to ensure the object :connection exists
|
56
|
+
# ~ required?(hParams, :connection)
|
57
|
+
# ~ required?(hParams, :server)
|
58
|
+
# ~ ... CODE to create
|
59
|
+
# ~ else
|
60
|
+
# ~ controller_error "'%s' is not a valid object for 'create'", sObjectType
|
61
|
+
# ~ end
|
62
|
+
# The code should return some data
|
63
|
+
# This data will be encapsulated in Lorj::Data object.
|
64
|
+
# data will be extracted by the framework with the controller get_attr
|
65
|
+
# function and mapped.
|
66
|
+
PrcLib.debug("Mock: object '%s' = '%s' is created.", sObjectType, result)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
# This function return a collection which have to provide:
|
71
|
+
# functions: [], length, each
|
72
|
+
# Used by network process.
|
73
|
+
def query(sObjectType, sQuery, hParams)
|
74
|
+
PrcLib.debug("Mock: query object '%s' with hdata '%s' using query '%s'",
|
75
|
+
sObjectType, hParams[:hdata], sQuery)
|
76
|
+
|
77
|
+
return [] unless @@data.key?(sObjectType)
|
78
|
+
|
79
|
+
result = []
|
80
|
+
|
81
|
+
@@data[sObjectType].each do |value|
|
82
|
+
elem = value
|
83
|
+
sQuery.each do |query_key, query_value|
|
84
|
+
elem = nil if !value.key?(query_key) || value[query_key] != query_value
|
85
|
+
end
|
86
|
+
result << elem if elem
|
87
|
+
end
|
88
|
+
result
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete(sObjectType, hParams)
|
92
|
+
PrcLib.debug("Mock: delete object '%s' with hdata '%s'",
|
93
|
+
sObjectType, hParams[:hdata])
|
94
|
+
return nil unless @@data.key?(sObjectType)
|
95
|
+
|
96
|
+
return false if !hParams.exist?(sObjectType) || hParams[sObjectType].nil?
|
97
|
+
@@data[sObjectType].delete(hParams[sObjectType])
|
98
|
+
PrcLib.debug("Mock: object '%s' = '%s' is deleted.",
|
99
|
+
sObjectType, hParams[sObjectType])
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
def get(sObjectType, sUniqId, hParams)
|
104
|
+
PrcLib.debug("Mock: Get object '%s' = '%s' with hdata '%s'",
|
105
|
+
sObjectType, sUniqId, hParams[:hdata])
|
106
|
+
return nil unless @@data.key?(sObjectType)
|
107
|
+
@@data[sObjectType][sUniqId]
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_attr(oControlerObject, key)
|
111
|
+
# This controller function read the data and
|
112
|
+
# extract the information requested by the framework.
|
113
|
+
# Those data will be mapped to the process data model.
|
114
|
+
# The key is an array, to get data from a level tree.
|
115
|
+
# [data_l1, data_l2, data_l3] => should retrieve data from structure like
|
116
|
+
# data[ data_l2[ data_l3 ] ]
|
117
|
+
attributes = oControlerObject
|
118
|
+
|
119
|
+
attributes.rh_get(key)
|
120
|
+
rescue => e
|
121
|
+
controller_error "Unable to map '%s'.\n%s", key, e.message
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_attr(oControlerObject, key, value)
|
125
|
+
attributes = oControlerObject
|
126
|
+
|
127
|
+
attributes.rh_set(value, key)
|
128
|
+
rescue => e
|
129
|
+
controller_error "Unable to map '%s' on '%s'.\n%s",
|
130
|
+
key, sObjectType, e.message
|
131
|
+
end
|
132
|
+
|
133
|
+
def update(sObjectType, oObject, hParams)
|
134
|
+
PrcLib.debug("Mock: Update object '%s' = '%s' with hdata '%s'",
|
135
|
+
sObjectType, sUniqId, hParams[:hdata])
|
136
|
+
return false unless @@data.key?(sObjectType)
|
137
|
+
|
138
|
+
return false unless @@data[sObjectType][oObject[:id]].nil?
|
139
|
+
# Considered hash object is already updated.
|
140
|
+
# This action emule the object save which doesn't make sense in this empty
|
141
|
+
# Mock controller.
|
142
|
+
true
|
143
|
+
end
|
144
|
+
end
|
data/lorj-spec/data.yaml
ADDED
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# Students process
|
18
|
+
class StudentsProcess
|
19
|
+
def create_student(sObjectType, hParams)
|
20
|
+
PrcLib.state(format("Running creation process for object '%s' = '%s'",
|
21
|
+
sObjectType, hParams[:student_name]))
|
22
|
+
# byebug if ENV['BYEBUG'] # rubocop: disable Debugger
|
23
|
+
object = controller_create(sObjectType)
|
24
|
+
PrcLib.runtime_fail "Student '%s' not created.",
|
25
|
+
hParams[:student_name] if object.nil?
|
26
|
+
PrcLib.info("'%s': '%s' created with id %s",
|
27
|
+
sObjectType, hParams[:student_name], object[:id])
|
28
|
+
object
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Declaring your data model and handlers.
|
33
|
+
class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
|
34
|
+
# We need to define the student object and the handler to use while we need to
|
35
|
+
# create it.
|
36
|
+
define_obj(:student,
|
37
|
+
# The function to call in the class Students
|
38
|
+
:create_e => :create_student,
|
39
|
+
# We use predefined call to the controller query
|
40
|
+
:query_e => :controller_query,
|
41
|
+
# We use predefined call to the controller get
|
42
|
+
:get_e => :controller_get,
|
43
|
+
# We use predefined call to the controller delete
|
44
|
+
:delete_e => :controller_delete
|
45
|
+
)
|
46
|
+
|
47
|
+
obj_needs :data, :student_name, :for => [:create_e], :mapping => :name
|
48
|
+
end
|