lorj 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +39 -579
  4. data/Rakefile +7 -0
  5. data/example/students_1/student_v1.md +115 -0
  6. data/example/students_1/students.rb +8 -2
  7. data/example/students_2/process/students.rb +5 -5
  8. data/example/students_2/student_v2.md +90 -0
  9. data/example/students_2/students.rb +6 -6
  10. data/example/students_3/controller/yaml_students.rb +23 -73
  11. data/example/students_3/controller/yaml_students_code.rb +106 -0
  12. data/example/students_3/controller/yaml_students_def.rb +69 -0
  13. data/example/students_3/process/students.rb +23 -157
  14. data/example/students_3/student_v3.md +283 -0
  15. data/example/students_3/students.rb +26 -83
  16. data/example/students_4/controller/yaml_students.rb +51 -0
  17. data/example/students_4/controller/yaml_students_code.rb +109 -0
  18. data/example/students_4/controller/yaml_students_def.rb +72 -0
  19. data/example/students_4/process/students/code/students.rb +103 -0
  20. data/example/students_4/process/students/definition/students.rb +60 -0
  21. data/example/students_4/process/students.rb +29 -0
  22. data/example/students_4/student_v4.md +191 -0
  23. data/example/students_4/students.rb +65 -0
  24. data/example/students_5/controller/yaml_students.rb +106 -0
  25. data/example/{students_3 → students_5}/controller/yaml_students_controller.rb +5 -3
  26. data/example/students_5/process/students.rb +182 -0
  27. data/example/students_5/student_v5.md +382 -0
  28. data/example/students_5/students.rb +119 -0
  29. data/example/yaml_students/students.rb +1 -1
  30. data/example/yaml_students/yaml_students.rb +102 -23
  31. data/lib/concept.md +3 -3
  32. data/lib/core/core.rb +15 -15
  33. data/lib/core/core_controller.rb +49 -24
  34. data/lib/core/core_internal.rb +2 -2
  35. data/lib/core/core_model.rb +13 -7
  36. data/lib/core/core_object_data.rb +18 -18
  37. data/lib/core/core_object_params.rb +75 -34
  38. data/lib/core/core_process.rb +104 -59
  39. data/lib/core/core_process_setup.rb +11 -11
  40. data/lib/core/core_setup_ask.rb +24 -14
  41. data/lib/core/core_setup_encrypt.rb +17 -15
  42. data/lib/core/core_setup_init.rb +19 -15
  43. data/lib/core/core_setup_list.rb +12 -12
  44. data/lib/core/definition.rb +20 -20
  45. data/lib/core/definition_internal.rb +20 -10
  46. data/lib/core/lorj_basecontroller.rb +8 -8
  47. data/lib/core/lorj_basedefinition.rb +47 -126
  48. data/lib/core/lorj_baseprocess.rb +81 -57
  49. data/lib/core/lorj_data.rb +28 -27
  50. data/lib/core/lorj_keypath.rb +1 -1
  51. data/lib/core_process/cloud/process/flavor.rb +3 -2
  52. data/lib/core_process/cloud/process/keypairs.rb +5 -4
  53. data/lib/core_process/cloud/process/network.rb +4 -3
  54. data/lib/core_process/cloud/process/public_ip.rb +3 -2
  55. data/lib/core_process/cloud/process/rules.rb +7 -6
  56. data/lib/core_process/cloud/process/security_groups.rb +1 -1
  57. data/lib/core_process/cloud/process/server.rb +1 -1
  58. data/lib/core_process/cloud/process/server_log.rb +1 -1
  59. data/lib/core_process/cloud/process/subnetwork.rb +4 -1
  60. data/lib/core_process/cloud_process.rb +1 -1
  61. data/lib/logging.rb +41 -48
  62. data/lib/lorj/version.rb +1 -1
  63. data/lib/lorj.rb +7 -0
  64. data/lib/lorj_account.rb +3 -3
  65. data/lib/lorj_config.rb +1 -1
  66. data/lib/lorj_defaults.rb +222 -26
  67. data/lib/overview.md +120 -0
  68. data/lib/prc.rb +97 -24
  69. data/lib/prc_core_config.rb +134 -52
  70. data/lib/providers/hpcloud/compute.rb +3 -3
  71. data/lib/providers/hpcloud/hpcloud.rb +14 -14
  72. data/lib/providers/hpcloud/network.rb +4 -4
  73. data/lib/providers/hpcloud/security_groups.rb +1 -1
  74. data/lib/providers/mock/mock.rb +3 -3
  75. data/lib/providers/openstack/openstack.rb +12 -12
  76. data/lib/providers/templates/compute.rb +6 -6
  77. data/lib/rh.rb +7 -5
  78. data/spec/04_prc_core_config_spec.rb +52 -0
  79. data/spec/11_lorj_config_spec.rb +1 -1
  80. metadata +21 -3
@@ -57,24 +57,21 @@ module Lorj
57
57
 
58
58
  @config = oForjConfig
59
59
  @erb_config = ERBConfig.new(oForjConfig)
60
- fail Lorj::PrcError.new, "'%s' is not a valid ForjAccount or ForjConfig"\
61
- ' Object.',
62
- [oForjConfig.class] if
63
- !oForjConfig.is_a?(Lorj::Account) &&
64
-
65
- !oForjConfig.is_a?(Lorj::Config)
66
-
60
+ if !oForjConfig.is_a?(Lorj::Account) && !oForjConfig.is_a?(Lorj::Config)
61
+ PrcLib.runtime_fail "'%s' is not a valid ForjAccount or ForjConfig"\
62
+ ' Object.', oForjConfig.class
63
+ end
67
64
  @controller = controller
68
- if controller
69
- runtime_fail "'%s' is not a valid ForjProvider Object type.",
70
- controller.class unless controller.is_a?(BaseController)
65
+ unless controller.nil? || controller.is_a?(BaseController)
66
+ PrcLib.runtime_fail "'%s' is not a valid BaseController Object type.",
67
+ controller.class
71
68
  end
72
69
 
73
70
  @process = process
74
- fail Lorj::PrcError.new, "'%s' is not a valid BaseProcess Object type.",
75
- [process.class] unless process.is_a?(BaseProcess)
71
+ PrcLib.runtime_fail "'%s' is not a valid BaseProcess Object type.",
72
+ process.class unless process.is_a?(BaseProcess)
76
73
 
77
- @process.base_object(self)
74
+ @process.base_object = self
78
75
  end
79
76
 
80
77
  # ------------------------------------------------------
@@ -98,9 +95,8 @@ module Lorj
98
95
  # config.get(key)
99
96
  # OR
100
97
  # config[key]
101
-
102
98
  def config
103
- fail Lorj::PrcError.new, 'No config object loaded.' unless @config
99
+ PrcLib.runtime_fail 'No config object loaded.' unless @config
104
100
  @config
105
101
  end
106
102
 
@@ -140,87 +136,69 @@ module Lorj
140
136
  maps = PrcLib.model.meta_obj.rh_get(object_type, :query_mapping)
141
137
  hParams.each do |key, value|
142
138
  key_path_obj = KeyPath.new(key)
143
- key_path = key_path_obj.fpath
139
+
140
+ bold_action = ANSI.bold('ACTION REQUIRED')
144
141
  PrcLib.runtime_fail "Forj query field '%s.%s' not defined by class"\
145
- " '%s'.\n#{ANSI.bold}ACTION REQUIRED#{ANSI.clear}"\
142
+ " '%s'.\n#{bold_action}"\
146
143
  ":\nMissing data model 'def_attribute' or "\
147
144
  "'def_query_attribute' for '%s'??? "\
148
145
  "Check the object '%s' data model.",
149
146
  object_type, key_path_obj.key,
150
147
  self.class, key_path_obj.key,
151
148
  object_type unless maps.key?(key_path_obj.fpath)
152
- map_path = KeyPath.new(maps[key_path_obj.fpath])
153
- value_mapping = PrcLib.model.meta_obj.rh_get(object_type,
154
- :value_mapping, key_path)
155
- if value_mapping
156
- PrcLib.runtime_fail "'%s.%s': No value mapping for '%s'",
157
- object_type, key_path_obj.key,
158
- value unless value_mapping.rh_exist?(value)
159
149
 
160
- result.rh_set(value_mapping[value], map_path.tree)
161
- else
162
- result.rh_set(value, map_path.tree)
163
- end
150
+ next if maps[key_path_obj.fpath].nil?
151
+
152
+ map_path = KeyPath.new(maps[key_path_obj.fpath])
153
+ _query_value_mapping(object_type, result, key_path_obj, map_path, value)
164
154
  end
165
155
  result
166
156
  end
167
157
 
168
- # Obsolete. Used by the Process.
169
- # Ask controller get_attr to get a data
170
- # The result is the data of a defined data attribute.
171
- # If the value is normally mapped (value mapped), the value is
172
- # returned as a recognized data attribute value.
173
- # def get_attr(oObject, key)
174
- # fail Lorj::PrcError.new, "'%s' is not a valid Object type. " % [oObject.
175
- # class] if !oObject.is_a?(Hash) &&
176
- # ! oObject.rh_exist?(:object_type)
177
- # sCloudObj = oObject[:object_type]
178
- # oKeyPath = KeyPath.new(key)
179
- # fail Lorj::PrcError.new, "'%s' key is not declared as data of '%s' "\
180
- # 'CloudObject. You may need to add obj_needs...'
181
- # % [oKeyPath.key, sCloudObj] if PrcLib.model.meta_obj.rh_exist?(sClou
182
- # dObj, :returns, oKeyPath.fpath) != 3
183
- # begin
184
- # oMapPath = KeyPath.new PrcLib.model.meta_obj.rh_get(sCloudObj, :
185
- # returns, oKeyPath.fpath)
186
- # hMap = oMapPath.fpath
187
- # value = @controller.get_attr(get_cObject(oObject), hMap)
188
-
189
- # hValueMapping = PrcLib.model.meta_obj.rh_get(sCloudObj, :value_m
190
- # apping, oKeyPath.fpath)
158
+ def _query_value_mapping(object_type, result, key_path_obj, map_path, value)
159
+ key_path = key_path_obj.fpath
160
+ value_mapping = PrcLib.model.meta_obj.rh_get(object_type, :value_mapping,
161
+ key_path)
162
+ if value_mapping
163
+ PrcLib.runtime_fail "'%s.%s': No value mapping for '%s'",
164
+ object_type, key_path_obj.key,
165
+ value unless value_mapping.rh_exist?(value)
191
166
 
192
- # if hValueMapping
193
- # hValueMapping.each do | found_key, found_value |
194
- # if found_value == value
195
- # value = found_key
196
- # break
197
- # end
198
- # end
199
- # end
200
- # rescue => e
201
- # raise Lorj::PrcError.new, "'%s.get_attr' fails to provide value of '%s'
202
- # " % [oProvider.class, key]
203
- # end
204
- # end
167
+ result.rh_set(value_mapping[value], map_path.tree)
168
+ else
169
+ result.rh_set(value, map_path.tree)
170
+ end
171
+ nil
172
+ end
205
173
 
206
174
  # Register the object to the internal @object_data instance
207
175
  def register(oObject, sObjectType = nil, sDataType = :object)
208
176
  if oObject.is_a?(Lorj::Data)
209
177
  data_objects = oObject
210
178
  else
211
- runtime_fail "Unable to register an object '%s' "\
212
- 'as Lorj::Data object if ObjectType is not given.',
213
- oObject.class unless sObjectType
179
+ PrcLib.runtime_fail "Unable to register an object '%s' "\
180
+ 'as Lorj::Data object if ObjectType is not given.',
181
+ oObject.class unless sObjectType
214
182
  data_objects = Lorj::Data.new(sDataType)
215
- data_objects.set(oObject, sObjectType) do | sObjType, oControlerObject |
183
+ data_objects.set(oObject, sObjectType) do |sObjType, oControlerObject|
216
184
  _return_map(sObjType, oControlerObject)
217
185
  end
218
186
  end
219
187
  @object_data.add data_objects
220
188
  end
221
189
 
190
+ # Function to get Lorj core data cache.
191
+ #
192
+ # *Args*
193
+ # - object_type : Object type to get
194
+ # - *key : tree of keys to get values.
195
+ # The syntax is defined by Lorj::Data[]
196
+ #
197
+ # *Return*
198
+ # - Value of the Lorj::Data cached key.
199
+ #
222
200
  def data_objects(sObjectType, *key)
223
- @object_data[sObjectType, key]
201
+ @object_data[sObjectType, *key]
224
202
  end
225
203
 
226
204
  # get an attribute/object/... from an object.
@@ -234,56 +212,11 @@ module Lorj
234
212
  object_data[oObj, *key]
235
213
  end
236
214
 
237
- # ~ def hParams(sCloudObj, hParams)
238
- # ~ aParams = _get_object_params(sCloudObj, ":ObjectData.hParams")
239
- # ~ end
240
-
241
- # def get_cObject(oObject)
242
- # return nil unless oObject.rh_exist?(:object)
243
- # oObject.rh_get(:object)
244
- # end
245
-
246
215
  private
247
216
 
248
217
  # -------------------------------------------------------------------------
249
218
  # Functions available for Process to communicate with the controler Object
250
219
  # -------------------------------------------------------------------------
251
- # def cloud_obj_requires(sCloudObj, res = {})
252
- # aCaller = caller
253
- # aCaller.pop
254
-
255
- # return res if @object_data.exist?(sCloudObj)
256
- # # ~ return res if Lorj::rh_exist?(@CloudData, sCloudObj)
257
-
258
- # PrcLib.model.meta_obj.rh_get(sCloudObj, :params).each do |
259
- # key, hParams|
260
- # case hParams[:type]
261
- # when :data
262
- # if hParams.key?(:array)
263
- # hParams[:array].each do | aElem |
264
- # aElem = aElem.clone
265
- # aElem.pop # Do not go until last level, as used to loop next.
266
- # hParams.rh_get(aElem).each do | subkey, _hSubParam |
267
- # next if aElem.length == 0 && [:array, :type].include?(subkey)
268
- # if hSubParams[:required] && @config.get(subkey).nil?
269
- # res[subkey] = hSubParams
270
- # end
271
- # end
272
- # end
273
- # else
274
- # if hParams[:required] && @config.get(key).nil?
275
- # res[key] = hParams
276
- # end
277
- # end
278
- # when :CloudObject
279
- # if hParams[:required] && !@object_data.exist?(sCloudObj)
280
- # res[key] = hParams
281
- # cloud_obj_requires(key, res)
282
- # end
283
- # end
284
- # end
285
- # res
286
- # end
287
220
 
288
221
  def get_object(sCloudObj)
289
222
  # ~ return nil unless Lorj::rh_exist?(@CloudData, sCloudObj)
@@ -291,17 +224,5 @@ module Lorj
291
224
  @object_data[sCloudObj, :ObjectData]
292
225
  # ~ Lorj::rh_get(@CloudData, sCloudObj)
293
226
  end
294
-
295
- # def objectExist?(sCloudObj)
296
- # @object_data.exist?(sCloudObj)
297
- # # ~ !(Lorj::rh_exist?(@CloudData, sCloudObj))
298
- # end
299
-
300
- # def get_forjKey(sCloudObj, key)
301
- # return nil unless @object_data.exist?(sCloudObj)
302
- # @object_data[sCloudObj, :attrs, key]
303
- # # ~ return nil unless Lorj::rh_exist?(oCloudData, sCloudObj)
304
- # # ~ Lorj::rh_get(oCloudData, sCloudObj, :attrs, key)
305
- # end
306
227
  end
307
228
  end
@@ -30,7 +30,7 @@ module Lorj
30
30
  # with controller calls
31
31
  class BaseProcess
32
32
  def initialize
33
- @definition = nil
33
+ @base_object = nil
34
34
  end
35
35
 
36
36
  # Simply raise an error
@@ -43,39 +43,45 @@ module Lorj
43
43
  # - Lorj::PrcError
44
44
  def process_error(msg, *p)
45
45
  msg = format(msg, *p)
46
- runtime_fail '%s: %s', self.class, msg
46
+ fail Lorj::PrcError.new, format('%s: %s', self.class, msg)
47
47
  end
48
48
 
49
49
  attr_writer :base_object
50
50
 
51
- def controller_connect(sObjectType, hParams = {})
52
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
53
- @definition.controller_connect(sObjectType, hParams)
51
+ def controller_connect(sObjectType, params = nil)
52
+ process_error 'No Controler object loaded.' unless @base_object
53
+ params = nil unless params.is_a?(Hash)
54
+ @base_object.controller_connect(sObjectType, params)
54
55
  end
55
56
 
56
- def controller_create(sObjectType, hParams = {})
57
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
58
- @definition.controller_create(sObjectType, hParams)
57
+ def controller_create(sObjectType, params = nil)
58
+ process_error 'No Controler object loaded.' unless @base_object
59
+ params = nil unless params.is_a?(Hash)
60
+ @base_object.controller_create(sObjectType, params)
59
61
  end
60
62
 
61
- def controller_query(sObjectType, sQuery, hParams = {})
62
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
63
- @definition.controller_query(sObjectType, sQuery, hParams)
63
+ def controller_query(sObjectType, sQuery, params = nil)
64
+ process_error 'No Controler object loaded.' unless @base_object
65
+ params = nil unless params.is_a?(Hash)
66
+ @base_object.controller_query(sObjectType, sQuery, params)
64
67
  end
65
68
 
66
- def controller_update(sObjectType, hParams = {})
67
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
68
- @definition.controller_update(sObjectType, hParams)
69
+ def controller_update(sObjectType, params = nil)
70
+ process_error 'No Controler object loaded.' unless @base_object
71
+ params = nil unless params.is_a?(Hash)
72
+ @base_object.controller_update(sObjectType, params)
69
73
  end
70
74
 
71
- def controller_delete(sObjectType, hParams = {})
72
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
73
- @definition.controller_delete(sObjectType, hParams)
75
+ def controller_delete(sObjectType, params = nil)
76
+ process_error 'No Controler object loaded.' unless @base_object
77
+ params = nil unless params.is_a?(Hash)
78
+ @base_object.controller_delete(sObjectType, params)
74
79
  end
75
80
 
76
- def controller_get(sObjectType, sId, hParams = {})
77
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
78
- @definition.controller_get(sObjectType, sId, hParams)
81
+ def controller_get(sObjectType, sId, params = nil)
82
+ process_error 'No Controler object loaded.' unless @base_object
83
+ params = nil unless params.is_a?(Hash)
84
+ @base_object.controller_get(sObjectType, sId, params)
79
85
  end
80
86
  end
81
87
 
@@ -83,28 +89,28 @@ module Lorj
83
89
  # with process calls
84
90
  class BaseProcess
85
91
  def process_create(sObjectType)
86
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
87
- @definition.process_create(sObjectType)
92
+ process_error 'No Base object loaded.' unless @base_object
93
+ @base_object.process_create(sObjectType)
88
94
  end
89
95
 
90
96
  def process_query(sObjectType, sQuery)
91
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
92
- @definition.process_query(sObjectType, sQuery)
97
+ process_error 'No Base object loaded.' unless @base_object
98
+ @base_object.process_query(sObjectType, sQuery)
93
99
  end
94
100
 
95
101
  def process_update(sObjectType)
96
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
97
- @definition.process_update(sObjectType)
102
+ process_error 'No Base object loaded.' unless @base_object
103
+ @base_object.process_update(sObjectType)
98
104
  end
99
105
 
100
106
  def process_get(sObjectType, sId)
101
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
102
- @definition.process_get(sObjectType, sId)
107
+ process_error 'No Base object loaded.' unless @base_object
108
+ @base_object.process_get(sObjectType, sId)
103
109
  end
104
110
 
105
111
  def process_delete(sObjectType)
106
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
107
- @definition.process_delete(sObjectType)
112
+ process_error 'No Base object loaded.' unless @base_object
113
+ @base_object.process_delete(sObjectType)
108
114
  end
109
115
  end
110
116
 
@@ -114,62 +120,62 @@ module Lorj
114
120
  private
115
121
 
116
122
  def query_cache_cleanup(sObjectType)
117
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
118
- @definition.query_cleanup(sObjectType)
123
+ fail Lorj::PrcError.new, 'No Base object loaded.' unless @base_object
124
+ @base_object.query_cleanup(sObjectType)
119
125
  end
120
126
 
121
127
  def object_cache_cleanup(sObjectType)
122
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
123
- @definition.object_cleanup(sObjectType)
128
+ fail Lorj::PrcError.new, 'No Base object loaded.' unless @base_object
129
+ @base_object.object_cleanup(sObjectType)
124
130
  end
125
131
 
126
132
  def controler
127
133
  PrcLib.warning('controler object call is obsolete. Please update your'\
128
134
  " code. Use controller_<action> instead.\n%s", caller)
129
- fail Lorj::PrcError.new, 'No Controler object loaded.' unless @definition
130
- @definition
135
+ PrcLib.runtime_fail 'No Controler object loaded.' unless @base_object
136
+ @base_object
131
137
  end
132
138
 
133
139
  def object
134
140
  PrcLib.warning('object call is obsolete. Please update your code.'\
135
141
  "Use <Action> instead.\n%s", caller)
136
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
137
- @definition
142
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
143
+ @base_object
138
144
  end
139
145
 
140
146
  def format_object(sObjectType, oMiscObj)
141
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
142
- @definition.format_object(sObjectType, oMiscObj)
147
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
148
+ @base_object.format_object(sObjectType, oMiscObj)
143
149
  end
144
150
 
145
151
  def format_query(sObjectType, oMiscObj, hQuery)
146
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
147
- @definition.format_list(sObjectType, oMiscObj, hQuery)
152
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
153
+ @base_object.format_list(sObjectType, oMiscObj, hQuery)
148
154
  end
149
155
 
150
156
  def data_objects(sObjectType, *key)
151
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
152
- @definition.data_objects(sObjectType, *key)
157
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
158
+ @base_object.data_objects(sObjectType, *key)
153
159
  end
154
160
 
155
161
  def get_data(oObj, *key)
156
162
  PrcLib.warning('get_data call is obsolete. Please update your code. '\
157
163
  "Use [] instead.\n%s", caller)
158
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
159
- @definition.get_data(oObj, :attrs, key)
164
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
165
+ @base_object.get_data(oObj, :attrs, key)
160
166
  end
161
167
 
162
168
  def register(oObject, sObjectType = nil)
163
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
164
- @definition.register(oObject, sObjectType)
169
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
170
+ @base_object.register(oObject, sObjectType)
165
171
  end
166
172
 
167
173
  def config
168
- fail Lorj::PrcError.new, 'No Base object loaded.' unless @definition
169
- @definition.config
174
+ PrcLib.runtime_fail 'No Base object loaded.' unless @base_object
175
+ @base_object.config
170
176
  end
171
177
 
172
- def query_single(sCloudObj, list, sQuery, name, sInfoMsg = {})
178
+ def query_single(sCloudObj, sQuery, name, sInfoMsg = {})
173
179
  list = controller_query(sCloudObj, sQuery)
174
180
 
175
181
  info = _qs_info_init(sInfoMsg)
@@ -214,22 +220,40 @@ module Lorj
214
220
  class BaseProcess
215
221
  private
216
222
 
223
+ # Internal Function to printout a format string
224
+ #
225
+ # *Args*
226
+ # - list : ObjectData
227
+ # - items: Symbol or Array of symbols
228
+ # - items_format : String format supported by format function
229
+ #
230
+ # *return:
231
+ # - formated string thanks to data extracted from list.
232
+ # If the key is not found (or value nil) from list,
233
+ # an error message is return to the formated string
234
+ # with the wrong key.
235
+ #
217
236
  def _qs_info(list, items, items_form)
218
237
  items_built = []
219
238
  if items.is_a?(Array)
220
- items.each do | key |
221
- items_built << list[0, key]
239
+ items.each do |key|
240
+ items_built << _qs_value(list, 0, key)
222
241
  end
223
242
  else
224
- items_built << list[0, items]
243
+ items_built << _qs_value(list, 0, items)
225
244
  end
226
- format(items_form, items_built)
245
+ format(items_form, *items_built)
246
+ end
247
+
248
+ def _qs_value(list, index, key)
249
+ value = list[index, key]
250
+ (value.nil? ? format("\"key '%s' unknown\"", key) : value)
227
251
  end
228
252
 
229
253
  def _qs_check_match(list, sQuery)
230
- list.each do | oElem |
254
+ list.each do |oElem|
231
255
  is_found = true
232
- sQuery.each do | key, value |
256
+ sQuery.each do |key, value|
233
257
  if oElem[key] != value
234
258
  is_found = false
235
259
  break
@@ -155,11 +155,31 @@ module Lorj
155
155
  @data[:object] = oObj
156
156
  @data[:attrs] = yield(sObjType, oObj)
157
157
  when :list
158
- list_set(oObj, sObjType, hQuery)
158
+ list_set(oObj, sObjType, hQuery) do |object_type, object|
159
+ yield(object_type, object)
160
+ end
159
161
  end
160
162
  self
161
163
  end
162
164
 
165
+ def to_s
166
+ str = format("-- Lorj::Data --\nType: %s\nContent:\n", @type)
167
+ str += format('%s <= ', @data[:object_type])
168
+ str += format("(%s) :\n", @data[:object].class)
169
+ if @type != :list
170
+ str += @data[:attrs].to_yaml
171
+ return str
172
+ end
173
+ str += format("query:\n%s", @data[:query].to_yaml)
174
+ str += format("\nlist count: %s\n", @data[:list].length)
175
+ elem_print = []
176
+ @data[:list].each do |elem|
177
+ elem_print << elem.to_s
178
+ end
179
+ str += elem_print.to_yaml
180
+ str
181
+ end
182
+
163
183
  # Set the :object type
164
184
  #
165
185
  # * *Args* :
@@ -347,25 +367,6 @@ module Lorj
347
367
  @data[:object].nil?
348
368
  end
349
369
 
350
- # Redefine nil? Warning! Can be confused. Cannot see if your object is
351
- # simply nil or if current object is simply empty.
352
- # Use empty? instead.
353
- # A warning will be raised soon to ask developer to update it.
354
- #
355
- # * *Args* :
356
- # No parameters
357
- #
358
- # * *Returns* :
359
- # - true/false
360
- #
361
- # * *Raises* :
362
- # No exceptions
363
- #
364
- def nil?
365
- # Obsolete Use empty? instead.
366
- @data[:object].nil?
367
- end
368
-
369
370
  # return 0, 1 or N if the Lorj::Data object is nil.
370
371
  # 0 if no objects stored
371
372
  # 1 if an object exist even if type :object or :list
@@ -414,7 +415,7 @@ module Lorj
414
415
  end
415
416
 
416
417
  return if to_remove.length <= 0
417
- to_remove.each { | elem | @data[:list].delete(elem) }
418
+ to_remove.each { |elem| @data[:list].delete(elem) }
418
419
  end
419
420
 
420
421
  # yield loop on a list
@@ -441,7 +442,7 @@ module Lorj
441
442
  end
442
443
  return if to_remove.length <= 0
443
444
 
444
- to_remove.each { | elem | @data[:list].delete(elem) }
445
+ to_remove.each { |elem| @data[:list].delete(elem) }
445
446
  end
446
447
 
447
448
  # A Lorj::Data can be cached by Lorj::ObjectData.
@@ -502,7 +503,7 @@ module Lorj
502
503
  return self if oObj.nil?
503
504
 
504
505
  begin
505
- oObj.each do | oElemObject |
506
+ oObj.each do |oElemObject|
506
507
  next if oElemObject.nil?
507
508
  begin
508
509
  data_obj = Lorj::Data.new(:object)
@@ -511,13 +512,13 @@ module Lorj
511
512
  end
512
513
  @data[:list] << data_obj
513
514
  rescue => e
514
- runtime_fail "'%s' Mapping attributes issue.\n%s",
515
- sObjType, e.message
515
+ PrcLib.runtime_fail "'%s' Mapping attributes issue.\n%s",
516
+ sObjType, e.message
516
517
  end
517
518
  end
518
519
  rescue => e
519
- runtime_fail "each function is not supported by '%s'.\n%s",
520
- oObj.class, e.message
520
+ PrcLib.runtime_fail "each function is not supported by '%s'.\n%s",
521
+ oObj.class, e.message
521
522
  end
522
523
  self
523
524
  end
@@ -106,7 +106,7 @@ module Lorj
106
106
  if %r{[^\\/]?/[^/]} =~ sKeyPath || /:[^:\/]/ =~ sKeyPath
107
107
  # keypath to interpret
108
108
  res = sKeyPath.split('/')
109
- res.each_index do | iIndex |
109
+ res.each_index do |iIndex|
110
110
  next unless res[iIndex].is_a?(String)
111
111
  res[iIndex] = res[iIndex][1..-1].to_sym if res[iIndex][0] == ':'
112
112
  end
@@ -44,8 +44,9 @@ class CloudProcess
44
44
  # Should return 1 or 0 flavor.
45
45
  def query_flavor(sCloudObj, sQuery, hParams)
46
46
  flavor_name = hParams[:flavor_name]
47
- list = forj_query_flavor(sCloudObj, sQuery, hParams)
48
- query_single(sCloudObj, list, sQuery, flavor_name)
47
+ # list = forj_query_flavor(sCloudObj, sQuery, hParams)
48
+ # query_single(sCloudObj, list, sQuery, flavor_name)
49
+ query_single(sCloudObj, sQuery, flavor_name)
49
50
  end
50
51
 
51
52
  # Should return 1 or 0 flavor.
@@ -76,8 +76,9 @@ class CloudProcess
76
76
  key_name = hParams[:keypair_name]
77
77
  ssl_error_obj = SSLErrorMgt.new
78
78
  begin
79
- list = controller_query(sCloudObj, sQuery)
80
- query_single(sCloudObj, list, sQuery, key_name)
79
+ # list = controller_query(sCloudObj, sQuery)
80
+ # query_single(sCloudObj, list, sQuery, key_name)
81
+ query_single(sCloudObj, sQuery, key_name)
81
82
  rescue => e
82
83
  retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
83
84
  end
@@ -139,7 +140,7 @@ class CloudProcess
139
140
  priv_key_exist = true
140
141
  priv_key_name = key_basename + private_key_ext
141
142
  else
142
- files.each do | temp_file |
143
+ files.each do |temp_file|
143
144
  PrcLib.warning('keypair_detect: Private key file name detection has '\
144
145
  "detected '%s' as a directory. Usually, it should be a "\
145
146
  'private key file. Please check.',
@@ -163,7 +164,7 @@ class CloudProcess
163
164
  def _check_key_file(key_path, key_basename, extensions)
164
165
  found_ext = nil
165
166
  files = []
166
- extensions.each do | ext |
167
+ extensions.each do |ext|
167
168
  temp_file = File.join(key_path, key_basename + ext)
168
169
  if File.exist?(temp_file) && !File.directory?(temp_file)
169
170
  found_ext = ext
@@ -37,7 +37,7 @@ class CloudProcess
37
37
  end
38
38
 
39
39
  # object.Create(:subnetwork)
40
- Create(:subnetwork)
40
+ process_create(:subnetwork)
41
41
 
42
42
  network
43
43
  end
@@ -100,8 +100,9 @@ class CloudProcess
100
100
  # nil or Provider Object
101
101
  def find_network(sCloudObj, hParams)
102
102
  query = { :name => hParams[:network_name] }
103
- list = controller_query(sCloudObj, query)
104
- query_single(sCloudObj, list, query, hParams[:network_name])
103
+ # list = controller_query(sCloudObj, query)
104
+ # query_single(sCloudObj, list, query, hParams[:network_name])
105
+ query_single(sCloudObj, query, hParams[:network_name])
105
106
  rescue => e
106
107
  PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
107
108
  end